Skip to contents

For counts of several categories made together on each unit, such as the sequence counts of several taxa in a sample. The data hold one row per category at each unit. Each unit's vector of K counts is multinomial with probabilities softmax(mu), where mu holds the categories' linear predictors. A unit's total is the sum of its counts and may differ between units.

Usage

multi()

Value

A family object to pass to jsdgam() or mvgam().

Details

jsdgam() fits the family, taking the unit and category columns and the number of latent factors n_lv. The constraints that identify the model are those of diri().

Identification

The softmax is unchanged when the same constant is added to every component. The data then identify neither a shift of the linear predictors that every component shares nor a shift of the loadings that every component shares. mvgam removes both:

  • The first component is the reference. Its linear predictor is subtracted from every component's before the softmax, as in brms's dirichlet() family. A term that acts on every component alike, such as Intercept or env in y ~ env * series, then cancels. Its posterior is its prior, student_t(3, 0, 2.5) by default. The series terms are contrasts with the first component. jsdgam() warns when the formula has no term that varies by component.

  • Each column of the loadings Z sums to zero, through Stan's sum_to_zero_vector type.

A loadings_prior combines with that constraint.

Post-fit conventions

The density is joint over a unit's components, which makes the unit the grain of log_lik(), loo() and waic() (Vehtari et al. 2017). log_lik() gives each unit's log density on its first row and NA on the others. loo() then counts each unit once. loo_compare() needs every model it compares scored at that grain.

posterior_linpred() gives mu per row before the reference subtraction. posterior_epred() gives the expected shares, which sum to one within each unit.

species_effects(), variance_partition() and forecast_uncertainty(scale = "link") report the predictor centred across each unit's components, the centred log-ratio scale. A shift shared by every component then drops out.

References

Warton, D. I., Blanchet, F. G., O'Hara, R. B., Ovaskainen, O., Taskinen, S., Walker, S. C. and Hui, F. K. C. (2015). So many variables: joint modeling in community ecology. Trends in Ecology and Evolution, 30(12):766-779. doi:10.1016/j.tree.2015.09.007

See also

Examples

# \dontrun{
# Counts of four categories at 60 sites, 30 per site
simdat <- sim_jsdgam(family = multi(), n_species = 4L, n_sites = 60L,
                     seed = 3L)

fit <- jsdgam(
  formula        = y ~ env * series,
  factor_formula = ~ -1,
  data           = simdat$data_train,
  unit           = time, species = series,
  family         = multi(),
  n_lv           = 1L,
  chains         = 2L,
  silent         = 2
)

# The probability of each category along the gradient
conditional_effects(fit, effects = "env:series")


# Next, residual_cor(fit) gives the correlations the factor implies
# }