Class IndTestConditionalGaussianLrt
- All Implemented Interfaces:
IndependenceTest, RowsSettable, EffectiveSampleSizeSettable
Assumes a conditional Gaussian model and uses a likelihood ratio test. Drop-in replacement note: - setRows(...) now respects the provided argument (no random subsampling). - Row restriction is intersected with testwise deletion for the specific (x, y | z) variables. - Caches are cleared when row restrictions or discretization knobs change.
Effective sample size (added 2026-8-25). When an effective sample size nEff is set (see
setEffectiveSampleSize(int)), the likelihood-ratio statistic 2 * (l1 - l0) is scaled by r = nEff / N,
where N is the number of rows in the dataset, before being referred to the chi-square distribution. The
degrees of freedom are unchanged. Since the log-likelihoods are row sums, this is the statistic that nEff
independent rows would have produced. The value is relative to the full dataset: if setRows(List)
restricts the test to m rows, or testwise deletion drops rows for a particular (x, y | z), the test behaves as if
it had r * m independent rows, so a subsample or resample inherits the same per-row information content rather
than the full nEff. (This differs from IndTestDegenerateGaussianLrt, which resets nEff to the actual row
count on setRows, and from IndTestFisherZ, which keeps the absolute nEff regardless of setRows.) With
nEff unset, r = 1 and the test is unchanged from the previous implementation.
- Version:
- $Id: $Id
- Author:
- josephramsey
-
Constructor Summary
ConstructorsConstructorDescriptionIndTestConditionalGaussianLrt(DataSet data, double alpha, boolean discretize) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncheckIndependence(Node x, Node y, Set<Node> _z) Returns an independence result that states whether x _||_ y | z and what the p-value of the test is.booleandetermines(List<Node> z, Node y) Determines whether a given list of nodes (z) determines a node (y).doublegetAlpha()Returns the significance level of the independence test.getData()Returns the data.intReturns the effective sample size: the value set viasetEffectiveSampleSize(int), or, if none has been set, the number of rows currently in use (the restriction fromsetRows(List)if any, otherwise the full dataset).Declares what this test can do, natively, with data containing missing values.doubleReturns the probability associated with the most recently executed independence test, or Double.NaN if p value is not meaningful for this test.getRows()Returns the user-specified row restriction (or null if none).Returns the list of variables over which this independence checker is capable of determining independence relations.indTestSubset(List<Node> vars) This method returns an instance of the IndependenceTest interface that can test the independence of a subset of variables.booleanReturns true iff verbose output should be printed.voidsetAlpha(double alpha) Sets the significance level.voidsetEffectiveSampleSize(int nEff) Sets the effective sample size, interpreted relative to the full dataset, or -1 (any negative value) to use the actual number of rows.voidsetMinSampleSizePerCell(int minSampleSizePerCell) Sets the minimum sample size per cell for the independence test.voidsetNumCategoriesToDiscretize(int numCategoriesToDiscretize) Sets the number of categories used to discretize variables.voidAllows the user to set which rows are used in the test.voidsetVerbose(boolean verbose) Sets whether verbose output should be printed.toString()Returns a string representation of this test.Methods inherited from interface IndependenceTest
canBeSubsampled, checkIndependence, determines, getCov, getDataSets, getSampleSize, getVariable, getVariableNames, isPValueAProbability
-
Constructor Details
-
IndTestConditionalGaussianLrt
Constructor.- Parameters:
data- The data to analyze.alpha- The significance level.discretize- Whether discrete children of continuous parents should be discretized.
-
-
Method Details
-
indTestSubset
This method returns an instance of the IndependenceTest interface that can test the independence of a subset of variables.- Specified by:
indTestSubsetin interfaceIndependenceTest- Parameters:
vars- The sublist of variables to test for independence.- Returns:
- An instance of the IndependenceTest interface.
- See Also:
-
checkIndependence
Returns an independence result that states whether x _||_ y | z and what the p-value of the test is.- Specified by:
checkIndependencein interfaceIndependenceTest- Parameters:
x- aNodeobjecty- aNodeobject_z- aSetobject- Returns:
- a
IndependenceResultobject - See Also:
-
getPValue
public double getPValue()Returns the probability associated with the most recently executed independence test, or Double.NaN if p value is not meaningful for this test.- Returns:
- This p-value.
-
getVariables
Returns the list of variables over which this independence checker is capable of determining independence relations.- Specified by:
getVariablesin interfaceIndependenceTest- Returns:
- This list.
-
determines
-
getAlpha
public double getAlpha()Returns the significance level of the independence test.- Specified by:
getAlphain interfaceIndependenceTest- Returns:
- This level.
-
setAlpha
public void setAlpha(double alpha) Sets the significance level.- Specified by:
setAlphain interfaceIndependenceTest- Parameters:
alpha- This level.
-
getData
Returns the data.- Specified by:
getDatain interfaceIndependenceTest- Returns:
- This data.
-
toString
Returns a string representation of this test.- Specified by:
toStringin interfaceIndependenceTest- Overrides:
toStringin classObject- Returns:
- This string.
-
isVerbose
public boolean isVerbose()Returns true iff verbose output should be printed.- Specified by:
isVerbosein interfaceIndependenceTest- Returns:
- True if the case.
-
setVerbose
public void setVerbose(boolean verbose) Sets whether verbose output should be printed.- Specified by:
setVerbosein interfaceIndependenceTest- Parameters:
verbose- True, if so.
-
setNumCategoriesToDiscretize
public void setNumCategoriesToDiscretize(int numCategoriesToDiscretize) Sets the number of categories used to discretize variables.- Parameters:
numCategoriesToDiscretize- This number, by default 3.
-
setMinSampleSizePerCell
public void setMinSampleSizePerCell(int minSampleSizePerCell) Sets the minimum sample size per cell for the independence test.- Parameters:
minSampleSizePerCell- The minimum sample size per cell.
-
getEffectiveSampleSize
public int getEffectiveSampleSize()Returns the effective sample size: the value set viasetEffectiveSampleSize(int), or, if none has been set, the number of rows currently in use (the restriction fromsetRows(List)if any, otherwise the full dataset).- Specified by:
getEffectiveSampleSizein interfaceEffectiveSampleSizeSettable- Returns:
- the effective sample size
-
setEffectiveSampleSize
public void setEffectiveSampleSize(int nEff) Sets the effective sample size, interpreted relative to the full dataset, or -1 (any negative value) to use the actual number of rows. A value of 0 is treated as unset. See the class Javadoc for the interaction with setRows and testwise deletion.Configuration mutator: do not call concurrently with running tests.
- Specified by:
setEffectiveSampleSizein interfaceEffectiveSampleSizeSettable- Parameters:
nEff- the effective sample size, or a nonpositive value to use the actual number of rows
-
getRows
Returns the user-specified row restriction (or null if none).- Specified by:
getRowsin interfaceRowsSettable- Returns:
- The current row restriction.
-
setRows
Allows the user to set which rows are used in the test. If null is passed, all rows are eligible (subject to testwise deletion for each test).- Specified by:
setRowsin interfaceRowsSettable- Parameters:
rows- Row indices into the original DataSet.
-
getMissingValueSupport
Declares what this test can do, natively, with data containing missing values. The default isMissingValueSupport.NONE, meaning that missingness must be handled upstream (e.g., by imputation, or by supplying an EM-estimated covariance matrix if the test consumes one); tests that handle missing values themselves should override this.Each likelihood-ratio calculation uses the rows complete on the variables involved in that calculation (the candidate rows are intersected with the rows having no missingness on those variables), i.e., test-wise deletion, unbiased only under MCAR.
- Specified by:
getMissingValueSupportin interfaceIndependenceTest- Returns:
MissingValueSupport.TESTWISE.
-