Skip to contents

Draws a synthetic OTU count matrix (and, optionally, covariates) directly from the zero-inflated multivariate rounded log-normal model, together with the true parameter values used to generate it. Useful for examples, unit tests and checking parameter recovery with ZI_MLN().

Usage

simulate_zimln(
  n = 20,
  J = 150,
  K = 5,
  zero.rate = 0.8,
  sig2 = 1,
  vs2 = 1,
  p = 0,
  M = n,
  m = NULL,
  seed = 1
)

Arguments

n

Number of samples.

J

Number of OTUs (features).

K

Number of latent factors used to build the true covariance.

zero.rate

Proportion of entries in each column of the true loading matrix Lambda set to zero (controls covariance sparsity). Default 0.8.

sig2

True idiosyncratic variance \(\sigma^2\) (default 1).

vs2

True subject random-effect variance \(u_s^2\) (default 1).

p

Number of continuous covariates to generate. 0 (default) produces a no-covariate data set (X is NULL).

M

Number of subjects/groups (default n, i.e. one sample per subject).

m

Optional length-n subject index. Defaults to a balanced assignment of the n samples to the M subjects.

seed

Random seed (default 1).

Value

A list with the simulated data and the ground truth:

Y

n by J integer count matrix (the model input).

X

n by p covariate matrix, or NULL when p = 0.

m,M

subject index and subject count.

Lambda,sig2,vs2

true covariance components.

Omega,true.cor

true covariance Lambda Lambda' + sig2 I and the true marginal correlation matrix cov2cor(Omega + vs2 I).

ri,thetaj,smj

true sample-size / OTU-size factors and subject random effects.

beta

true J by p regression coefficients (NULL when p = 0).

kappa

true J by p + 1 probit zero-inflation coefficients.

eps

n by J true absence probabilities \(\epsilon_{ij}\).

delta

n by J true presence indicators (1 = present).

See also

Examples

sim <- simulate_zimln(n = 20, J = 30, K = 3, seed = 1)
dim(sim$Y)
#> [1] 20 30
mean(sim$Y == 0)   # overall zero rate
#> [1] 0.29