Fits a Poisson log-normal PCA model (PLN-PCA) to a count matrix with missing values, using a variational objective optimized by NLOpt-based routines. The function estimates model/variational parameters and returns expected counts to impute missing entries.
Arguments
- Y
Numeric
n x pcount matrix. May containNA.- X
Numeric design matrix of covariates: either
n x d(rowwise) or(n*p) x d(vectorized to matchMatrixToVector(Y)).- O
Optional numeric
n x pmatrix of offsets (default: zeros).- w
Optional numeric vector of length
nwith observation weights (default: all ones).- q
Integer, latent rank (dimension of the latent space).
- params
Optional initial parameters (list) typically produced by
Init; ifNULL, they are initialized internally.- config
Optional optimizer configuration; if
NULL, defaults toPLNPCA_param()$config_optim.
Value
A list with components:
mStepList with
beta(1 x d) andC(p x q).eStepList with
M(n x q) andS(n x q).predList with
Aandpredicted, both equal to then x pmatrix of expected counts used for imputation: $$ A = \exp\!\big(O + X B + M C^\top + 0.5\,(S\odot S)\,(C\odot C)^\top\big), $$ where \(\odot\) denotes the Hadamard product andX Bis reshaped ton x pwhenXis vectorized.iterInteger, number of iterations.
elboPathNumeric vector of objective (ELBO) values over iterations.
elboFinal ELBO value.
params.initThe initial parameters used.
monitoringOptimizer log/diagnostics as returned by the backend.
Details
Two designs for X are supported:
Rowwise design (
nrow(X) == n): one row per sample.Vectorized design (
nrow(X) == n*p):Xaligns withvec(Y)(vectorization by columns).
Examples
if (FALSE) { # \dontrun{
set.seed(1)
n <- 40; p <- 12; d <- 2; q <- 2
Y <- matrix(rpois(n*p, 2), n, p)
Y[sample(length(Y), 20)] <- NA
X <- cbind(1, rnorm(n)) # rowwise design
fit <- Miss.PLNPCA(
Y = Y, X = X, q = q,
O = matrix(0, n, p),
w = rep(1, n),
params = NULL,
config = NULL
)
str(fit$pred$A) # expected counts (n x p)
fit$elbo # final ELBO
} # }