Class IndTestConditionalGaussianLrt

java.lang.Object
edu.cmu.tetrad.search.test.IndTestConditionalGaussianLrt
All Implemented Interfaces:
IndependenceTest, RowsSettable, EffectiveSampleSizeSettable

public class IndTestConditionalGaussianLrt extends Object implements IndependenceTest, RowsSettable, EffectiveSampleSizeSettable
Performs a test of conditional independence X _||_ Y | Z1...Zn where all variables are either continuous or discrete. This test is valid for both ordinal and non-ordinal discrete variables.

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 Details

    • IndTestConditionalGaussianLrt

      public IndTestConditionalGaussianLrt(DataSet data, double alpha, boolean discretize)
      Constructor.
      Parameters:
      data - The data to analyze.
      alpha - The significance level.
      discretize - Whether discrete children of continuous parents should be discretized.
  • Method Details

    • indTestSubset

      public IndependenceTest indTestSubset(List<Node> vars)
      This method returns an instance of the IndependenceTest interface that can test the independence of a subset of variables.
      Specified by:
      indTestSubset in interface IndependenceTest
      Parameters:
      vars - The sublist of variables to test for independence.
      Returns:
      An instance of the IndependenceTest interface.
      See Also:
    • checkIndependence

      public IndependenceResult checkIndependence(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.
      Specified by:
      checkIndependence in interface IndependenceTest
      Parameters:
      x - a Node object
      y - a Node object
      _z - a Set object
      Returns:
      a IndependenceResult object
      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

      public List<Node> getVariables()
      Returns the list of variables over which this independence checker is capable of determining independence relations.
      Specified by:
      getVariables in interface IndependenceTest
      Returns:
      This list.
    • determines

      public boolean determines(List<Node> z, Node y)
      Determines whether a given list of nodes (z) determines a node (y).
      Parameters:
      z - The list of nodes to check if they determine y.
      y - The node to check if it is determined by z.
      Returns:
      True if z determines y, false otherwise.
    • getAlpha

      public double getAlpha()
      Returns the significance level of the independence test.
      Specified by:
      getAlpha in interface IndependenceTest
      Returns:
      This level.
    • setAlpha

      public void setAlpha(double alpha)
      Sets the significance level.
      Specified by:
      setAlpha in interface IndependenceTest
      Parameters:
      alpha - This level.
    • getData

      public DataSet getData()
      Returns the data.
      Specified by:
      getData in interface IndependenceTest
      Returns:
      This data.
    • toString

      public String toString()
      Returns a string representation of this test.
      Specified by:
      toString in interface IndependenceTest
      Overrides:
      toString in class Object
      Returns:
      This string.
    • isVerbose

      public boolean isVerbose()
      Returns true iff verbose output should be printed.
      Specified by:
      isVerbose in interface IndependenceTest
      Returns:
      True if the case.
    • setVerbose

      public void setVerbose(boolean verbose)
      Sets whether verbose output should be printed.
      Specified by:
      setVerbose in interface IndependenceTest
      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 via setEffectiveSampleSize(int), or, if none has been set, the number of rows currently in use (the restriction from setRows(List) if any, otherwise the full dataset).
      Specified by:
      getEffectiveSampleSize in interface EffectiveSampleSizeSettable
      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:
      setEffectiveSampleSize in interface EffectiveSampleSizeSettable
      Parameters:
      nEff - the effective sample size, or a nonpositive value to use the actual number of rows
    • getRows

      public List<Integer> getRows()
      Returns the user-specified row restriction (or null if none).
      Specified by:
      getRows in interface RowsSettable
      Returns:
      The current row restriction.
    • setRows

      public void setRows(List<Integer> rows)
      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:
      setRows in interface RowsSettable
      Parameters:
      rows - Row indices into the original DataSet.
    • getMissingValueSupport

      public MissingValueSupport getMissingValueSupport()
      Declares what this test can do, natively, with data containing missing values. The default is MissingValueSupport.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:
      getMissingValueSupport in interface IndependenceTest
      Returns:
      MissingValueSupport.TESTWISE.