Draw multiple imputations for the missing values of a numeric matrix under a low-rank model using the Audigier, Husson and Josse (BayesMIPCA) data-augmentation sampler.
Usage
mipca(
obj,
rank,
transform,
subset = NULL,
keep_state = FALSE,
prop_diag = 0.5,
iter_sampling = 100,
iter_warmup = 100,
thin = 1,
nu = Inf,
chains = 4L,
refresh = 0L,
spectra = spectra_opts(),
init = 1,
seed = NULL,
abb = NULL
)Arguments
- obj
A double matrix with samples in rows and features in columns. Row and column names are required and must be unique.
NAandNaNvalues are imputed.- rank
Integer. Number of principal components in the model. Use
mipca_tune()to choose the rank on held-out values.- transform
Character or a transform object. The scale the model is fitted on:
"identity","logit_biwhiten", or an object fromtf_identity(),tf_sv()ortf_biwhiten(). See Details inmipca().- subset
Optional character or integer vector. The columns whose draws are kept and returned, by name or by number, or
NULLfor every column. Defaults toNULL.- keep_state
Logical. If
TRUE, return a fit thatupdate()can extend at the cost of memory. Defaults toFALSE.- prop_diag
Numeric scalar between
0and1. Proportion of each column's missing values on whichsummary()computes Rhat and ESS.0is refused. Defaults to0.5.- iter_sampling
Integer. Number of draws kept per chain. Defaults to
100.- iter_warmup
Integer. Number of iterations discarded at the start of each chain,
0or more. Defaults to100.- thin
Integer. After warmup, each chain keeps one iteration in every
thin, so it runsiter_sampling * thiniterations to keepiter_samplingdraws. Defaults to1.- nu
Numeric. Degrees of freedom of the noise drawn for a missing value:
Inffor Gaussian noise, or a number above2for Student-t noise of the same variance. Defaults toInf. Can be chosen bymipca_tune().- chains
Integer. Number of independent chains. Defaults to
4.- refresh
Integer. Print a progress line every
refreshiterations of each chain, or0for none. Defaults to0.- spectra
A
spectra_optsobject. Settings for the eigensolver, fromspectra_opts().- init
Numeric. How widely each chain's starting values are spread: each missing value starts at a random draw whose standard deviation is
inittimes its column's observed standard deviation. Must be positive. Defaults to1.- seed
Integer, numeric, or
NULL. Seed for the sampler. WithNULL, the seed is drawn from R's random number stream. Defaults toNULL.- abb
Optional character or integer vector. Columns to draw by approximate Bayesian bootstrap instead of by the model.
abb_cols()proposes them. Defaults toNULL.
Value
With keep_state = FALSE, a finalized fit of class si_mi. It
holds chains * iter_sampling draws of every missing value in the selected
columns. Use:
as.matrix(fit, draw = b)for the completed matrix at drawb.summary()for Rhat and ESS.cbind()to join fits made over different columns.
With keep_state = TRUE, a resumable fit of class si_mi_pca. Extend it
with update(), then finish it with mipca_finalize().
Details
The transform. "identity" fits the values as they are.
"logit_biwhiten" is for proportions such as DNAm beta values, and every
observed value must lie in [0, 1]; see tf_sv() and tf_biwhiten(). Draws
are returned on the scale of obj.
Which columns take part. Every column of obj takes part in the model,
and every missing value is drawn at every iteration. subset selects only
which columns' draws are kept. The result holds the selected columns in the
order they have in obj.
Size. The draws hold one number per missing value kept, per chain, per
draw. Keep fewer columns with subset, or ask for fewer chains or
iter_sampling. If the selected columns have no missing values, the fit is
returned without sampling.
Reproducibility. With the same seed, or the same set.seed() before a
call with seed = NULL, the draws are the same.
Performance
Linking R to a faster BLAS can make the sampler significantly faster: OpenBLAS on Windows, or Apple's Accelerate on macOS.
References
Audigier V, Husson F, Josse J (2016). Multiple imputation for continuous variables using a Bayesian principal component analysis. Journal of Statistical Computation and Simulation, 86(11), 2140-2156. doi:10.1080/00949655.2015.1104683
See also
mipca_tune()andmipca_fit()to chooserankandnuon held-out values, then fit.mipca_flank_plan()to fit each target column on a window of its neighbors by location.pca_imp()for a single imputation.
Examples
set.seed(1)
sim <- sim_mat(n = 50, p = 20, beta = TRUE)
fit <- mipca(sim$input, rank = 2, transform = "logit_biwhiten", seed = 1)
fit
#> si_mi fit: 50 x 20, 100 imputed cells, 400 draws
#> next: as.matrix() with 'draw' for a completed matrix, summary() for Rhat and ESS
completed <- lapply(c(1, 200, 400), function(b) as.matrix(fit, draw = b))
summary(fit)
#> si_mi_summary: Rhat and ESS for 50 cells in 10 columns
#> prop_diag 0.5, 4 chains x 100 draws
#> 0% 25% 50% 75% 100%
#> rhat 0.996 1 1.01 1.01 1.03
#> ess 153.000 291 330.00 354.00 409.00
#> worst 6 cells by rhat:
#> chunk col name row rhat ess
#> 1 10 feature10 11 1.029468 230.5473
#> 1 7 feature7 4 1.017100 333.5527
#> 1 14 feature14 2 1.016376 348.8917
#> 1 10 feature10 28 1.016294 219.3950
#> 1 20 feature20 5 1.016222 266.4496
#> 1 15 feature15 35 1.015993 300.7472