(EXPERIMENTAL/subject to change)
glmmTMB can accept prior specifications, for doing maximum a posteriori (MAP) estimation (or Hamiltonian MC with the tmbstan package), or (outside of a Bayesian framework) for the purposes of regularizing parameter estimates
The priors argument to glmmTMB must (if not NULL) be a data frame with columns
priorcharacter; the prior specification, e.g. "normal(0,2)"
classthe name of the underlying parameter vector on which to impose the prior ("fixef", "fixef_zi", "fixef_disp", "ranef", "ranef_zi", "psi")
coef(optional) a string (if present) specifying the particular elements of the parameter vector to apply the prior to. coef should specify an integer parameter index, a column name from the fixed effect model matrix or a grouping variable for a random effect (the behaviour is currently undefined if there is more one than random effect term with the same grouping variable in a model ...); one can also append "_cor" or "_sd" to a random-effects class specification to denote the correlation parameters, or all of the standard deviation parameters, corresponding to a particular random effect term. If the class element is missing, or a particular element is blank, then all of the elements of the specified parameter vector use independent priors with the given specification. The exception is for the fixed-effect parameter vectors ("fixef", "fixef_zi", "fixef_disp"), where the intercept (if present) is not included; the prior on the intercept must be set explicitly.
`The available prior distributions are:
"normal" (mean/sd parameterization)
"t" (mean/sd/df)
"cauchy" (location/scale)
"gamma" (mean/shape); applied on the SD (not the log-SD) scale
"lkj" (correlation) [WARNING, maybe buggy at present!]
The first three are typically used for fixed effect parameters; the fourth for standard deviation parameters; and the last for correlation structures. See the "priors" vignette for examples and further information.
data("sleepstudy", package = "lme4")
prior1 <- data.frame(prior = c("normal(250,3)","t(0,3,3)","gamma(10,1)"),
class = c("fixef", "fixef", "ranef_sd"),
coef = c("(Intercept)", "Days", "Subject"))
g1 <- glmmTMB(Reaction ~ 1 + Days + (1 + Days |Subject), sleepstudy)
update(g1, priors = prior1)
#> Formula: Reaction ~ 1 + Days + (1 + Days | Subject)
#> Data: sleepstudy
#> AIC BIC logLik -2*log(L) df.resid
#> 1793.3224 1812.4801 -890.6612 1781.3224 174
#> Random-effects (co)variances:
#>
#> Conditional model:
#> Groups Name Std.Dev. Corr
#> Subject (Intercept) 21.094
#> Days 5.604 0.14
#> Residual 25.701
#>
#> Number of obs: 180 / Conditional model: Subject, 18
#>
#> Dispersion estimate for gaussian family (sigma^2): 661
#>
#> Fixed Effects:
#>
#> Conditional model:
#> (Intercept) Days
#> 250.340 9.812
#>
#> Priors: fixef((Intercept)) ~ normal(250, 3); fixef(Days) ~ t(0, 3, 3); ranef_sd(Subject) ~ gamma(10, 1)
#>
prior2 <- data.frame(prior = c("t(0,3,3)","gamma(10,1)"),
class = c("fixef", "ranef_sd"),
coef = c("", "Subject"))
update(g1, priors = prior2)
#> Formula: Reaction ~ 1 + Days + (1 + Days | Subject)
#> Data: sleepstudy
#> AIC BIC logLik -2*log(L) df.resid
#> 1789.2204 1808.3781 -888.6102 1777.2204 174
#> Random-effects (co)variances:
#>
#> Conditional model:
#> Groups Name Std.Dev. Corr
#> Subject (Intercept) 21.074
#> Days 5.608 0.13
#> Residual 25.701
#>
#> Number of obs: 180 / Conditional model: Subject, 18
#>
#> Dispersion estimate for gaussian family (sigma^2): 661
#>
#> Fixed Effects:
#>
#> Conditional model:
#> (Intercept) Days
#> 251.768 9.768
#>
#> Priors: fixef ~ t(0, 3, 3); ranef_sd(Subject) ~ gamma(10, 1)
#>
## no prior is set for the intercept in this case - see Details above
prior3 <- data.frame(prior = "t(0, 3, 3)",
class = "fixef")
update(g1, priors = prior3)
#> Formula: Reaction ~ 1 + Days + (1 + Days | Subject)
#> Data: sleepstudy
#> AIC BIC logLik -2*log(L) df.resid
#> 1774.3996 1793.5574 -881.1998 1762.3996 174
#> Random-effects (co)variances:
#>
#> Conditional model:
#> Groups Name Std.Dev. Corr
#> Subject (Intercept) 23.785
#> Days 5.763 0.08
#> Residual 25.592
#>
#> Number of obs: 180 / Conditional model: Subject, 18
#>
#> Dispersion estimate for gaussian family (sigma^2): 655
#>
#> Fixed Effects:
#>
#> Conditional model:
#> (Intercept) Days
#> 251.849 9.736
#>
#> Priors: fixef ~ t(0, 3, 3)
#>