Skip to contents

Partitions the link-scale variance of a fitted sdmTMB model among its random components using sdmTMB::tidy(), and plots the proportion of that variance from each. This is an approximate, descriptive summary, not a formal variance decomposition.

Usage

plot_variance_partitioning(fit, base_size = 11)

Arguments

fit

A fitted sdmTMB::sdmTMB() model.

base_size

Numeric. Base font size. Default 11.

Value

A ggplot object.

Details

Included are the components with a variance on the link scale:

  • the spatial field (sigma_O) and spatiotemporal field (sigma_E);

  • random intercepts (sd__(Intercept), one per grouping factor);

  • the observation-level variance on the link scale, where the family has one that does not depend on the mean (Nakagawa et al. 2017, doi:10.1098/rsif.2017.0213 ): phi^2 for a gaussian() family with an identity link and for lognormal(); trigamma(phi) for Gamma() with a log link (phi is the shape); pi^2 / 3 for a binomial() with a logit link; and pi^2 / 6 for a complementary log-log link, which includes the first component of a Poisson-link delta model (type = "poisson-link"), whose encounter probability is 1 - exp(-exp(eta)).

Left out are the observation-level variances that depend on the mean (e.g. Tweedie, Poisson, NB2), smooth-term SDs (sd__s(...), the SD of penalised spline coefficients, not of the fitted smooth) and spatially varying coefficient SDs (sigma_Z, whose contribution scales with the covariate). The proportions are therefore of the variance of the included components only. For delta models, each component is partitioned on its own link scale.

AI assistance

AI-assisted (model not recorded); not yet reviewed in full by the current model. Edited by Claude Opus 5.5 (Anthropic), 2026-11-24.

See also

Author

Mikko Vihtakari

Examples

# \donttest{
mesh <- sdmTMB::make_mesh(sdmTMB::pcod, c("X", "Y"), cutoff = 20)
m <- sdmTMB::sdmTMB(
  density ~ 0 + as.factor(year), data = sdmTMB::pcod, time = "year",
  mesh = mesh, family = sdmTMB::tweedie()
)
plot_variance_partitioning(m)

# }