Generates appropriate priors for a linear predictor derived from an R formula. As such it makes the most sense to use this macro together with the LINPRED macro, which takes similar arguments.
NIMBLE code for the priors specified by the formula.
An R formula The formula must be right-hand side only (e.g., ~x).
This must always be the first argument supplied to LINPRED_PRIORS.
All model coefficient names will begin with this prefix.
default is "beta_" (so 'x' becomes 'beta_x', etc.)
All dispersion parameters will begin with this prefix. Default is no prefix.
List of prior specifications, generated using setPriors.
setPriors()
Logical indicating if parameters should be named so they match the
names one would get from R's model.matrix. Default is FALSE.
Logical indicating whether to use noncentered parameterization
for random effects. Default is FALSE. Under the noncentered parameterization,
random effects have a standard normal prior (beta_x_raw ~ dnorm(0, sd = 1))
and are then scaled by the hyperparameters (mean and SD), i.e.,
beta_x = mu_beta + sd_beta * beta_x_raw. This parameterization can improve
mixing in some cases.
Grouping variable (covariate) to 'center' the random effects on.
By default (when NULL), random effects come from normal distributions with mean 0
as with lme4. For example, for random intercepts by grouping variable x,
the linear predictor would be beta_Intercept + beta_x[x[i]] and the
prior for the random effects would be beta_x ~ dnorm(0, sd_x). When
centerVar = x, the linear predictor would be beta_x[x[i]]
and the random effect prior would be beta_x ~ dnorm(beta_Intercept, sd = sd_x).
That is, the mean of the random effects is now beta_Intercept.
These two formulations should yield the same results. Note that this option
is unrelated to the noncentered argument despite the similar names.
Used internally by nimbleMacros; a list of model information such as constants and dimensions
Used internally by nimbleMacros; the environment where the model was created
Ken Kellner
constants <- list(x = rnorm(3), x2 = factor(letters[1:3]))
code <- nimbleCode({
LINPRED_PRIORS(~x + x2)
})
mod <- nimbleModel(code, constants = constants)
mod$getCode()
Run the code above in your browser using DataLab