Skip to contents

Resolve selectors against the same Gaussian or binomial design builders used by drmTMB(). Models require complete data and unit weights. Gaussian identity models can include one or two independent mean random intercepts with distinct grouping partitions. Normal coefficient priors also support one phylogenetic mean intercept with a matching phylogenetic SD regression and fixed residual-SD predictors. The prior targets mu or sigma coefficients, not the phylogenetic SD-regression coefficients. The R-to-Julia bridge is not yet qualified for this phylogenetic prior route. Other structured combinations and random slopes are not supported with priors. A Gamma SD prior identifies the exact group and intercept and reports shape and rate on the natural SD scale. The native engine also supports a Gamma prior for the residual SD and LKJ priors for rho12 in an intercept-only bivariate Gaussian model or for the correlation in one unlabelled Gaussian mean random-intercept/random-slope block. No automatic centring or scaling is performed. Student-t coefficient, residual-SD, and correlation table rows are native-engine only; the Julia bridge refuses them until its versioned contract supports those targets.

Usage

drm_resolve_priors(formula, family = stats::gaussian(), data, priors)

Arguments

formula

A drm_formula() or bf() specification.

family

Gaussian identity, binomial logit, or bivariate Gaussian family for the documented target classes.

data

A data frame with complete model variables.

priors

A collection created by drm_priors(), or a data frame with prior, class, and coef columns. class = "fixef" accepts normal(mean, sd), student_t(location, scale, df), or ridge(lambda); class = "ranef_sd" accepts gamma(mean, shape) for a named independent Gaussian mean-intercept SD; class = "residual_sd" accepts that Gamma form for the residual SD with dpar = "sigma" and coef = "(Intercept)"; and class = "correlation" accepts lkj(eta). Correlation targets use dpar = "rho12", coef = "(Intercept)" for bivariate residual correlation, or dpar = "mu", group, from_coef, and to_coef for the exact intercept/slope pair in one unlabelled Gaussian q=2 block. Optional dpar defaults to "mu"; optional group names a grouping factor. A blank fixed-effect coefficient selects non-intercept coefficients; a blank random-SD selector selects all supported mean-intercept SDs. Gamma table rows use mean and shape, so rate = shape / mean; the constructor uses shape and rate. Normal, Student-t, Gamma, and LKJ densities are normalized; natural-SD and natural-correlation priors add no transform Jacobian. Overlapping targets, unsupported models, and a coefficient literally named "all" are rejected. Fitted objects retain the input table and update() replays resolved targets.

Value

A data frame identifying the resolved targets. Fixed-effect rows report the distributional parameter, coefficient, matrix column, prior mean, SD, precision and selection reason. An SD-prior row reports the distributional parameter, group, random-effect block, coefficient, SD scale, shape and rate. Residual-SD rows identify the natural SD target; correlation rows identify the exact pair and LKJ eta. Previews use the classes fixef, ranef_sd, residual_sd, and correlation, with scales link, natural_sd, or natural_correlation. Mixed results combine these fields, with unavailable fields recorded as NA.

Examples

d <- data.frame(y = c(1, 2, 1, 3), x = c(0, 1, 2, 3))
p <- drm_priors(drm_prior_normal("mu", "x", sd = 2))
drm_resolve_priors(bf(mu = y ~ x, sigma = ~ 1), gaussian(), d, p)
#>   dpar coefficient matrix_column mean sd precision df       reason   kind
#> 1   mu           x             2    0  2      0.25 NA exact column normal
table <- data.frame(prior = "normal(0,2)", class = "fixef", coef = "x")
drm_resolve_priors(bf(mu = y ~ x, sigma = ~ 1), gaussian(), d, table)
#>   dpar coefficient matrix_column mean sd precision df       reason   kind
#> 1   mu           x             2    0  2      0.25 NA exact column normal
d$group <- factor(c(1, 1, 2, 2))
drm_resolve_priors(bf(mu = y ~ x + (1 | group), sigma = ~ 1), gaussian(), d, p)
#>   dpar coefficient matrix_column mean sd precision df       reason   kind
#> 1   mu           x             2    0  2      0.25 NA exact column normal
sd_table <- data.frame(prior = "gamma(0.6666666666666666,2)",
                       class = "ranef_sd", coef = "group")
drm_resolve_priors(bf(mu = y ~ x + (1 | group), sigma = ~ 1), gaussian(), d, sd_table)
#>      class dpar group       block coefficient      scale  kind shape rate
#> 1 ranef_sd   mu group (1 | group) (Intercept) natural_sd gamma     2    3
if (FALSE) { # \dontrun{
d$group <- factor(rep(seq_len(12), each = 10))
d$x <- rep(seq(-1, 1, length.out = 10), 12)
d$y <- 0.4 + 0.6 * d$x + rnorm(nrow(d))
f <- bf(mu = y ~ x + (1 + x | group), sigma = ~ 1)
prior_table <- data.frame(
  prior = c("normal(0,2)", "student_t(0,1.5,4)", "gamma(0.8,2)", "lkj(2)"),
  class = c("fixef", "fixef", "residual_sd", "correlation"),
  dpar = c("mu", "mu", "sigma", "mu"),
  coef = c("(Intercept)", "x", "(Intercept)", ""),
  group = c("", "", "", "group"),
  from_coef = c("", "", "", "(Intercept)"),
  to_coef = c("", "", "", "x"),
  scale = c("link", "link", "natural_sd", "natural_correlation")
)
drm_resolve_priors(f, gaussian(), d, prior_table)
fit <- drmTMB(f, data = d, priors = prior_table)
c(logLik = as.numeric(logLik(fit)), penalized_objective = fit$penalized_objective)
} # }
if (FALSE) { # \dontrun{
tree <- ape::read.tree(text = "((a:0.5,b:0.5):0.5,(c:0.5,d:0.5):0.5);")
dat <- data.frame(y = c(.2,.7,.35,1.1,.8,1.25,1.4,1.1,1.9,1.5,2.15,.5),
                  x = c(-1.2,-.8,-.7,-.2,.1,.15,.4,.6,.8,1,1.2,-.3),
                  sp = c("a","a","b","b","b","c","c","d","d","d","d","a"),
                  z = c(-1,-1,-.35,-.35,-.35,.4,.4,1,1,1,1,-1))
f <- bf(y ~ x + phylo(1 | sp, tree = tree), sigma ~ x,
        sd(sp, level = "phylogenetic") ~ z)
pri <- data.frame(prior = c("normal(.1,.7)", "normal(-.2,.5)"),
                  class = "fixef", coef = "x", dpar = c("mu", "sigma"))
drm_resolve_priors(f, gaussian(), dat, pri)
fit <- drmTMB(f, data = dat, priors = pri)
} # }