Package edu.cmu.tetrad.search.test
Class IndTestChiSquare
java.lang.Object
edu.cmu.tetrad.search.test.IndTestChiSquare
- All Implemented Interfaces:
EffectiveSampleSizeSettable
,IndependenceTest
,RowsSettable
public final class IndTestChiSquare
extends Object
implements IndependenceTest, EffectiveSampleSizeSettable, RowsSettable
Checks the conditional independence X _||_ Y | S, where S is a set of discrete variable, and X and Y are discrete
variable not in S, by applying a conditional Chi Square test. A description of such a test is given in Fienberg, "The
Analysis of Cross-Classified Categorical Data," 2nd edition. The formulas for the degrees of freedom used in this
test are equivalent to the formulation on page 142 of Fienberg.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionIndTestChiSquare
(DataSet dataSet, double alpha) Constructs a new independence checker to check conditional independence facts for discrete data using a g square test. -
Method Summary
Modifier and TypeMethodDescriptioncheckIndependence
(Node x, Node y, Set<Node> _z) Determines whether variable x is independent of variable y given a list of conditioning varNames z.boolean
determines
(List<Node> z, Node x) Determines whether variable x is independent of variable y given a list of conditioning nodes.boolean
determines
(Set<Node> _z, Node x) Determines whether variable x is independent of a set of variables _z.double
getAlpha()
Returns the alpha significance level of the test.double
Returns the chi Square value.getData()
Returns the data being analyzed.int
getDf()
Returns the degrees of freedom associated with the most recent call of isIndependent.Returns the pvalue if the fact of X _||_ Y | Z is within the cache of results for independence fact.getRows()
Returns the rows used for the test.Returns the list of variables over which this independence checker is capable of determining independence relations-- that is, all the variables in the given graph or the given data set.indTestSubset
(List<Node> nodes) Checks conditional independence between variables in a subset.boolean
Checks if the verbosity flag is enabled.void
setAlpha
(double alpha) Sets the significance level at which independence judgments should be made.void
setCellTableType
(ChiSquareTest.CellTableType cellTableType) Sets the cell table type.void
setDeterminationP
(double determinationP) Sets the threshold for making judgments of determination.void
setEffectiveSampleSize
(int sampleSize) Sets the sample size if the sample size of the data or covariance matrix is not the sample size that should be used by the class.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.void
Sets the rows to use for the test.void
setVerbose
(boolean verbose) Sets whether verbose output should be printed.toString()
Returns a string representation of this test.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface edu.cmu.tetrad.search.IndependenceTest
checkIndependence, getCov, getDataSets, getSampleSize, getVariable, getVariableNames
-
Constructor Details
-
IndTestChiSquare
Constructs a new independence checker to check conditional independence facts for discrete data using a g square test.- Parameters:
dataSet
- the discrete data set.alpha
- the significance level of the tests.
-
-
Method Details
-
indTestSubset
Checks conditional independence between variables in a subset.- Specified by:
indTestSubset
in interfaceIndependenceTest
- Parameters:
nodes
- The sublist of variables.- Returns:
- An instance of IndependenceTest representing the test for conditional independence.
- Throws:
IllegalArgumentException
- If the subset of variables is empty or contains non-original nodes.
-
getChiSquare
public double getChiSquare()Returns the chi Square value.- Returns:
- This value.
-
getDf
public int getDf()Returns the degrees of freedom associated with the most recent call of isIndependent.- Returns:
- These degrees.
-
checkIndependence
Determines whether variable x is independent of variable y given a list of conditioning varNames z.- Specified by:
checkIndependence
in interfaceIndependenceTest
- Parameters:
x
- aNode
objecty
- aNode
object_z
- aSet
object- Returns:
- a
IndependenceResult
object - See Also:
-
getPValue
-
determines
Determines whether variable x is independent of variable y given a list of conditioning nodes.- Parameters:
z
- The list of conditioning nodes.x
- The variable x.- Returns:
- True if variable x is determined by the list of conditioning nodes, false otherwise.
- Throws:
NullPointerException
- if z or any node in z is null.IllegalArgumentException
- if any node in z is not used in the constructor.
-
getAlpha
public double getAlpha()Returns the alpha significance level of the test.- Specified by:
getAlpha
in interfaceIndependenceTest
- Returns:
- This level.
-
setAlpha
public void setAlpha(double alpha) Sets the significance level at which independence judgments should be made. Affects the cutoff for partial correlations to be considered statistically equal to zero.- Specified by:
setAlpha
in interfaceIndependenceTest
- Parameters:
alpha
- This level.
-
getVariables
Returns the list of variables over which this independence checker is capable of determining independence relations-- that is, all the variables in the given graph or the given data set.- Specified by:
getVariables
in interfaceIndependenceTest
- Returns:
- This list.
-
toString
Returns a string representation of this test.- Specified by:
toString
in interfaceIndependenceTest
- Overrides:
toString
in classObject
- Returns:
- This string.
-
getData
Returns the data being analyzed.- Specified by:
getData
in interfaceIndependenceTest
- Returns:
- This data.
- See Also:
-
isVerbose
public boolean isVerbose()Checks if the verbosity flag is enabled.- Specified by:
isVerbose
in interfaceIndependenceTest
- Returns:
- true if the verbosity flag is enabled, false otherwise
-
setVerbose
public void setVerbose(boolean verbose) Sets whether verbose output should be printed.- Specified by:
setVerbose
in interfaceIndependenceTest
- Parameters:
verbose
- True, if so.
-
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.
-
getRows
Returns the rows used for the test. If null, all rows are used.- Specified by:
getRows
in interfaceRowsSettable
- Returns:
- The rows to use for the test. Can be null.
-
setRows
Sets the rows to use for the test. If null, all rows are used.- Specified by:
setRows
in interfaceRowsSettable
- Parameters:
rows
- The rows to use for the test. Can be null.
-
setEffectiveSampleSize
public void setEffectiveSampleSize(int sampleSize) Description copied from interface:EffectiveSampleSizeSettable
Sets the sample size if the sample size of the data or covariance matrix is not the sample size that should be used by the class.- Specified by:
setEffectiveSampleSize
in interfaceEffectiveSampleSizeSettable
- Parameters:
sampleSize
- The sample size to use.
-
setCellTableType
Sets the cell table type.- Parameters:
cellTableType
- The cell table type.
-
setDeterminationP
public void setDeterminationP(double determinationP) Sets the threshold for making judgments of determination.- Parameters:
determinationP
- This threshold.
-
determines
Determines whether variable x is independent of a set of variables _z.- Specified by:
determines
in interfaceIndependenceTest
- Parameters:
_z
- a set of variables to condition onx
- the variable to check for independence- Returns:
- true if variable x is independent of _z, false otherwise
- Throws:
NullPointerException
- if _z or any element in _z is nullIllegalArgumentException
- if any variable in _z or x was not used in the constructor
-