check_imputation_quality: Check whether imputed values are distributionally plausible

View source: R/missing_data_diagnostics.R

check_imputation_qualityR Documentation

Check whether imputed values are distributionally plausible

Description

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.

Usage

check_imputation_quality(original, imputed)

Arguments

original

The data matrix before imputation, containing NA.

imputed

The same matrix after imputation, with identical dimensions and column order. A dimension mismatch is a warning, not an error, and returns is_valid = FALSE.

Value

A list with components:

is_valid

TRUE if neither threshold was breached and at least one feature could be compared.

mean_diff

Mean absolute standardised mean difference across comparable features, or NA if none.

sd_ratio

Mean ratio of imputed to observed standard deviation, or NA if none.

warning

NULL when valid; otherwise a string naming the thresholds that were breached.

See Also

safe_impute for the imputations this is meant to check.

Examples

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"))

LUCIDus documentation built on Sept. 3, 2026, 1:06 a.m.