Skip to contents

Generates count tables from the data-generating processes used in the simulation studies of the paper: counts are drawn from a rounded multivariate log-normal with a size factor, a three-component mixture of baseline abundances producing excess zeros, and a covariance built either from a sparse factor structure (Simulation 1) or arbitrarily by the vine method of Lewandowski, Kurowicka and Joe (Simulations 2 and 3).

Usage

simulate_spbgfm(
  n = 20,
  J = c(150, 50),
  K_true = 5,
  type = c("block", "vine"),
  active = NULL,
  covariate = FALSE,
  beta_zero = 0.8,
  zero_prop = NULL,
  v2 = 0.25,
  seed = NULL
)

Arguments

n

Number of samples. With covariate = TRUE this must be even: one sample per level is generated for each of n/2 subjects.

J

Integer vector of features per domain. Default c(150, 50).

K_true

Number of true latent factors, used when type = "block". Default 5.

type

"block" (default) builds \(\Sigma^{tr} = \Lambda^{tr} \Lambda^{tr\prime} + V^{tr}\) with only active features loading on a single randomly chosen factor, so that the remaining features do not interact. "vine" generates an arbitrary sparse correlation matrix by the vine method and rescales it with feature-specific variances.

active

List of length length(J) giving, per domain, the indices of the features that interact. Used only by type = "block". Defaults to the first half of each domain. Simulation 1 of the paper corresponds to list(c(1:25, 51:75), 1:25) with J = c(150, 50).

covariate

Logical; include a two-level categorical covariate as in Simulation 2, with a sparse effect (beta_zero of the coefficients are exactly zero). Default FALSE.

beta_zero

Probability that a covariate effect is exactly zero. Default 0.8.

zero_prop

Optional vector of per-feature probabilities of the "zero" mixture component, of length sum(J). When NULL (default) the mixture weights are drawn from Dirichlet(30, 40, 30) as in Simulation 1. Supplying the empirical zero rates of a real dataset reproduces the setup of Simulations 2 and 3.

v2

Idiosyncratic variance per domain when type = "block". Default 0.25.

seed

Optional integer seed.

Value

A list with elements Y (a list of count matrices), Sigma and cor (the true covariance and correlation), Lambda (the true loadings, type = "block" only), alpha, r, beta, X, subject and J.

References

Lewandowski, D., Kurowicka, D. and Joe, H. (2009). Generating random correlation matrices based on vines and extended onion method. Journal of Multivariate Analysis 100(9), 1989-2001.

Examples

sim <- simulate_spbgfm(n = 20, J = c(30, 10), seed = 1)
mean(do.call(cbind, sim$Y) == 0)   # proportion of zero counts
#> [1] 0.2725