Skip to contents

gllvmTMBcontrol(priors = ...) accepts one table for response fixed coefficients, the existing blanket loading ridge, a narrowly supported Gaussian residual standard deviation, and a named kernel’s trait-specific Psi standard deviation on the supported Gaussian route. Each row names its target class and coefficient or target selectors. These targets remain distinct: a residual-SD prior does not regularize a latent loading or a kernel Psi SD.

Supported rows

class prior Target
fixef normal(mean, sd) or student_t(location, scale, df) One exact response fixed-effect coefficient with dpar = "mu" and scale = "link"
fixef or loading ridge(lambda) Existing quadratic fixed-effect penalty, or the existing blanket loading ridge (coef = "all", scale = "loading_coef")
residual_sd gamma(mean, shape) One constant Gaussian residual SD (dpar = "sigma", coef = "(Intercept)", scale = "natural_sd")
unique_variance gamma(mean, shape) One named kernel’s trait-specific Psi SD (trait, kernel, scale = "natural_sd")

The residual-SD row is currently limited to complete, unit-weight Gaussian fits with one estimated residual SD, using native TMB ML with Laplace integration. The Gamma shape must exceed one. Its normalized density is defined on the natural SD sigma; optimization uses log(sigma), but no log-SD Jacobian is added. This is a penalized-ML / SD-scale MAP point estimate, not a fully specified posterior fit.

For a named kernel with unique = TRUE, a unique_variance row instead targets the trait-specific SD sqrt(Psi[t,t]). The row uses trait and kernel selectors; coef and dpar are empty. The Gamma mean must be finite and positive, and its shape must be finite and greater than one. The same natural-SD density convention applies, and the normalized Psi penalty can be combined with fixed-effect and residual-SD rows when the complete-data, unit-weight Gaussian route is supported. The legacy kernel_psi_sd_prior control remains available for half-normal sensitivity fits.

Here the single table regularizes a response coefficient, the residual SD, and one trait’s unique SD in a named kernel:

set.seed(20261124)
n <- 8L
species <- paste0("s", seq_len(n))
K <- 0.5^abs(outer(seq_len(n), seq_len(n), "-"))
dimnames(K) <- list(species, species)
kernel_data <- data.frame(
  species = factor(species, levels = species),
  row_id = factor(species, levels = species),
  y1 = sin(seq_len(n) / 2),
  y2 = cos(seq_len(n) / 3)
)
kernel_priors <- data.frame(
  prior = c("normal(0,2)", "gamma(2,3.6)", "gamma(1.5,2)"),
  class = c("fixef", "unique_variance", "residual_sd"),
  coef = c("traity1", "", "(Intercept)"),
  dpar = c("mu", "", "sigma"),
  trait = c("", "y1", ""),
  kernel = c("", "phy", ""),
  scale = c("link", "natural_sd", "natural_sd")
)
kernel_fit <- suppressWarnings(gllvmTMB(
  traits(y1, y2) ~ 1 + kernel_latent(
    species, K = K, d = 1, name = "phy", unique = TRUE
  ),
  data = kernel_data, family = gaussian(), unit = "row_id",
  cluster = "species",
  control = gllvmTMBcontrol(priors = kernel_priors, se = FALSE)
))
kernel_fit$prior_table_resolved
#> [[1]]
#> [[1]]$prior
#> [1] "normal(0,2)"
#> 
#> [[1]]$class
#> [1] "fixef"
#> 
#> [[1]]$kind
#> [1] "normal"
#> 
#> [[1]]$coef
#> [1] "traity1"
#> 
#> [[1]]$dpar
#> [1] "mu"
#> 
#> [[1]]$scale
#> [1] "link"
#> 
#> [[1]]$args
#> [1] 0 2
#> 
#> [[1]]$trait
#> [1] ""
#> 
#> [[1]]$kernel
#> [1] ""
#> 
#> [[1]]$measure
#> NULL
#> 
#> 
#> [[2]]
#> [[2]]$prior
#> [1] "gamma(2,3.6)"
#> 
#> [[2]]$class
#> [1] "unique_variance"
#> 
#> [[2]]$kind
#> [1] "gamma"
#> 
#> [[2]]$coef
#> [1] ""
#> 
#> [[2]]$dpar
#> [1] ""
#> 
#> [[2]]$scale
#> [1] "natural_sd"
#> 
#> [[2]]$args
#> [1] 2.0 3.6
#> 
#> [[2]]$trait
#> [1] "y1"
#> 
#> [[2]]$kernel
#> [1] "phy"
#> 
#> [[2]]$measure
#> [1] "natural_sd"
#> 
#> 
#> [[3]]
#> [[3]]$prior
#> [1] "gamma(1.5,2)"
#> 
#> [[3]]$class
#> [1] "residual_sd"
#> 
#> [[3]]$kind
#> [1] "gamma"
#> 
#> [[3]]$coef
#> [1] "(Intercept)"
#> 
#> [[3]]$dpar
#> [1] "sigma"
#> 
#> [[3]]$scale
#> [1] "natural_sd"
#> 
#> [[3]]$args
#> [1] 1.5 2.0
#> 
#> [[3]]$trait
#> [1] ""
#> 
#> [[3]]$kernel
#> [1] ""
#> 
#> [[3]]$measure
#> NULL
kernel_fit$objective_components
#> $likelihood_nll
#> [1] 6.523044
#> 
#> $ridge_penalty
#> [1] 0
#> 
#> $fixed_effect_prior_nll
#> [1] 1.620498
#> 
#> $kernel_psi_sd_prior_nll
#> [1] 2.483232
#> 
#> $optimization_nll
#> [1] 12.49541
#> 
#> $optimizer_reported
#> [1] 12.49541
#> 
#> $residual_sd_prior_nll
#> [1] 1.868633
set.seed(20261122)
n <- 36L
binomial_data <- expand.grid(
  trait = factor(c("a", "b")),
  unit = factor(seq_len(n))
)
binomial_data$x <- rep(seq(-1, 1, length.out = n), each = 2L)
eta <- rep(c(-0.2, 0.25), n) +
  rep(c(0.45, -0.35), n) * binomial_data$x +
  rep(rnorm(n, sd = 0.5), each = 2L)
binomial_data$value <- rbinom(nrow(binomial_data), 1, plogis(eta))

binomial_priors <- data.frame(
  prior = c("student_t(0,1.5,4)", "normal(0,2)", "ridge(0.25)"),
  class = c("fixef", "fixef", "loading"),
  coef = c("traita:x", "traitb:x", "all"),
  dpar = "mu",
  scale = c("link", "link", "loading_coef")
)
binomial_fit <- suppressWarnings(gllvmTMB(
  value ~ 0 + trait + trait:x + latent(0 + trait | unit, d = 1, unique = FALSE),
  data = binomial_data, trait = "trait", unit = "unit",
  family = binomial("logit"),
  control = gllvmTMBcontrol(priors = binomial_priors, se = FALSE,
                            svd_start = FALSE, n_init = 1L)
))
binomial_fit$prior_table_resolved
#> [[1]]
#> [[1]]$prior
#> [1] "student_t(0,1.5,4)"
#> 
#> [[1]]$class
#> [1] "fixef"
#> 
#> [[1]]$kind
#> [1] "student_t"
#> 
#> [[1]]$coef
#> [1] "traita:x"
#> 
#> [[1]]$dpar
#> [1] "mu"
#> 
#> [[1]]$scale
#> [1] "link"
#> 
#> [[1]]$args
#> [1] 0.0 1.5 4.0
#> 
#> [[1]]$trait
#> [1] ""
#> 
#> [[1]]$kernel
#> [1] ""
#> 
#> [[1]]$measure
#> NULL
#> 
#> 
#> [[2]]
#> [[2]]$prior
#> [1] "normal(0,2)"
#> 
#> [[2]]$class
#> [1] "fixef"
#> 
#> [[2]]$kind
#> [1] "normal"
#> 
#> [[2]]$coef
#> [1] "traitb:x"
#> 
#> [[2]]$dpar
#> [1] "mu"
#> 
#> [[2]]$scale
#> [1] "link"
#> 
#> [[2]]$args
#> [1] 0 2
#> 
#> [[2]]$trait
#> [1] ""
#> 
#> [[2]]$kernel
#> [1] ""
#> 
#> [[2]]$measure
#> NULL
#> 
#> 
#> [[3]]
#> [[3]]$prior
#> [1] "ridge(0.25)"
#> 
#> [[3]]$class
#> [1] "loading"
#> 
#> [[3]]$kind
#> [1] "ridge"
#> 
#> [[3]]$coef
#> [1] "all"
#> 
#> [[3]]$dpar
#> [1] "mu"
#> 
#> [[3]]$scale
#> [1] "loading_coef"
#> 
#> [[3]]$args
#> [1] 0.25
#> 
#> [[3]]$trait
#> [1] ""
#> 
#> [[3]]$kernel
#> [1] ""
#> 
#> [[3]]$measure
#> NULL
binomial_fit$objective_components
#> $likelihood_nll
#> [1] 47.07144
#> 
#> $ridge_penalty
#> [1] 0.1864324
#> 
#> $fixed_effect_prior_nll
#> [1] 3.224851
#> 
#> $kernel_psi_sd_prior_nll
#> [1] 0
#> 
#> $optimization_nll
#> [1] 50.48272
#> 
#> $optimizer_reported
#> [1] 50.48272

This combines two named response-coefficient priors with the existing blanket loading ridge. Loading ridge remains a compatibility penalty rather than a coefficient-by-coefficient loading prior.

set.seed(20261123)
n_gaussian <- 32L
gaussian_data <- data.frame(
  unit = factor(rep(seq_len(n_gaussian), each = 2L)),
  trait = factor(rep(c("a", "b"), times = n_gaussian)),
  value = rnorm(2L * n_gaussian,
                mean = rep(c(0.7, 0.1), times = n_gaussian), sd = 0.65)
)
gaussian_priors <- data.frame(
  prior = c("normal(0,2)", "gamma(0.8,2)"),
  class = c("fixef", "residual_sd"),
  dpar = c("mu", "sigma"),
  coef = c("traita", "(Intercept)"),
  scale = c("link", "natural_sd")
)

gaussian_fit <- suppressWarnings(gllvmTMB(
  value ~ 0 + trait,
  data = gaussian_data, trait = "trait", unit = "unit",
  family = gaussian(),
  control = gllvmTMBcontrol(priors = gaussian_priors, se = FALSE, n_init = 1L)
))
gaussian_fit$prior_table_resolved
#> [[1]]
#> [[1]]$prior
#> [1] "normal(0,2)"
#> 
#> [[1]]$class
#> [1] "fixef"
#> 
#> [[1]]$kind
#> [1] "normal"
#> 
#> [[1]]$coef
#> [1] "traita"
#> 
#> [[1]]$dpar
#> [1] "mu"
#> 
#> [[1]]$scale
#> [1] "link"
#> 
#> [[1]]$args
#> [1] 0 2
#> 
#> [[1]]$trait
#> [1] ""
#> 
#> [[1]]$kernel
#> [1] ""
#> 
#> [[1]]$measure
#> NULL
#> 
#> 
#> [[2]]
#> [[2]]$prior
#> [1] "gamma(0.8,2)"
#> 
#> [[2]]$class
#> [1] "residual_sd"
#> 
#> [[2]]$kind
#> [1] "gamma"
#> 
#> [[2]]$coef
#> [1] "(Intercept)"
#> 
#> [[2]]$dpar
#> [1] "sigma"
#> 
#> [[2]]$scale
#> [1] "natural_sd"
#> 
#> [[2]]$args
#> [1] 0.8 2.0
#> 
#> [[2]]$trait
#> [1] ""
#> 
#> [[2]]$kernel
#> [1] ""
#> 
#> [[2]]$measure
#> NULL
gaussian_fit$objective_components
#> $likelihood_nll
#> [1] 66.84194
#> 
#> $ridge_penalty
#> [1] 0
#> 
#> $fixed_effect_prior_nll
#> [1] 1.663079
#> 
#> $kernel_psi_sd_prior_nll
#> [1] 0
#> 
#> $optimization_nll
#> [1] 68.76204
#> 
#> $optimizer_reported
#> [1] 68.76204
#> 
#> $residual_sd_prior_nll
#> [1] 0.2570187

The optimizer minimizes the data negative log-likelihood plus each selected normalized prior penalty once. fit$objective_components$likelihood_nll remains the unpenalized likelihood contribution, while the prior contribution is reported separately. logLik() returns the unpenalized likelihood evaluated at the MAP point and warns that it is not maximized there; AIC and likelihood ratio comparisons should use ordinary unpenalized refits.

Inverse penalized curvature is reported only as local approximate posterior curvature. It is not calibrated sampling uncertainty. Profile intervals, bootstrap intervals, and prediction standard errors are withheld for these prior fits. Use update() to replay the exact prior-table rows when changing the data or other named fit arguments.

Scope boundaries

The table does not yet target grouping-factor random-intercept or random-slope SDs, correlations, latent-score coefficients, slopes of distributional parameters, or non-mean distributional parameters. The residual row does not support non-Gaussian, missing-response, weighted, REML, MSPL, AGHQ, variational, or Julia-engine fits. Unsupported requests fail with an error instead of being ignored. Correlation priors and other random-effect SD priors, such as grouping-factor intercept or slope SDs, are separate future slices; they are not implied by support for kernel Psi.