View source: R/missing_data_diagnostics.R
| check_imputation_quality | R Documentation |
Compares the values that were filled in against the values that were actually observed, feature by feature, and flags an imputation that has shifted the centre or the spread of the data far enough to distort a subsequent LUCID fit. This is a sanity check on the imputation, not a measure of its accuracy: the true values are unknown, so agreement in distribution is all that can be assessed.
For each feature, the imputed values are compared with the observed ones
through a standardised mean difference,
(\bar{x}_{imp} - \bar{x}_{obs}) / s_{obs}, and a spread ratio
s_{imp} / s_{obs}. Features with no observed values or no imputed
values are skipped. The reported mean_diff is the mean absolute
standardised difference across features, and sd_ratio the mean spread
ratio. A feature that is constant where observed contributes a
sd_ratio of 1 if its imputed values are also constant, and Inf
if they are not.
The imputation is declared invalid when mean_diff exceeds 2 (the
filled values sit more than two observed standard deviations from the
observed centre), or when sd_ratio falls outside [0.3, 3] –
below that range indicates the near-constant imputation that mean-filling
produces at high missingness, which biases cluster covariances towards
singularity.
check_imputation_quality(original, imputed)
original |
The data matrix before imputation, containing |
imputed |
The same matrix after imputation, with identical dimensions
and column order. A dimension mismatch is a warning, not an error, and
returns |
A list with components:
TRUE if neither threshold was breached and at
least one feature could be compared.
Mean absolute standardised mean difference across
comparable features, or NA if none.
Mean ratio of imputed to observed standard deviation, or
NA if none.
NULL when valid; otherwise a string naming the
thresholds that were breached.
safe_impute for the imputations this is meant to
check.
Z <- matrix(rnorm(200), nrow = 20)
Z_na <- Z; Z_na[1:5, 1] <- NA
check_imputation_quality(Z_na, safe_impute(Z_na, method = "mean"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.