Skip to contents

A latent effect for each unit, such as a site, plot or time point, drawn from a multivariate normal that correlates the series. Unlike the other trends, the effect at one unit does not depend on the previous one. The constructor records its arguments. The model evaluates them against the data.

Usage

ZMVN(
  time = NA,
  series = NA,
  gr = NA,
  subgr = NA,
  n_lv = NULL,
  cor = TRUE,
  trend_map = NULL,
  df = Inf,
  centred = FALSE
)

Arguments

time

The unquoted name of the numeric or integer variable in data that indexes the units, such as sites, plots or times. Defaults to time, as for the other trends.

The values may have any spacing. Each unit's effects follow \(x_{u, :} \sim MVN(0, \Sigma)\), with \(\Sigma\) indexed by series alone. The gap between two units plays no part. That suits sites, dropped units, k-fold refits and irregular sampling.

series

The unquoted name of the factor variable in data that names each row's series. Its levels fix the order of the series. A trend needs this column even for a single series. Defaults to series.

gr

An optional grouping factor in data. Each of its levels takes its own correlation matrix among the latent effects. Each matrix shrinks toward a global one by the weight alpha_cor_trend, as trend_constructors sets out. Without subgr, the series column names the series within each level.

subgr

A subgrouping factor in data naming the units within each level of gr, from which the series are built as trend_constructors describes. For species (species) counted at sites (site) in regions (region), time = site, gr = region and subgr = species correlate the species' latent effects within each region.

n_lv

The number of latent factors to estimate for dynamic factor models. When n_lv is smaller than the number of series, the latent processes are modelled as n_lv factors with estimated loadings onto the series. Defaults to NULL, in which case one latent process is used per series.

cor

Logical. Correlate the innovations of different series? TRUE estimates a full covariance matrix of the innovations when the data hold more than one series. AR() and RW() default to NULL. That means FALSE for an ungrouped trend and TRUE when gr names a grouping variable. VAR(), ZMVN() and grouped AR() and RW() trends always estimate correlations. They refuse cor = FALSE. CAR() defaults to FALSE.

In a factor model with every loading sampled, the factors take independent shocks. The loadings carry the correlation among series, which residual_cor() reports. A correlation among the factors would trade off against the loadings. AR(), RW() and LLT() refuse cor = TRUE there. A trend_map that fixes the loadings keeps the factors apart. cor = TRUE then estimates their correlation.

trend_map

Optional map of the series onto the latent processes, which fixes some or all loadings of a dynamic factor model. One of three forms:

  • a numeric n_series x n_lv matrix of loadings. NA entries are sampled and finite entries stay fixed. An all-NA matrix, such as matrix(NA, n_series, 2), fixes nothing and sets two factors.

  • a data.frame(series, trend) placing each series on one process, with a loading of one.

  • "identity", one process per series, or "shared", one process for every series.

Its columns set the number of factors, which an n_lv given too must match. Without a trend_map every loading is sampled and identified after sampling by a thin QR rotation (Heaps and Jermyn 2024). A map that fixes any loading takes no rotation. The loadings_prior of mvgam() accepts a map with no fixed entries. Defaults to NULL.

df

Degrees of freedom for the latent process innovations. Defaults to Inf, which gives Gaussian innovations: a t with infinite degrees of freedom is a normal. Set df = NA to estimate them, or supply a number above 2 to fix them.

Finite degrees of freedom let the latent process absorb an occasional large shock while sigma_trend stays at the scale of ordinary variation. That suits boom-and-bust population series and outbreak dynamics. The innovations follow a multivariate t. Because it shares one innovation scale across the series at each time point, large innovations tend to occur together. Each series keeps its own direction and magnitude. A shock in one series says nothing about the sign of the others. One series can also stay unmoved by an event that moves its neighbours. cor sets the correlation between series exactly as it does for Gaussian innovations. The degrees of freedom set how heavy the tails of the innovations are.

When df = NA the degrees of freedom are estimated as nu_trend, with a default gamma(4, 0.3) prior. The prior argument replaces it, for example prior(gamma(2, 0.1), class = "nu_trend"). get_prior lists nu_trend with the other trend classes.

Three caveats apply:

  • A fixed value must exceed 2. Below it the innovations have no finite variance. An autoregressive trend then has no stationary covariance to start from.

  • The first states of an autoregressive trend take the stationary mean and covariance. Under t innovations the true stationary distribution has heavier tails than that.

  • Only the tails of the latent process inform the degrees of freedom. Below roughly 200 time points their posterior stays close to the prior.

VAR() samples its states directly and PW() has no innovations. Neither takes df.

centred

Logical. Sample the latent states directly rather than their innovations? Default FALSE. The model and its posterior are the same. See Centred states below.

Value

An object of class mvgam_trend.

Identification

A factor model with sampled loadings fits equally well under any reordering or sign change of its factors. Some models also fit equally well under any rotation. mvgam reports one version, chosen by the dynamics of the factors:

  • AR() factors take their own coefficients, as do RW() and AR() factors with ma = TRUE. A rotation would mix those coefficients. After sampling, the factors of every draw are reordered and signed to agree with one reference. The loadings Z, the factor paths lv_trend and the coefficients ar1_trend or theta1_trend move together. Factors are numbered by the variance they explain, largest first.

  • RW(), VAR() and ZMVN() factors without a moving-average term are unchanged by rotation. So are AR() factors with coef_sharing = "shared" and no moving-average term. Following Heaps & Jermyn (2024), generated quantities rotate each draw to lower-triangular loadings Z_tilde with a non-negative diagonal. The factor paths rotate to lv_trend_tilde. A VAR factor model rotates its coefficients to Phi_trend_tilde.

Post-fit methods use the identified loadings and factor paths. shared_variation() and residual_cor() are the same under every version.

A trend_map keeps its fixed entries on Z exactly. A by = lv_axis() smooth ties each factor to its own covariate effect. Neither takes a rotation. For a model with every loading sampled, the loadings_prior argument of mvgam() replaces the default iid Student-t prior on Z with a structured matrix-normal prior. That prior is built from per-series features, pairwise distance matrices or both. See mvgam for its arguments.

Setting loadings_prior = "mgp" (or loadings_prior = list(column_shrinkage = "mgp")) switches the column scaling to the multiplicative gamma process prior of Bhattacharya & Dunson (2011), which shrinks later columns of Z toward zero with increasing strength. n_lv is then a truncation ceiling on the factor count. active_factors reports the posterior distribution of the number of active factors.

References

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

jsdgam() fits ZMVN() factors across species. residual_cor() and ordinate() interpret the fitted correlations. The dynamic factor vignette builds factor models with a partial trend_map. The integrated distribution model article shares one latent process across several observation families.

Other trend models: LLT(), PW(), list_trend_types(), lv_axis(), print.mvgam_trend()

Examples

# \dontrun{
# Simulate counts of four series whose latent effects are correlated
# at each time point but independent over time.
set.seed(2)
simdat <- sim_mvgam(
  family       = poisson(),
  n_series     = 4L,
  n_timepoints = 120L,
  trend_model  = ZMVN(),
  prop_trend   = 0.9
)

mod <- mvgam(
  y ~ 1,
  trend_formula = ~ ZMVN(),
  data          = simdat$data_train,
  family        = poisson(),
  chains        = 2,
  silent        = 2
)
summary(mod)
#>  Family: poisson 
#>   Links: mu = log 
#> Formula: y ~ 1 
#>    Data: simdat$data_train (Number of observations: 360) 
#>  Series: 4 
#>  Trends: ZMVN 
#>   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     1.68      0.06     1.56     1.80 1.00      678      868
#> 
#> == Trend Model ==
#> Trend Specific Parameters:
#>                       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
#> sigma_trend[series_1]     0.73      0.08     0.59     0.91 1.00      593
#> sigma_trend[series_2]     0.68      0.07     0.55     0.84 1.00      925
#> sigma_trend[series_3]     0.81      0.08     0.66     0.98 1.00      680
#> sigma_trend[series_4]     0.75      0.07     0.62     0.90 1.00      799
#>                       Tail_ESS
#> sigma_trend[series_1]      692
#> sigma_trend[series_2]     1216
#> sigma_trend[series_3]     1068
#> sigma_trend[series_4]     1314
#> 
#> 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
#>   - `residual_cor(fit)`: implied correlations among series
#>   - `loo(fit)` / `loo_compare(...)`: model fit + comparison
#> Use `how_to_cite(fit)` for a methods paragraph and `methods_md(fit)` for its equations.

# The correlations among the series that ZMVN() estimates
rc <- residual_cor(mod)
rc
#> Residual correlations from an mvgam fit
#>   Source     : correlated innovations
#>   Covariance : stationary
#>   Series     : 4
#>   Mean |r_ij| (i != j): 0.34 [0.22, 0.47]
#>   Pairs with prob_nonzero > 0.95: 6 / 6
plot(rc)


# Next: jsdgam() fits ZMVN() factors across many species
# }