Package edu.cmu.tetrad.search.test
Class ChiSquareTest
java.lang.Object
edu.cmu.tetrad.search.test.ChiSquareTest
Calculates chi-square or g-square for a conditional cross-tabulation table for independence question 0 _||_ 1 | 2, 3,
...max by summing up chi-square and degrees of freedom for each conditional table in turn, where rows or columns that
sum to less than a given threshold have been removed. The adjusted conditional tables are required to have more than
0 total counts and at least 2 rows and 2 columns; otherwise, the test is judged to be invalid. Otherwise, a p-value
is returned based on the Chi-Square distribution with the total degrees of freedom and total chi-square.
- Version:
- $Id: $Id
- Author:
- frankwimberly, josephramsey
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The type of cell table to use.static class
Simple class to store the parameters of the result returned by the G Square test.static enum
The type of test to perform. -
Constructor Summary
ConstructorsConstructorDescriptionChiSquareTest
(DataSet dataSet, double alpha, ChiSquareTest.TestType testType, List<Integer> rows) Constructs a test using the given data set and significance level. -
Method Summary
Modifier and TypeMethodDescriptioncalcChiSquare
(int[] testIndices, double sampleSize) Calculates chi square for a conditional cross-tabulation table for independence question 0 _||_ 1 | 2, 3, ...max by summing up chi square and degrees of freedom for each conditional table in turn.double
getAlpha()
Returns the model significance level being used for tests.boolean
isDetermined
(int[] testIndices, double p) Returns a judgment of whether a set of parent variables determines a child variables.void
setAlpha
(double alpha) Sets the significance level to be used for tests.void
setCellTableType
(ChiSquareTest.CellTableType cellTableType) Sets the type of cell table to use.void
setMinCountPerCell
(double minCountPerCell) The minimum number of counts per conditional table for chi-square for that table and its degrees of freedom to be included in the overall chi-square and degrees of freedom.
-
Constructor Details
-
ChiSquareTest
public ChiSquareTest(DataSet dataSet, double alpha, ChiSquareTest.TestType testType, List<Integer> rows) Constructs a test using the given data set and significance level.- Parameters:
dataSet
- A data set consisting entirely of discrete variables.alpha
- The significance level, usually 0.05.testType
- The type of test to perform, either CHI_SQUARE or G_SQUARE.rows
- The rows to use in the test; if null, all rows are used.
-
-
Method Details
-
calcChiSquare
Calculates chi square for a conditional cross-tabulation table for independence question 0 _||_ 1 | 2, 3, ...max by summing up chi square and degrees of freedom for each conditional table in turn. Rows or columns that with fewer than minSumRowOrCol counts have been removed. The adjusted conditional tables are required to have more than 0 total counts and at least 2 rows and 2 columns; otherwise, the test is judged to be invalid. Otherwise, a p-value is returned based on the Chi-Square distribution with the total degrees of freedom and total chi-square.- Parameters:
testIndices
- These indices, in order.sampleSize
- The sample size to use for the test; expected and observed counts will be multiplied by the ratio of this to the sample size of the data.- Returns:
- a Chi square test result.
- See Also:
-
isDetermined
public boolean isDetermined(int[] testIndices, double p) Returns a judgment of whether a set of parent variables determines a child variables.- Parameters:
testIndices
- An array of indices for variables in the dataset supplied in the constructor.p
- The probability that some marginal for some table dominates. A good value is 0.99.- Returns:
- True if the variable at index 0 is determined by the variables at the other indices.
-
getAlpha
public double getAlpha()Returns the model significance level being used for tests.- Returns:
- this level.
-
setAlpha
public void setAlpha(double alpha) Sets the significance level to be used for tests.- Parameters:
alpha
- This significance level.
-
setMinCountPerCell
public void setMinCountPerCell(double minCountPerCell) The minimum number of counts per conditional table for chi-square for that table and its degrees of freedom to be included in the overall chi-square and degrees of freedom. Note that this should not be too small, or the chi-square distribution will not be a good approximation to the distribution of the test statistic.- Parameters:
minCountPerCell
- The minimum number of counts per conditional table. The default is 1; this must be >= 0.
-
setCellTableType
Sets the type of cell table to use.- Parameters:
cellTableType
- The type of cell table to use.
-