Draws parameter samples using the sandwich variance V_theta, simulates
predictive counts with zero-inflation and returns per-cell prediction
intervals. Two types of intervals are available: conditional (latent
variables drawn from their variational posterior, after one VE step per
draw) and marginal (latent variables drawn from their prior).
Arguments
- Y
An n x p count matrix (NAs allowed).
- X
An (n*p) x d design matrix (stacked by blocks of size n).
- fit
Estimator output list (from
Miss.ZIPLNPCA).- MC
Integer, number of Monte Carlo draws.
- type
"conditional"(default) or"marginal".- conditional
for each parameter draw, a VE step gives \(M\), \(S\) and \(\xi\); then \(U \sim \mathcal{B}(\xi)\) and \(Z_i \sim \mathcal{N}(X\beta + M_i C^\top, C\,\mathrm{diag}(S_i)\,C^\top)\).
- marginal
no VE step; \(U \sim \mathcal{B}(\mathrm{logit}^{-1}(X\gamma))\) and \(Z_i \sim \mathcal{N}(X\beta, C C^\top)\).
In both cases \(U = 1\) means presence and the prediction is \(U \times \mathcal{P}(\exp(Z))\).
- probs
Numeric vector of length 2, the lower and upper quantile levels of the interval. Default
c(0, 0.9).- output
Character vector, what to return besides the intervals. One or several of
"intervals"(always returned),"draws","latent","params", or"all".- cl
Parallelisation of the VE steps (conditional type only), passed to
pblapply.NULL(default): sequential. An integer: number of forked processes (not available on Windows). A cluster frommakeCluster: works on all platforms. All random draws are made in the main process, so results for a given seed do not depend oncl.- verbose
Logical. If
TRUE(default), prints the current step and shows progress bars for the VE steps and the simulation of the latent variables. Progress bars can also be controlled globally withpboptions.
Value
A list with elements:
lower,upper: n x p matrices of predictive quantiles at levelsprobs.draws(if requested): list withcount(Poisson draws) andpresence(Bernoulli draws \(U\)), arrays n x p x MC. The prediction iscount * presence.latent(if requested): list withZ, array n x p x MC of Gaussian latent draws, and for the conditional typeM,S(arrays n x q x MC) andxi(array n x p x MC) from the VE steps.params(if requested): list withgamma,beta(matrices MC x d) andC(matrix MC x (p*q), column-major vectorisation of C).settings: list withtype,probsandMC.
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
fit <- Miss.ZIPLNPCA(Y, X, q)
# \donttest{
# Conditional intervals (default), 90% upper bound
pi_cond <- Predictions(Y, X, fit, MC = 20)
#> Computing the sandwich variance...
#> Running 20 VE steps:
#> Simulating the latent variables:
#> Simulating the counts and computing the intervals...
pi_cond$upper[1:3, ]
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 103.4 8.9 63.4 0.1 1.0
#> [2,] 6.7 7.1 7.3 34.6 4.2
#> [3,] 7.0 1.0 8.1 0.0 6.3
# Marginal intervals at other levels, with the draws
pi_marg <- Predictions(Y, X, fit, MC = 20, type = "marginal",
probs = c(0.05, 0.95), output = "draws")
#> Computing the sandwich variance...
#> Simulating the latent variables:
#> Simulating the counts and computing the intervals...
dim(pi_marg$draws$count)
#> [1] 30 5 20
# }