Class MissingDataAudit
MissingDataPolicy. The audit reports
per-variable missing counts and rates, the number of complete rows, the distinct missingness patterns and their
frequencies, and the matrix of pairwise complete counts (the number of rows on which each pair of variables is
jointly observed), whose minimum is a useful proxy for how much information test-wise deletion actually has
available for the worst pair.
For continuous datasets, littlesMcarTest() computes Little's (1988) chi-square test of the MCAR
hypothesis, using EM estimates of the mean and covariance under the saturated Gaussian model. A small p-value is
evidence against MCAR, in which case deletion-based policies (MissingDataPolicy.LISTWISE,
MissingDataPolicy.TESTWISE) are suspect and a MAR-based policy
(MissingDataPolicy.EM_COVARIANCE, MissingDataPolicy.MULTIPLE_IMPUTATION) should be preferred. A
large p-value is consistent with MCAR but does not prove it.
Missing values are Double.NaN for continuous variables and DiscreteVariable.MISSING_VALUE for
discrete variables, per Tetrad convention.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe result of Little's MCAR test: the chi-square statistic, its degrees of freedom, the p-value, and pattern accounting. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe per-variable missing rate at or above which advice() flags a variable as having high missingness.static final doubleThe alpha level advice() uses to interpret Little's MCAR test.static final intThe pairwise complete count below which advice() warns that test-wise statistics may be unstable. -
Constructor Summary
ConstructorsConstructorDescriptionMissingDataAudit(DataSet dataSet) Constructs the audit for the given dataset, computing all descriptive statistics. -
Method Summary
Modifier and TypeMethodDescriptionadvice()Rule-based advice for handling the missingness in this dataset, as a list of short paragraphs, in decreasing order of importance.booleanTrue just in case the dataset contains at least one missing entry.doubleThe mean, over pairs of distinct columns, of the pairwise complete count (seeMissingDataSpec.EffectiveSampleSizeMode.MEAN_PAIRWISE).intThe minimum, over pairs of distinct columns, of the pairwise complete count.intgetMissingCount(int column) The number of missing entries for the given column.doublegetMissingRate(int column) The fraction of entries missing for the given column.intThe number of rows with no missing entries--i.e., the sample size that listwise deletion would retain.intThe number of distinct missingness patterns among the rows.doubleThe fraction of all entries that are missing.int[][]The matrix of pairwise complete counts: entry (i, j) is the number of rows on which columns i and j are both observed.The distinct missingness patterns and their row counts.static booleanReturns true just in case the given cell of the dataset is missing, using Tetrad's conventions:DiscreteVariable.MISSING_VALUEfor discrete variables andDouble.NaNotherwise.Computes Little's (1988) chi-square test of the MCAR hypothesis for a continuous dataset, using EM estimates of the mean and covariance under the saturated Gaussian model.report()A human-readable, multi-line summary of the audit, suitable for logging via TetradLogger before a search is run.toString()A string representation of the audit.
-
Field Details
-
HIGH_MISSING_RATE
public static final double HIGH_MISSING_RATEThe per-variable missing rate at or above which advice() flags a variable as having high missingness.- See Also:
-
MCAR_TEST_ALPHA
public static final double MCAR_TEST_ALPHAThe alpha level advice() uses to interpret Little's MCAR test.- See Also:
-
SMALL_PAIRWISE_COUNT
public static final int SMALL_PAIRWISE_COUNTThe pairwise complete count below which advice() warns that test-wise statistics may be unstable.- See Also:
-
-
Constructor Details
-
MissingDataAudit
Constructs the audit for the given dataset, computing all descriptive statistics. This is a single O(n * p^2) pass over the data (for the pairwise counts).- Parameters:
dataSet- The dataset. May be continuous, discrete, or mixed.
-
-
Method Details
-
isMissing
Returns true just in case the given cell of the dataset is missing, using Tetrad's conventions:DiscreteVariable.MISSING_VALUEfor discrete variables andDouble.NaNotherwise.- Parameters:
dataSet- The dataset.row- The row index.column- The column index.- Returns:
- True if the cell is missing.
-
anyMissing
public boolean anyMissing()True just in case the dataset contains at least one missing entry.- Returns:
- True if any entry is missing.
-
getMissingCount
public int getMissingCount(int column) The number of missing entries for the given column.- Parameters:
column- The column index.- Returns:
- This count.
-
getMissingRate
public double getMissingRate(int column) The fraction of entries missing for the given column.- Parameters:
column- The column index.- Returns:
- This rate, in [0, 1].
-
getOverallMissingRate
public double getOverallMissingRate()The fraction of all entries that are missing.- Returns:
- This rate, in [0, 1].
-
getNumCompleteRows
public int getNumCompleteRows()The number of rows with no missing entries--i.e., the sample size that listwise deletion would retain.- Returns:
- This count.
-
getNumPatterns
public int getNumPatterns()The number of distinct missingness patterns among the rows.- Returns:
- This count.
-
getPatternCounts
-
getPairwiseCompleteCounts
public int[][] getPairwiseCompleteCounts()The matrix of pairwise complete counts: entry (i, j) is the number of rows on which columns i and j are both observed. The diagonal gives per-variable observed counts.- Returns:
- A defensive copy of this matrix.
-
getMinPairwiseCount
public int getMinPairwiseCount()The minimum, over pairs of distinct columns, of the pairwise complete count. This is the sample size available to test-wise deletion for the worst pair, and a candidate conservative effective sample size (seeMissingDataSpec.EffectiveSampleSizeMode.MIN_PAIRWISE).- Returns:
- This minimum, or the number of rows if there are fewer than two columns.
-
getMeanPairwiseCount
public double getMeanPairwiseCount()The mean, over pairs of distinct columns, of the pairwise complete count (seeMissingDataSpec.EffectiveSampleSizeMode.MEAN_PAIRWISE).- Returns:
- This mean, or the number of rows if there are fewer than two columns.
-
littlesMcarTest
Computes Little's (1988) chi-square test of the MCAR hypothesis for a continuous dataset, using EM estimates of the mean and covariance under the saturated Gaussian model. Rows with no observed values are excluded. Patterns whose observed-variable covariance submatrix is singular are skipped (their degrees of freedom are not counted). The result is cached.Reference: Little, R. J. A. (1988). A test of missing completely at random for multivariate data with missing values. Journal of the American Statistical Association, 83(404), 1198-1202.
- Returns:
- The test result.
- Throws:
IllegalArgumentException- If the dataset is not continuous.IllegalStateException- If the dataset has no missing values (the test is vacuous).
-
advice
Rule-based advice for handling the missingness in this dataset, as a list of short paragraphs, in decreasing order of importance. This is shared by the GUI's Data Audit dialog, causal-cmd, and py-tetrad so that all three interfaces give the same recommendations. The rules are deliberately conservative: no test can confirm MCAR or rule out MNAR, so the advice recommends policies rather than asserting assumptions.- Returns:
- The advice, one recommendation per entry; never empty.
-
report
A human-readable, multi-line summary of the audit, suitable for logging via TetradLogger before a search is run. Includes Little's MCAR test for continuous datasets with missing values.- Returns:
- This summary.
-
toString
-