Package edu.cmu.tetrad.search.test
Class IndTestFisherZ
java.lang.Object
edu.cmu.tetrad.search.test.IndTestFisherZ
- All Implemented Interfaces:
- RawMarginalIndependenceTest,- IndependenceTest,- RowsSettable,- EffectiveSampleSizeSettable
public final class IndTestFisherZ
extends Object
implements IndependenceTest, EffectiveSampleSizeSettable, RowsSettable, RawMarginalIndependenceTest
Fisher's Z CI test with shrinkage (RIDGE/LedoitâWolf) and optional pseudoinverse fallback.
- 
Nested Class SummaryNested Classes
- 
Constructor SummaryConstructorsConstructorDescriptionIndTestFisherZ(DataSet dataSet, double alpha) Constructs an independence test using the Fisher Z test statistic.IndTestFisherZ(DataSet dataSet, double alpha, double ridge) Constructor for IndTestFisherZ which initializes the independence test using the Fisher Z test with specified parameters.IndTestFisherZ(ICovarianceMatrix covMatrix, double alpha) Constructs an instance of IndTestFisherZ using the given covariance matrix and significance level.IndTestFisherZ(ICovarianceMatrix covMatrix, double alpha, double ridge) Constructor for the IndTestFisherZ class.IndTestFisherZ(Matrix data, List<Node> variables, double alpha) Constructs an instance of the IndTestFisherZ class, which is a statistical test for conditional independence based on the Fisher Z-test.IndTestFisherZ(Matrix data, List<Node> variables, double alpha, double ridge) Constructor for the IndTestFisherZ class, which performs a Fisher Z independence test with ridge regularization applied to handle issues with covariance matrix inversion.
- 
Method SummaryModifier and TypeMethodDescriptioncheckIndependence(Node x, Node y, Set<Node> z) Checks the independence of two nodes given a conditioning set and returns the result.doublecomputePValue(double[] x, double[] y) Computes the p-value for the statistical test of independence between two variables.booleandetermines(List<Node> z, Node x) Determines whether the given set of nodes, z, has a deterministic relationship with the specified node, x.doublegetAlpha()Retrieves the significance level.doublegetBic()Computes and returns the Bayesian Information Criterion (BIC) value.getCov()Retrieves the covariance matrix used by this instance.getData()Retrieves the data set associated with the current instance.Retrieves a list of data sets associated with this instance.intRetrieves the effective sample size.doublegetLastR()Gets the last computed partial correlation.doubleGets the tolerance for the pseudoinverse computation.doubleCalculates the p-value for the partial correlation between two nodes conditioned on a set of other nodes.doublegetRho()Gets the last computed partial correlation.doublegetRidge()Retrieves the current value of the ridge parameter associated with this instance.getRows()Retrieves the list of row indices currently associated with this instance.intRetrieves the sample size of the data set associated with this instance.Retrieves the current shrinkage mode used by this instance.getVariable(String name) Retrieves a variable by its name from the internal mapping of variable names to nodes.Retrieves the list of variables.indTestSubset(List<Node> vars) Returns a new IndependenceTest instance for a subset of variables.booleanChecks whether the pseudoinverse is being used in computations.booleanRetrieves the verbosity setting for this instance.voidsetAlpha(double alpha) Sets the significance level.voidsetEffectiveSampleSize(int effectiveSampleSize) Sets the effective sample size.voidsetLambda(double lambda) Sets the value of the lambda parameter for this instance.voidsetPinvTolerance(double tol) Sets the tolerance for the pseudoinverse computation.voidsetRidge(double ridge) Sets the value of the ridge parameter for this instance.voidSets the list of row indices for the instance.voidSets the shrinkage mode for the instance.voidsetUsePseudoinverse(boolean use) Sets whether to use the pseudoinverse in computations.voidsetVariables(List<Node> variables) Sets the list of variables for the instance.voidsetVerbose(boolean verbose) Sets the verbosity setting for this instance.toString()Returns a string representation of this instance, including details about the test configuration.Methods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.cmu.tetrad.search.test.IndependenceTestcheckIndependence, determines, getVariableNamesMethods inherited from interface edu.cmu.tetrad.search.RawMarginalIndependenceTestcomputePValue
- 
Constructor Details- 
IndTestFisherZConstructs an independence test using the Fisher Z test statistic. The test evaluates the independence of variables given a dataset and a significance level (alpha). The dataset must be continuous and should not contain missing values for certain operations.- Parameters:
- dataSet- the dataset used for the independence test; must be continuous
- alpha- the significance level for the Fisher Z test; must be in the range [0, 1]
- Throws:
- IllegalArgumentException- if the dataset is not continuous
- IllegalArgumentException- if the alpha value is not in the range [0, 1]
 
- 
IndTestFisherZConstructor for IndTestFisherZ which initializes the independence test using the Fisher Z test with specified parameters.- Parameters:
- dataSet- the dataset on which the independence test will be performed
- alpha- the significance level for determining independence
- ridge- the ridge parameter used for regularization in the test
 
- 
IndTestFisherZConstructs an instance of the IndTestFisherZ class, which is a statistical test for conditional independence based on the Fisher Z-test.- Parameters:
- data- The data matrix, where rows represent samples and columns represent variables.
- variables- A list of variables corresponding to the columns in the data matrix. The order must match the column order in the data matrix.
- alpha- The significance level (type I error rate) for the Fisher Z-test.
 
- 
IndTestFisherZConstructor for the IndTestFisherZ class, which performs a Fisher Z independence test with ridge regularization applied to handle issues with covariance matrix inversion.- Parameters:
- data- The data matrix containing the dataset.
- variables- The list of nodes corresponding to the variables in the dataset.
- alpha- The significance level for the independence test.
- ridge- The ridge parameter for regularization of the covariance matrix.
 
- 
IndTestFisherZConstructs an instance of IndTestFisherZ using the given covariance matrix and significance level.- Parameters:
- covMatrix- the covariance matrix used to compute correlations and perform the Fisher's Z test
- alpha- the significance level for independence tests
 
- 
IndTestFisherZConstructor for the IndTestFisherZ class. It initializes the test with a given covariance matrix, significance level, and ridge parameter. This test determines the conditional independence of variables using the Fisher Z test.- Parameters:
- covMatrix- the covariance matrix used for calculating correlations.
- alpha- the significance level for testing conditional independence.
- ridge- the ridge parameter used for regularization in the shrinkage mode.
 
 
- 
- 
Method Details- 
indTestSubsetReturns a new IndependenceTest instance for a subset of variables. This method verifies that the given variables are part of the original variable set, then creates a submatrix of the covariance matrix and constructs an IndependenceTestFisherZ object for the subset.- Specified by:
- indTestSubsetin interface- IndependenceTest
- Parameters:
- vars- A list of variables for which the subset independence test will be created. All variables in this list must be part of the original set of variables.
- Returns:
- An IndependenceTest instance that operates on the given subset of variables.
- Throws:
- IllegalArgumentException- If the provided subset is empty or contains variables not in the original variable set.
 
- 
checkIndependenceChecks the independence of two nodes given a conditioning set and returns the result.- Specified by:
- checkIndependencein interface- IndependenceTest
- Parameters:
- x- the first node to be tested for independence
- y- the second node to be tested for independence
- z- the set of nodes conditioning the independence test
- Returns:
- an IndependenceResult containing the results of the independence test, including whether x and y are independent given z, the p-value of the test, and other test details
- Throws:
- RuntimeException- if a singular matrix is encountered during computation or if the p-value is undefined
 
- 
getPValuepublic double getPValue(Node x, Node y, Set<Node> z) throws org.apache.commons.math3.linear.SingularMatrixException Calculates the p-value for the partial correlation between two nodes conditioned on a set of other nodes.- Parameters:
- x- the first node involved in the correlation.
- y- the second node involved in the correlation.
- z- the set of conditioning nodes.
- Returns:
- the p-value for the partial correlation between nodes x and y given the conditioning set z.
- Throws:
- org.apache.commons.math3.linear.SingularMatrixException- if the covariance matrix inversion fails during computation.
- IllegalArgumentException- if the degrees of freedom (df) are non-positive.
 
- 
getEffectiveSampleSizepublic int getEffectiveSampleSize()Retrieves the effective sample size.- Specified by:
- getEffectiveSampleSizein interface- EffectiveSampleSizeSettable
- Returns:
- the effective sample size as an integer.
 
- 
setEffectiveSampleSizepublic void setEffectiveSampleSize(int effectiveSampleSize) Sets the effective sample size. If the provided effective sample size is negative, it will default to the sample size.- Specified by:
- setEffectiveSampleSizein interface- EffectiveSampleSizeSettable
- Parameters:
- effectiveSampleSize- the effective sample size to set; if negative, the sample size will be used instead.
 
- 
getBicpublic double getBic()Computes and returns the Bayesian Information Criterion (BIC) value.- Returns:
- the BIC value as a double calculated based on the effective sample size and the correlation coefficient squared.
 
- 
getAlphapublic double getAlpha()Retrieves the significance level.- Specified by:
- getAlphain interface- IndependenceTest
- Returns:
- the significance level as a double.
 
- 
setAlphapublic void setAlpha(double alpha) Sets the significance level. Validates that the provided significance level is within the valid range (0.0 to 1.0).- Specified by:
- setAlphain interface- IndependenceTest
- Parameters:
- alpha- This level.
 
- 
getVariablesRetrieves the list of variables.- Specified by:
- getVariablesin interface- IndependenceTest
- Returns:
- the list of variables.
 
- 
setVariablesSets the list of variables for the instance. Validates that the size of the provided variable list matches the current size of the instance's internal variable list, and updates internal state accordingly.- Parameters:
- variables- the list of variables to set; must match the size of the current variable list
- Throws:
- IllegalArgumentException- if the size of the provided variable list does not match the current variable list size
 
- 
getVariableRetrieves a variable by its name from the internal mapping of variable names to nodes.- Specified by:
- getVariablein interface- IndependenceTest
- Parameters:
- name- the name of the variable to retrieve; must match an existing key in the name map
- Returns:
- the node corresponding to the given name, or null if no such node exists
 
- 
getDataRetrieves the data set associated with the current instance.- Specified by:
- getDatain interface- IndependenceTest
- Returns:
- the DataSet object representing the data in this instance
 
- 
getCovRetrieves the covariance matrix used by this instance.- Specified by:
- getCovin interface- IndependenceTest
- Returns:
- an object implementing the ICovarianceMatrix interface, representing the covariance matrix associated with this instance
 
- 
getDataSetsRetrieves a list of data sets associated with this instance.- Specified by:
- getDataSetsin interface- IndependenceTest
- Returns:
- a list containing the data set associated with this instance
 
- 
getSampleSizepublic int getSampleSize()Retrieves the sample size of the data set associated with this instance.- Specified by:
- getSampleSizein interface- IndependenceTest
- Returns:
- the number of rows in the data set, or the sample size of the covariance matrix if no data set is available
 
- 
isVerbosepublic boolean isVerbose()Retrieves the verbosity setting for this instance.- Specified by:
- isVerbosein interface- IndependenceTest
- Returns:
- true if verbose output is enabled, false otherwise
 
- 
setVerbosepublic void setVerbose(boolean verbose) Sets the verbosity setting for this instance.- Specified by:
- setVerbosein interface- IndependenceTest
- Parameters:
- verbose- True, if so.
 
- 
toStringReturns a string representation of this instance, including details about the test configuration.- Specified by:
- toStringin interface- IndependenceTest
- Overrides:
- toStringin class- Object
- Returns:
- a string representation of this instance
 
- 
determinesDetermines whether the given set of nodes, z, has a deterministic relationship with the specified node, x. Specifically, this method checks if the covariance matrix derived from z is invertible. If the matrix is singular (non-invertible), it indicates a determinism detected between the nodes.- Parameters:
- z- the list of nodes to analyze as a potential set of deterministic parents for the node x
- x- the node to check for a deterministic relationship with the set of nodes z
- Returns:
- true if a deterministic relationship exists (when the covariance matrix is singular), false otherwise
- Throws:
- UnsupportedOperationException- if the operation is not supported due to some internal state or configuration
 
- 
getRowsRetrieves the list of row indices currently associated with this instance.- Specified by:
- getRowsin interface- RowsSettable
- Returns:
- a list of integers representing the row indices
 
- 
setRowsSets the list of row indices for the instance. Validates the provided list to ensure all elements are non-negative and non-null. Resets internal correlation state if the rows are updated.- Specified by:
- setRowsin interface- RowsSettable
- Parameters:
- rows- the list of row indices to set. Each element must be non-null and non-negative. If the provided list is null, the current row list is set to null.
- Throws:
- NullPointerException- if any element in the rows list is null.
- IllegalArgumentException- if any element in the rows list is negative.
 
- 
setLambdapublic void setLambda(double lambda) Sets the value of the lambda parameter for this instance. Lambda is used for regularization or other purposes within the class, depending on the context of its implementation.- Parameters:
- lambda- the value to set for the lambda parameter
 
- 
getRidgepublic double getRidge()Retrieves the current value of the ridge parameter associated with this instance.- Returns:
- the ridge parameter as a double value
 
- 
setRidgepublic void setRidge(double ridge) Sets the value of the ridge parameter for this instance. The ridge parameter is commonly used for regularization purposes. The provided value must be non-negative.- Parameters:
- ridge- the value to set for the ridge parameter; must be greater than or equal to 0
- Throws:
- IllegalArgumentException- if the ridge parameter is negative
 
- 
getShrinkageModeRetrieves the current shrinkage mode used by this instance.- Returns:
- the shrinkage mode, represented as a ShrinkageModeenum value, which indicates the type of regularization or adjustment (if any) applied in computations.
 
- 
setShrinkageModeSets the shrinkage mode for the instance. The shrinkage mode determines the type of regularization or adjustment applied during calculations, if any. If the provided mode is null, the shrinkage mode defaults toShrinkageMode.NONE.- Parameters:
- mode- the shrinkage mode to set, represented as a- ShrinkageModeenum value. It can be- ShrinkageMode.NONE,- ShrinkageMode.RIDGE, or- ShrinkageMode.LEDOIT_WOLF.
 
- 
isUsePseudoinversepublic boolean isUsePseudoinverse()Checks whether the pseudoinverse is being used in computations.- Returns:
- true if the pseudoinverse is enabled, false otherwise
 
- 
setUsePseudoinversepublic void setUsePseudoinverse(boolean use) Sets whether to use the pseudoinverse in computations.- Parameters:
- use- true to enable pseudoinverse, false to disable
 
- 
getPinvTolerancepublic double getPinvTolerance()Gets the tolerance for the pseudoinverse computation.- Returns:
- the tolerance value
 
- 
setPinvTolerancepublic void setPinvTolerance(double tol) Sets the tolerance for the pseudoinverse computation.- Parameters:
- tol- the tolerance value
 
- 
getLastRpublic double getLastR()Gets the last computed partial correlation.- Returns:
- the last computed partial correlation
 
- 
getRhopublic double getRho()Gets the last computed partial correlation.- Returns:
- the last computed partial correlation
 
- 
computePValuepublic double computePValue(double[] x, double[] y) Computes the p-value for the statistical test of independence between two variables.- Specified by:
- computePValuein interface- RawMarginalIndependenceTest
- Parameters:
- x- the array of values representing the first variable
- y- the array of values representing the second variable
- Returns:
- the computed p-value indicating the strength of independence between the two variables
 
 
-