Class CellTableCountSample
java.lang.Object
edu.cmu.tetrad.data.CellTableCountSample
- All Implemented Interfaces:
CellTable
Stores a cell count table of arbitrary dimension. Provides methods for incrementing particular cells and for
calculating marginals.
This implementation of CellTable uses a MultiDimIntTable to store the cell counts and counts data in the dataset to populate the tables, for each independence question encountered.
Immutable.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCellTableCountSample(int[][] data, List<DiscreteVariable> variables, int[] testIndices, List<Integer> rows) Constructs a CellTableCountSample object with the specified data, variables, test indices, and rows. -
Method Summary
Modifier and TypeMethodDescriptionintcalcMargin(int[] coords) Calculates a marginal sum for the cell table.intcalcMargin(int[] coords, int[] marginVars) An alternative way to specify a marginal calculation.intgetDimension(int varIndex) Returns the dimensions of the given variable.intgetValue(int[] coords) Returns the value of the cell specified by the given coordinates.
-
Constructor Details
-
CellTableCountSample
public CellTableCountSample(int[][] data, List<DiscreteVariable> variables, int[] testIndices, List<Integer> rows) Constructs a CellTableCountSample object with the specified data, variables, test indices, and rows. Initializes the table to count occurrences for specific variables and rows in a multi-dimensional data set.- Parameters:
data- a 2D integer array representing the data set; each column corresponds to a variable and each row to an observationvariables- a list of DiscreteVariable objects representing the variables being analyzedtestIndices- an integer array specifying the indices of the variables to be used for table constructionrows- a list of integer indices specifying the rows of the data set to include in the count; if null, all rows will be used- Throws:
IllegalArgumentException- if the data set or testIndices array is null, if a test index exceeds the bounds of the data set, or if a row index exceeds the bounds of the data set
-
-
Method Details
-
getDimension
public int getDimension(int varIndex) Returns the dimensions of the given variable.- Specified by:
getDimensionin interfaceCellTable- Parameters:
varIndex- the index of the variable in question.- Returns:
- the dimension of the variable.
-
calcMargin
public int calcMargin(int[] coords) Calculates a marginal sum for the cell table. The variables over which marginal sums should be taken are indicated by placing "-1's" in the appropriate positions in the coordinate argument. For instance, to find the margin for v0 = 1, v1 = 3, and v3 = 2, where the marginal sum ranges over all values of v2 and v4, the array [1, 3, -1, 2, -1] should be used.- Specified by:
calcMarginin interfaceCellTable- Parameters:
coords- an array of the sort described above.- Returns:
- the marginal sum specified.
-
calcMargin
public int calcMargin(int[] coords, int[] marginVars) An alternative way to specify a marginal calculation. In this case, coords specifies a particular cell in the table, and varIndices is an array containing the indices of the variables over which the margin sum should be calculated. The sum is over the cell specified by 'coord' and all the cells which differ from that cell in any of the specified coordinates.- Specified by:
calcMarginin interfaceCellTable- Parameters:
coords- anint[]valuemarginVars- anint[]value- Returns:
- an
intvalue
-
getValue
-