Class IndTestBasisFunctionBlocks
- All Implemented Interfaces:
RawMarginalIndependenceTest, IndependenceTest, RowsSettable, EffectiveSampleSizeSettable
Basis–function independence test using block–structured Wilks statistics. This class:
- Applies a per-variable truncated basis expansion (via
Embedding) to produce an embedded dataset. - Builds a block mapping from each original variable to the list of embedded columns that belong to that variable.
- Delegates conditional-independence testing to
IndTestBlocksWilkes, using aBlockSpecconstructed from the embedded dataset, the block mapping, and the original variable nodes.
Subsampling support:
This class implements RowsSettable. Whenever setRows(...) is
called:
- If
rows == null, the test reverts to using the full embedded dataset. - If a non-null list of row indices is provided, a row-subsetted
embedded dataset is constructed, and the internal
IndTestBlocksWilkesdelegate is rebuilt on that subsample.
This guarantees that:
- The block structure remains identical across subsamples.
- All independence tests are run on the subsampled data when used inside tools such as the Markov Checker.
- Node identity is preserved (the same
Nodeinstances are passed through to the delegate).
Contract:
blocks.get(v) returns the list of embedded column indices corresponding
exactly to original variable v, for v = 0, ..., V-1.
-
Constructor Summary
ConstructorsConstructorDescriptionIndTestBasisFunctionBlocks(DataSet dataSet, int truncationLimit, int basisType) Constructs an instance of IndTestBasisFunctionBlocks.IndTestBasisFunctionBlocks(DataSet dataSet, int truncationLimit, int basisType, boolean adaptiveBasisSelection) Constructs an instance of IndTestBasisFunctionBlocks, optionally with adaptive basis selection.IndTestBasisFunctionBlocks(DataSet dataSet, int truncationLimit, int basisType, boolean adaptiveBasisSelection, MissingDataSpec spec) As the four-argument constructor, with an explicit missing-data specification. -
Method Summary
Modifier and TypeMethodDescriptioncheckIndependence(Node x, Node y, Set<Node> z) Checks for statistical independence between two given variables (nodes), conditioned on a set of other variables.doublecomputePValue(double[] x, double[] y) Computes the p-value for the statistical test of marginal independence between the two given variables represented by the input arrays.doublecomputePValue(double[] x, double[][] Y) Default multivariate fallback: run BFIT on each column of Y and combine with Fisher.doublegetAlpha()Retrieves the alpha value currently set for this instance.Retrieves the list of blocks, where each block is represented as a list of integers.getData()Retrieves the original dataset represented by this instance.intReturns the effective sample size.Declares what this test can do, natively, with data containing missing values.getRows()Gets the rows to use for the test.Retrieves the list of nodes (variables) associated with this instance.booleanIndicates whether this instance is operating in verbose mode.voidsetAlpha(double alpha) Sets the alpha value used as a threshold or parameter for statistical tests or computations.voidsetEffectiveSampleSize(int nEff) Sets the effective sample size.voidSets the rows to use for the test.voidsetVerbose(boolean verbose) Sets the verbosity mode for this instance.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IndependenceTest
canBeSubsampled, checkIndependence, determines, getCov, getDataSets, getSampleSize, getVariable, getVariableNames, indTestSubset, isPValueAProbability, toString
-
Constructor Details
-
IndTestBasisFunctionBlocks
Constructs an instance of IndTestBasisFunctionBlocks. This class is designed to perform independence tests based on basis function transformations of the provided dataset, using specified degree and basis type.- Parameters:
dataSet- the input dataset, which provides the raw data to be analyzed. Cannot be null.truncationLimit- the degree of the basis function transformation. Must be a non-negative integer.basisType- the type of basis functions to use for transformations (e.g., polynomial, Fourier, etc.). This value determines the embedding style and configuration specifics.- Throws:
IllegalArgumentException- if the raw dataset is null or if the degree is negative.
-
IndTestBasisFunctionBlocks
public IndTestBasisFunctionBlocks(DataSet dataSet, int truncationLimit, int basisType, boolean adaptiveBasisSelection) Constructs an instance of IndTestBasisFunctionBlocks, optionally with adaptive basis selection.- Parameters:
dataSet- the input dataset, which provides the raw data to be analyzed. Cannot be null.truncationLimit- the degree of the basis function transformation. Must be a non-negative integer.basisType- the type of basis functions to use for transformations.adaptiveBasisSelection- if true, basis columns beyond the linear term that fail a BIC-crossing screen against every other variable's embedded block are dropped from the blocks before testing, so that the effective truncation is chosen by the data and the test's behavior converges as the truncation limit is raised past the data-supported order. The screen is computed once, from the full-sample embedded correlation matrix, and the same pruned blocks are used for every test and every row subset (so bootstrap subsamples share one fixed block structure). Wilks degrees of freedom shrink accordingly.- Throws:
IllegalArgumentException- if the raw dataset is null or if the degree is negative.- See Also:
-
IndTestBasisFunctionBlocks
public IndTestBasisFunctionBlocks(DataSet dataSet, int truncationLimit, int basisType, boolean adaptiveBasisSelection, MissingDataSpec spec) As the four-argument constructor, with an explicit missing-data specification. On a data set with missing values the supported policies are LISTWISE, TESTWISE and EM_COVARIANCE. In both of the last two the embedding carries NaN in every derived column of a variable wherever that variable is missing, and the adaptive screen (if any) uses pairwise-deletion correlations. Under TESTWISE the delegate blocks test computes each test's correlation matrix over the rows complete on the columns it uses. Under EM_COVARIANCE it estimates one correlation matrix of the embedded columns by EM, under a jointly Gaussian working model, and the spec's effective-sample-size mode sets the sample size unless the caller sets one. As for the basis-function BIC score, this working model ignores the exact relations among a continuous variable's basis columns (the quadratic column is the square of the linear one), so the EM path is offered for comparison, not as the default. A null spec on missing data throws.- Parameters:
dataSet- the input dataset.truncationLimit- the degree of the basis function transformation.basisType- the type of basis functions.adaptiveBasisSelection- see the four-argument constructor.spec- the missing-data specification, or null.
-
-
Method Details
-
checkIndependence
Checks for statistical independence between two given variables (nodes), conditioned on a set of other variables.- Specified by:
checkIndependencein interfaceIndependenceTest- Parameters:
x- the first variable (node) to test for independencey- the second variable (node) to test for independencez- the set of conditioning variables (nodes) for the independence test- Returns:
- an IndependenceResult containing details about the test result, including whether the variables are independent, the p-value, and the significance level used
-
getVariables
Retrieves the list of nodes (variables) associated with this instance. The nodes returned are exactly the ones used internally by the delegate, ensuring identity consistency and preventing "unknown node" issues.- Specified by:
getVariablesin interfaceIndependenceTest- Returns:
- a list of nodes representing the variables
-
getData
Retrieves the original dataset represented by this instance.- Specified by:
getDatain interfaceIndependenceTest- Returns:
- the underlying data as a
DataModelobject
-
isVerbose
public boolean isVerbose()Indicates whether this instance is operating in verbose mode. Verbose mode allows for detailed output or logging to assist in debugging or monitoring execution.- Specified by:
isVerbosein interfaceIndependenceTest- Returns:
- true if verbose mode is enabled; false otherwise
-
setVerbose
public void setVerbose(boolean verbose) Sets the verbosity mode for this instance. Enabling verbosity allows for more detailed output or logging during execution.- Specified by:
setVerbosein interfaceIndependenceTest- Parameters:
verbose- true to enable verbose output, false to disable it
-
computePValue
Description copied from interface:RawMarginalIndependenceTestComputes the p-value for the statistical test of marginal independence between the two given variables represented by the input arrays.- Specified by:
computePValuein interfaceRawMarginalIndependenceTest- Parameters:
x- the first variable, represented as an array of doublesy- the second variable, represented as an array of doubles- Returns:
- the computed p-value for the test of marginal independence
- Throws:
InterruptedException- if the computation is interrupted
-
computePValue
Default multivariate fallback: run BFIT on each column of Y and combine with Fisher. If you later add a true multivariate BFIT, override this to call it directly.- Specified by:
computePValuein interfaceRawMarginalIndependenceTest- Parameters:
x- the first variable (scalar), represented as an array of doubles of length nY- the multivariate variable, represented as a 2D array of shape [n][m] (n samples, m variables)- Returns:
- the computed p-value for the test of independence
- Throws:
InterruptedException- if the computation is interrupted
-
getAlpha
public double getAlpha()Retrieves the alpha value currently set for this instance. The alpha value is typically used as a threshold or parameter in statistical tests or computations.- Specified by:
getAlphain interfaceIndependenceTest- Returns:
- the alpha value, which is a double strictly between 0 and 1
-
setAlpha
public void setAlpha(double alpha) Sets the alpha value used as a threshold or parameter for statistical tests or computations. The alpha value must be within the range (0, 1), exclusive.- Specified by:
setAlphain interfaceIndependenceTest- Parameters:
alpha- the desired alpha value, strictly between 0 and 1- Throws:
IllegalArgumentException- if alpha is less than or equal to 0 or greater than or equal to 1
-
getRows
Description copied from interface:RowsSettableGets the rows to use for the test. These rows over override testwise deletion if set.- Specified by:
getRowsin interfaceRowsSettable- Returns:
- The rows to use for the test. Can be null.
-
setRows
Description copied from interface:RowsSettableSets the rows to use for the test. This will override testwise deletion.- Specified by:
setRowsin interfaceRowsSettable- Parameters:
rows- The rows to use for the test. Can be null.
-
getBlocks
-
getEffectiveSampleSize
public int getEffectiveSampleSize()Description copied from interface:EffectiveSampleSizeSettableReturns the effective sample size.- Specified by:
getEffectiveSampleSizein interfaceEffectiveSampleSizeSettable- Returns:
- the effective sample size
-
setEffectiveSampleSize
public void setEffectiveSampleSize(int nEff) Sets the effective sample size. The value is remembered and survives subsequentsetRowscalls.Changes from the pre-2026-8 implementation: previously,
setRowsreset the effective sample size to the row count when it rebuilt the internal delegate, so a caller-set value was silently discarded by any tool that subsamples or shuffles rows -- in particular the Markov Checker, which callssetRowson every run (even with resample fraction 1). The requested value is now stored and re-applied whenever the row set changes. Under a proper row subset, the applied effective sample size is rescaled proportionally: if the caller declares that the full data of N rows carry nEff independent observations' worth of information, a subset of m rows is treated as carrying nEff * m / N (floored at 1). Passing a negative value restores the default (effective sample size = current row count).- Specified by:
setEffectiveSampleSizein interfaceEffectiveSampleSizeSettable- Parameters:
nEff- the effective sample size, or a negative value for the default.
-
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.TESTWISE: constructed with
MissingDataSpec.testwise(), each test uses the rows complete on the embedded columns of x, y, and z.- Specified by:
getMissingValueSupportin interfaceIndependenceTest- Returns:
- This support level.
-