Skip to main content

Uncertainty: choose a target, then choose an interval

ImportantThe question

For a chosen trait pair, is the uncertainty about the between-individual correlation, the within-individual correlation, their difference, a repeatability, or a loading? They are different targets. An interval for one is not an interval for another.

Start with the same question the data raised. For Arctic charr, how much more negative is the distance–exit time correlation between fish than across trials within fish? For dogs, how much more positive is the fear–touch sensitivity correlation between dogs than within dogs? Open the saved draws below to see how the intervals answer those questions. If you are working with a fresh fit, check Diagnostics first.

Start with the quantity you want to estimate

The model has two covariance matrices, \(\boldsymbol{\Sigma}_B\) and \(\boldsymbol{\Sigma}_W\). The first describes persistent differences among individuals after the fitted mean adjustment; the second describes deviations within an individual at a recorded occasion.

Biological sentence Calculate inside every refit
Stable differences among individuals are associated a B-level correlation
Within-individual deviations are associated a W-level correlation
The associations differ the paired contrast \(r_B-r_W\)
A trait is consistent repeatability \(R\)
A trait participates in the selected shared axes communality \(c_B^2\) or \(c_W^2\)

The contrast row matters. Do not infer a between-minus-within difference because two marginal intervals overlap or do not overlap. Calculate \(r_B-r_W\) in each generated-and-refitted data set, then take its percentiles.

What a parametric bootstrap does

For a frozen analysis specification, a parametric bootstrap:

  1. keeps the periods, trait set, observed-response pattern, response scale, fixed-effect design, B/W identifiers, rank, and unique-variance convention fixed;
  2. generates a new response under that fitted model, including fresh B and W variation, then restores the frozen observed-response pattern;
  3. refits the same model using the restored response pattern;
  4. reconstructs \(\boldsymbol{\Sigma}_B\) and \(\boldsymbol{\Sigma}_W\), then calculates the declared target; and
  5. retains the seed, fit status, failure reason, and target value for every attempt.

The result is a model-conditional 95% percentile interval. It quantifies variation under the selected model and frozen design choices. It does not demonstrate coverage for another rank, response distribution, missing-data mechanism, or temporal structure. That requires a separate simulation study.

Compare the bootstrap records

For each retained simulated dataset, subtract the within-level correlation from the between-level correlation. The two estimates come from the same selected glmmTMB refit. The interval comes from the 2.5th and 97.5th percentiles of those differences.

Main example Retained of simulated Point contrast 95% percentile interval
Charr, distance and exit time 1,066 of 2,000 −0.233 −0.342 to −0.140
Dogs, dog-directed fear and touch sensitivity 1,095 of 1,200 0.327 0.139 to 0.491

Charr refits passed the recorded numerical and covariance checks in both packages. A positive-definite Hessian was recorded separately. For dogs, both packages needed an eligible fit from the positive between-variance start, and the dog lesson explains the final screening step. In either example, the limits describe the retained draws.

The archive stores a value for each target and draw, including the paired difference already computed during aggregation. Pick out the charr contrast and calculate its limits. Run the code from the extracted repository root.

draw_dir <- "tutorial/downloads/bootstrap/main-examples"
if (!dir.exists(draw_dir)) draw_dir <- "downloads/bootstrap/main-examples"
charr_draws <- read.csv(file.path(draw_dir, "charr-target-draws.csv.gz"))
distance_exit <- subset(
  charr_draws,
  quantity == "correlation_contrast" & trait_1 == "Distance" & trait_2 == "Exit time"
)
stopifnot(nrow(distance_exit) == 1066L, !anyDuplicated(distance_exit$draw))
round(quantile(distance_exit$value, c(.025, .975)), 3)
  2.5%  97.5% 
-0.342 -0.140 

Both limits are negative. The observed contrast is negative too, which here means the between-fish correlation was more negative than the within-fish correlation. The two individual correlation intervals answer their own level-specific questions.

The saved draws and receipts and reproduction commands show how to recalculate both sets of endpoints. The archive lacks the original simulated responses, full campaign runners and failed-refit histories needed to rerun those campaigns. A fresh point fit also has its own diagnostic record and does not inherit the saved limits.

For a contrast with wide limits, read Why uncertainty matters in the six-trait red-knot example. That extension uses its own intercept-only model and bootstrap.

Match the covariance target first

Ordinary gllvmTMB::latent() defaults to unique = TRUE; the tutorials write that argument explicitly. It contains a shared low-rank component plus a diagonal unique component. In glmmTMB, rr() supplies only the shared part, so each level needs one declared source for its diagonal unique component. Usually that source is diag().

# glmmTMB: shared reduced-rank covariance + trait-specific diagonal covariance
rr(0 + trait | individual, d = 1) +
  diag(0 + trait | individual)

# gllvmTMB: the same shared-plus-unique target in one term
latent(0 + trait | individual, d = 1, unique = TRUE)

For Gaussian data, the W-level diagonal can instead be supplied by dispformula = ~ 0 + trait. The current six-trait red-knot extension uses this option at W, alongside an rr() + diag() between-bird structure. The dog model uses a W-level rr() with trait-specific dispersion. Do not include both a free W-level diag() and free trait-specific dispersion: they duplicate diagonal within-occasion variation. Each construction is matched to unique = TRUE only after reconstructing and comparing the full B and W matrices. Compare matrices and derived targets, never arbitrary loading signs.

Interval tools have different jobs

Tool Use Main limitation
glmmTMB parametric simulate-refit bootstrap Primary uncertainty for a declared correlation, contrast, repeatability, or communality Many refits; conditional on the fitted model
gllvmTMB::extract_correlations(..., method = "wald") Fast Fisher-z/Wald-style correlation sensitivity display Its effective sample size is a heuristic
gllvmTMB::extract_correlations(..., method = "bootstrap") and bootstrap_Sigma() Package-native simulate-refit interval for supported targets Check interval status, failures, and simulator warnings
gllvmTMB::loading_ci() Wald or profile interval for a stated loading entry The result depends on the loading sign and rotation

gllvmTMB accepts method = "profile" for loading intervals, but a profile interval is deliberately unavailable for trait correlations: its constrained correlation-profile prototype is not yet adequate.

gllvmTMB: fast checks and a matched bootstrap route

For a fitted gllvmTMB model using the TMB engine, the code below requests B and W correlations. method = "wald" is a documented alias for a Fisher-z heuristic. It is useful as a quick sensitivity display, but its n_eff must have a stated rationale. Do not copy a value from these examples: use the bootstrap route when that rationale is unavailable.

n_eff <- NA_integer_
if (is.na(n_eff)) stop("Set n_eff only after recording a design-specific rationale; otherwise use bootstrap.")
cor_wald <- gllvmTMB::extract_correlations(
  fit_gllvm,
  tier = c("unit", "unit_obs"),
  method = "wald",
  level = 0.95,
  n_eff = n_eff
)
cor_wald[, c("tier", "trait_i", "trait_j", "correlation",
             "lower", "upper", "method", "interval_status")]

For a supported model, ask for package-native bootstrap correlations. The returned interval_status belongs in the report: it states that the interval is target-specific and does not certify general frequentist coverage.

cor_boot <- gllvmTMB::extract_correlations(
  fit_gllvm,
  tier = c("unit", "unit_obs"),
  method = "bootstrap",
  nsim = 999,
  seed = 20260908
)
cor_boot[, c("tier", "trait_i", "trait_j", "correlation",
             "lower", "upper", "method", "interval_status")]

For covariance matrices, repeatability, and communality, bootstrap_Sigma() is more direct. Its argument names repeatability ICC; its R entry denotes a correlation matrix. It redraws random effects by default for documented tiers and refits the model. Record the seed, n_failed, model version, and input version beside any interval.

sigma_boot <- gllvmTMB::bootstrap_Sigma(
  fit_gllvm,
  n_boot = 999,
  level = c("unit", "unit_obs"),
  what = c("Sigma", "ICC", "communality"),
  conf = 0.95,
  seed = 20260908,
  n_cores = 1,
  keep_draws = TRUE
)

sigma_boot$n_failed
sigma_boot$ci_lower
sigma_boot$ci_upper

If simulation warns that a random-effect tier was not redrawn, its interval can be too narrow. The Julia engine currently returns point-only correlation rows. Inspect gllvmTMB::check_gllvmTMB(fit_gllvm) before interval work, and never turn a clean point estimate into an interval claim when refits or the simulator fail.

Compare implementations as three separate questions

  1. Point target: do reconstructed \(\boldsymbol{\Sigma}_B\), \(\boldsymbol{\Sigma}_W\), correlations, repeatabilities, and communalities agree under a matched specification?
  2. Uncertainty calculation: does the primary glmmTMB bootstrap agree broadly with an appropriate gllvmTMB interval for the same derived target? Compare bounds and failure records for the same target.
  3. Scientific conclusion: does the biological statement survive uncertainty and model-checking limits? Software agreement does not establish causation, distributional adequacy, or coverage across designs.

For charr and dogs, the selected glmmTMB refits supply the published intervals. In the six-trait red-knot lesson, the selected gllvmTMB fit supplies the estimates and the bootstrap. Agreement between packages checks the implementation. The interval belongs to its own model and refit rule.

Report it so a reader can assess it

Start with the pair and the level. For example, “The estimated between-fish correlation between distance and exit time was [estimate], with a 95% bootstrap percentile interval of [lower] to [upper] among the retained refits.” Then identify the observations, response scale, mean adjustment, rank and refit screening rule. Keep the counts tied to the model. For instance, the ten-score dog example uses 900 annual records from 100 dogs.

For a contrast, write the contrast directly: “The B-minus-W correlation interval was calculated inside each bootstrap refit.” Do not call one association stronger because one marginal interval is narrower or excludes zero while the other does not. Report and reproduce gives a reporting template, and Downloads contains the available derived results and receipts.