Priors and Boundaries
For the workflow guidance behind these controls, start with Stage 2: Model and Priors. This page is the technical contract for DSAMbayes prior and boundary behaviour.
Use this page when you need exact DSAMbayes semantics: supported prior families, override syntax, default generation rules, and scaling behaviour. Do not use it as the main argument for why a prior is reasonable. That reasoning belongs in the workflow pages and in your modelling rationale.
Purpose
This page defines how DSAMbayes specifies, defaults, overrides, and scales coefficient priors and parameter boundaries for all model classes. It covers the prior schema, supported families, default-generation logic, YAML override contract, and the interaction between priors, boundaries, and the scale=TRUE pathway.
How to read this page
- Use Minimal-Prior Policy if you want the short recommended operating rule.
- Use this page when you need to know exactly how DSAMbayes will interpret a prior or boundary specification.
- Return to Stage 2: Model and Priors if the question is whether a custom prior should be added at all.
Prior schema
Each model object carries a .prior tibble with one row per parameter. The columns are:
| Column | Type | Meaning |
|---|---|---|
parameter |
character | Parameter name (matches design-matrix column or special name) |
description |
character | Human-readable label |
distribution |
call | R distribution call, e.g. normal(0, 5) |
is_default |
logical | Whether the row was generated by default_prior() |
Supported prior families
| Family | Stan encoding | Use case |
|---|---|---|
normal(mean, sd) |
Default (prior_family_noise_sd = 0) |
Coefficient priors (location–scale) |
lognormal_ms(mean, sd) |
Encoded with log-transformed parameters | Positive noise_sd and hierarchical sd_<idx>[<term>] priors |
All coefficient priors use normal(). The lognormal_ms family is parameterised by the mean and standard deviation on the original (non-log) scale; DSAMbayes converts these internally to log-space parameters.
Default prior generation
BLM and hierarchical (population terms)
default_prior.blm() calls standard_prior_terms(). On the reporting scale,
the intercept prior is normal(ybar, sy), each slope prior is
normal(0, sy / sx), and the residual-SD prior is normal(0, sy), where
sy and sx are the response and term standard deviations. These defaults
therefore map to unit-scale priors after internal standardisation and respond
coherently when measurement units change.
Hierarchical (group-level standard deviations)
default_prior.hierarchical() additionally generates sd_<idx>[<term>] rows
for each group factor. Each constrained group SD receives a zero-centred normal
prior whose scale matches the corresponding coefficient scale: sy for a
group intercept and sy / sx for a random slope. Because the SD parameter is
constrained positive in Stan, this acts as a half-normal prior. It remains
positive when observed group outcome means happen to be equal, and random-slope
defaults change coherently when predictor measurement units change.
Specify hierarchical standard-deviation priors in reporting-scale units. With
scale = TRUE, DSAMbayes transforms them to the Stan scale: intercept
heterogeneity is divided by the response standard deviation, while slope
heterogeneity is multiplied by the predictor-to-response standard-deviation
ratio. The group intercept is defined at the internally centred predictor
reference point. It is not a group intercept at raw predictor values of zero.
With the defaults above, these transformations produce unit-scale group-SD
priors in Stan space. Explicit user overrides retain their supplied
reporting-scale meaning and are transformed by the same rules.
Default population and group-SD scales use the same population-model complete-case frame. This keeps the reporting-to-Stan transformation exact when a population term contains missing values. Random-slope terms must be numeric. Group-only random-slope terms are evaluated on the retained population rows. DSAMbayes aborts rather than deriving a group-SD default when a group term would drop additional rows or when a factor random slope is unsupported.
BLM from lm (Bayesian updating)
default_prior.bayes_lm_updater() initialises coefficient priors from the OLS point estimates (mean) and standard errors (sd), enabling informative Bayesian updating.
Pooled
default_prior.pooled() uses the BLM defaults for non-pooled terms (intercept, base regressors, noise_sd) and normal(0, 5) for each dimension-level pooled coefficient. Default pooled boundaries remain unconstrained; add explicit boundaries if a pooled dimension should be sign-restricted.
Boundary schema
Each model object carries a .boundaries tibble with one row per parameter:
| Column | Type | Meaning |
|---|---|---|
parameter |
character | Parameter name |
description |
character | Human-readable label |
boundary |
list-column | List with $lower and $upper (numeric scalars) |
is_default |
logical | Whether the row was generated by default_boundary() |
Default boundaries are lower = -Inf, upper = Inf for all terms. No sign constraints are imposed by default.
YAML override contract
Prior overrides
Each override replaces the distribution call for the named parameter with normal(mean, sd). Overrides are sparse: only the listed parameters are changed; all other parameters keep their defaults.
In M1, use_defaults must remain true. The v2 runner is default-first: it always starts from the generated prior table, then applies sparse grouped aliases and explicit overrides.
The friendly YAML surface also accepts an explicit alias style:
or:
HalfNormal is implemented by compiling to normal(0, sigma) plus an implied lower bound of 0 on targeted parameters that are otherwise unconstrained. The priors.likelihood.sigma alias compiles to the DSAMbayes noise_sd prior family.
Boundary overrides
Each override replaces the boundary entry for the named parameter. YAML infinity tokens (.Inf, -.Inf) are coerced during config resolution.
Scale semantics (scale = TRUE)
When model.scale: true (the default), the response and predictors are standardised before Stan fitting. This affects both priors and boundaries.
Coefficient prior scaling
Prior standard deviations are scaled by the ratio sx / sy for slope terms and by 1 / sy for the intercept. The noise_sd prior standard deviation is multiplied by sy (the response standard deviation) to remain interpretable in the scaled space.
Boundary scaling
- Zero boundaries (
0) are invariant under scaling. - Infinite boundaries (
±Inf) are invariant under scaling. - Finite non-zero boundaries for slope terms are scaled using
scale_boundary_for_parameter(), which applies the samesx / syratio used for slope priors. - If a finite non-zero boundary is specified for a parameter without a matching scale factor in the design matrix, DSAMbayes aborts with a validation error.
Practical implication
Users specify priors and boundaries on the original (unscaled) data scale. DSAMbayes converts them internally before passing data to Stan. Post-fit, coefficient draws are back-transformed to the original scale by get_posterior().
Interaction with model classes
| Behaviour | BLM | Hierarchical | Pooled |
|---|---|---|---|
| Default priors | Data-dependent: normal(ybar, sy) intercept, normal(0, sy / sx) slopes, normal(0, sy) noise_sd (see Default prior generation above) |
Population: same as BLM; group SD: data-derived | Non-pooled: BLM defaults; pooled dimension coefficients only: normal(0, 5) per dimension |
| Boundary defaults | (-Inf, Inf) per term |
Same as BLM for population terms | Per-dimension boundaries for pooled terms |
| Prior scaling | sx / sy ratio |
Same, computed on pooled model frame | Same, computed on full model frame |
| Boundary scaling | Same ratio | Same | Same |
Programmatic API
Inspect priors and boundaries
Override priors
Override boundaries
Minimal-prior policy
The recommended operating profile for MMM is documented in Minimal-Prior Policy. The policy keeps priors weak by default and uses hard constraints only when there is structural business knowledge.
Cross-references
- Model Classes, constructor and fit support per class
- Minimal-Prior Policy, governance guidance for prior specification
- Response Scale Semantics, link vs KPI scale behaviour
- Config Schema, YAML prior and boundary keys