For continuous responses measured together on each unit, such as the
biomass of several species at a site. The data hold one row per
response component at each unit. Latent factors shared by a unit's
components give their residuals the covariance
Z Z' + diag(Psi^2), where Z holds the factor loadings and Psi
each component's residual standard deviation (Hui et al. 2015; Niku
et al. 2019). Given the factors, each row is normal with mean mu
and standard deviation Psi.
Details
jsdgam() fits the family, taking the unit and component columns
and the number of factors n_lv. residual_cor() summarises the
residual correlations and shared_variation() the part the factors
share. Psi takes the prior inv_gamma(3, 1.07), with median
0.40 and no mass at zero, which suits responses near unit scale.
prior(..., class = Psi) sets another.
With K components the data separate the factor part from the
residual part only when (K - n_lv)^2 >= K + n_lv. Fewer factors or
more components meet the bound. jsdgam() warns when it fails.
References
Hui, F. K. C., Taskinen, S., Pledger, S., Foster, S. D. and Warton, D. I. (2015). Model-based approaches to unconstrained ordination. Methods in Ecology and Evolution, 6(4):399-411. doi:10.1111/2041-210X.12236
Niku, J., Brooks, W., Herliansyah, R., Hui, F. K. C., Taskinen, S. and Warton, D. I. (2019). Efficient estimation of generalized linear latent variable models. PLOS ONE, 14(5):e0216129. doi:10.1371/journal.pone.0216129
Heaps, S. E. and Jermyn, I. H. (2024). Structured prior distributions for the covariance matrix in latent factor models. Statistics and Computing, 34:143. doi:10.1007/s11222-024-10454-0
See also
Other observation families:
beta_nb(),
categ(),
com_binomial(),
diri(),
multi(),
mvgam_families,
mvt(),
nmix(),
occ(),
tweedie()
Examples
# \dontrun{
# Five species at 80 sites whose residuals share two latent
# factors
simdat <- sim_jsdgam(family = mvn(), n_species = 5L, n_sites = 80L,
n_lv = 2L, seed = 1L)
fit <- jsdgam(
formula = y ~ env * series,
factor_formula = ~ -1,
data = simdat$data_train,
unit = time, species = series,
family = mvn(),
n_lv = 2L,
chains = 2L,
silent = 2
)
#> Warning: 7 of 2000 (0.0%) transitions ended with a divergence.
#> See https://mc-stan.org/misc/warnings for details.
#> Warning: 2 of 2 chains had an E-BFMI less than 0.3.
#> See https://mc-stan.org/misc/warnings for details.
summary(fit)
#> Family: mvn
#> Links: mu = identity
#> Formula: y ~ env * series
#> Data: simdat$data_train (Number of observations: 400)
#> Species: 5
#> Trends: 2 latent factors
#> Draws: 2 chains, each with iter = 2000; warmup = 1000; thin = 1;
#> total post-warmup draws = 2000
#>
#> == Observation Model ==
#> Regression Coefficients:
#> Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> Intercept -0.41 0.11 -0.62 -0.19 1.00 310 540
#> env 0.35 0.13 0.11 0.61 1.01 135 192
#> seriessp_2 1.47 0.15 1.17 1.77 1.00 309 585
#> seriessp_3 1.33 0.16 1.02 1.65 1.00 400 546
#> seriessp_4 1.16 0.25 0.66 1.65 1.01 274 396
#> seriessp_5 2.08 0.13 1.81 2.34 1.00 330 461
#> env:seriessp_2 -1.61 0.18 -1.96 -1.28 1.01 147 211
#> env:seriessp_3 -0.76 0.18 -1.11 -0.42 1.01 209 592
#> env:seriessp_4 -1.49 0.29 -2.06 -0.93 1.01 139 153
#> env:seriessp_5 -0.79 0.16 -1.10 -0.49 1.01 166 226
#>
#> Further Distributional Parameters:
#> Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> Psi[1] 0.46 0.12 0.22 0.66 1.01 142 220
#> Psi[2] 0.49 0.04 0.41 0.57 1.00 1154 1359
#> Psi[3] 0.41 0.14 0.18 0.68 1.00 91 267
#> Psi[4] 0.57 0.17 0.25 0.86 1.00 122 219
#> Psi[5] 0.55 0.05 0.47 0.65 1.00 1145 1254
#>
#> == Trend Model ==
#> Factor Loadings:
#> Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> Z_tilde[sp_1,1] 0.89 0.11 0.69 1.11 1.00 254 727
#> Z_tilde[sp_2,1] -0.30 0.07 -0.43 -0.17 1.00 1550 1586
#> Z_tilde[sp_3,1] -0.07 0.13 -0.34 0.18 1.00 937 1530
#> Z_tilde[sp_4,1] -1.10 0.17 -1.43 -0.78 1.00 397 1172
#> Z_tilde[sp_5,1] 0.02 0.08 -0.13 0.19 1.01 1238 1225
#> Z_tilde[sp_2,2] 0.08 0.05 0.00 0.20 1.00 1472 1347
#> Z_tilde[sp_3,2] 0.53 0.72 -1.03 1.09 1.00 1025 1174
#> Z_tilde[sp_4,2] -0.42 0.60 -0.97 0.91 1.00 1458 1187
#> Z_tilde[sp_5,2] -0.20 0.27 -0.48 0.40 1.00 1523 1573
#>
#> Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
#> and Tail_ESS are effective sample size measures, and Rhat is the potential
#> scale reduction factor on split chains (at convergence, Rhat = 1).
#>
#> Next steps:
#> - `pp_check(fit)`: posterior predictive checks
#> - `shared_variation(fit)`: covariance the factors imply, unchanged by rotation
#> - `residual_cor(fit)`: implied correlations among species
#> - `ordinate(fit)`: biplot of the factor scores and loadings
#> - `loo(fit)` / `loo_compare(...)`: model fit + comparison
#> - `conditional_effects(fit)`: covariate effects
#> Use `how_to_cite(fit)` for a methods paragraph and `methods_md(fit)` for its equations.
# The species-by-species residual correlations, against the values
# the simulation used
round(residual_cor(fit)$cor, 2)
#> sp_1 sp_2 sp_3 sp_4 sp_5
#> sp_1 1.00 -0.45 -0.07 -0.67 0.03
#> sp_2 -0.45 1.00 0.13 0.34 -0.07
#> sp_3 -0.07 0.13 1.00 -0.39 -0.45
#> sp_4 -0.67 0.34 -0.39 1.00 0.22
#> sp_5 0.03 -0.07 -0.45 0.22 1.00
round(simdat$truth$residual_cor, 2)
#> sp_1 sp_2 sp_3 sp_4 sp_5
#> sp_1 1.00 -0.46 -0.05 -0.64 0.04
#> sp_2 -0.46 1.00 0.18 0.35 -0.12
#> sp_3 -0.05 0.18 1.00 -0.37 -0.45
#> sp_4 -0.64 0.35 -0.37 1.00 0.23
#> sp_5 0.04 -0.12 -0.45 0.23 1.00
# Next, shared_variation(fit) gives the part the factors share
# }
