safe_impute: Single-value imputation that tolerates fully missing columns

View source: R/missing_data_diagnostics.R

safe_imputeR Documentation

Single-value imputation that tolerates fully missing columns

Description

Fills missing entries feature by feature with a single summary of that feature's observed values. This is a starting point for the EM algorithm, not a substitute for it: LUCID's own E-step imputes missing omics values under the fitted cluster model (an internal EM detail, not part of the public API), and single-value filling here only has to be finite and roughly located.

Unlike a bare mean(x, na.rm = TRUE), a feature with no observed value does not yield NaN: it falls back to the mean over the whole matrix and warns. Note that this fallback uses the mean whichever method was requested, since a median or limit of detection is not defined for a feature with nothing observed.

Usage

safe_impute(Z, method = c("mean", "median", "lod"))

Arguments

Z

A numeric matrix with missing values coded NA.

method

The summary used to fill a feature:

"mean"

The feature's observed mean.

"median"

The feature's observed median; preferable for a skewed feature, where the mean is pulled towards the tail.

"lod"

The feature's observed minimum divided by \sqrt{2}, the standard substitution for values below an assay's limit of detection. This is appropriate only for data on the original measurement scale, where the minimum stands in for the detection limit; on centred or standardised data the observed minimum is negative and dividing it by \sqrt{2} moves the filled value up, which is not what the convention intends.

Value

A matrix of the same dimensions as Z with no missing values, unless every value of Z is missing, in which case Z is returned unchanged with a warning.

See Also

check_imputation_quality to check the result, and the init_impute argument of estimate_lucid for the imputation LUCID applies internally.

Examples

Z <- matrix(rnorm(100), nrow = 10)
Z[2:4, 2] <- NA
colMeans(is.na(safe_impute(Z, method = "median")))

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