Skip to contents

Draws from the posterior predictive distribution of the count of one or more features for a new sample, at a chosen sample size factor and covariate value. This is the model-checking device used in the paper: comparing these predictive draws with the observed counts (rescaled by normalize_counts) shows whether the model reproduces the excess zeros, over-dispersion and multimodality of the data.

Usage

posterior_predict(
  fit,
  features = NULL,
  r_pred = 0,
  x = NULL,
  ndraws = NULL,
  seed = NULL
)

Arguments

fit

A fitted "spbgfm" object.

features

Integer vector of feature (column) indices in the concatenated table, or NULL (default) for all features.

r_pred

Sample size factor of the new sample: a single number applied to all domains, or a length-\(M\) vector. Default 0, matching the figures in the paper.

x

Covariate vector of length p for the new sample. Required when the model was fitted with a covariate.

ndraws

Number of posterior draws to use, taken from the end of the chain. Default NULL, meaning all saved draws.

seed

Optional integer seed.

Value

An ndraws x length(features) integer matrix of predictive counts.

Details

For each retained posterior draw a new baseline abundance \(\alpha^{\mathrm{pred}}_{mj}\) is generated from the fitted mixture \(G_{mj}\), and the latent count is drawn from \(\mathrm{log-N}(r^{\mathrm{pred}}_m + \alpha^{\mathrm{pred}}_{mj} + x'\beta_{mj},\ \Sigma^{mm}_{jj})\) and rounded down. Using the marginal variance \(\Sigma^{mm}_{jj} = \lambda_{mj}'\lambda_{mj} + v_m^2\) integrates the latent factors \(\eta_i\) out.

See also