Model selection over candidate latent dimensions (BIC or ICL)
Source:R/select_model_bic.R
select_model_bic.RdFor each value in latents, fits a model with fun and computes
the chosen criterion (BIC or ICL). Returns the
criterion values, the latent dimension that maximizes the criterion and the
corresponding fit.
Arguments
- Y
Numeric
n x pcount matrix (NAs allowed).- X
Design matrix,
(n*p) x d.- fun
Fitting function, called as
fun(Y = Y, X = X, q = q)(e.g.Miss.ZIPLNPCAorMiss.PLNPCA).- latents
Integer vector of candidate latent dimensions.
- model
"ZIPLNPCA"(default) or"PLNPCA"; must matchfun. Passed toBICandICL.- criterion
"BIC"(default) or"ICL".
Value
A list with elements:
criterion: the criterion used.values: numeric vector of criterion values, named bylatents.q_star: the latent dimension maximizing the criterion.fit_star: the fit obtained withq_star.
Details
A progress bar is displayed via pbapply. The function checks
that model matches the fits returned by fun: a ZIP-PLN-PCA fit
contains mStep$gamma, a PLN-PCA fit does not.
Examples
set.seed(1)
n <- 30; p <- 5; d <- 2; q <- 2
X <- cbind(1, rnorm(n * p)) # (n*p) x d design
theta <- list(B = matrix(c(1, 0.5)), D = matrix(c(1, -0.5)),
C = matrix(rnorm(p * q, sd = 0.5), p, q))
Y <- Simul(X, theta, list(n = n, p = p, d = d, q = q))$Y
Y[sample(n * p, 20)] <- NA # missing entries
# \donttest{
sel <- select_model_bic(Y, X, Miss.ZIPLNPCA, latents = 1:3)
sel$values
#> 1 2 3
#> -265.5805 -267.4293 -272.9659
sel$q_star
#> [1] 1
fit <- sel$fit_star
sel_icl <- select_model_bic(Y, X, Miss.ZIPLNPCA, latents = 1:3,
criterion = "ICL")
sel_icl$q_star
#> [1] 1
# }