Below is the linear model I am estimating using brm:
f_priors <- c(prior(student_t(3, -4.6, 2), class = "Intercept"),
prior(student_t(3, 0, 2), class = "sd", group = "EG"),
prior(normal(0, .02), class = "b", coef = "period") )
f_model <- brm(claim_count ~ (1 | EG) + period + offset(log(earned_exposure)),
family = poisson(link = "log"),
sample_prior = "yes",
prior = f_priors,
data = model_data,
iter = 1500,
chains = 4,
warmup = 500,
cores = 4,
seed = 424242,
verbose = FALSE)
This returns the below (partial) summary
Group-Level Effects:
~EG (Number of levels: 28)
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sd(Intercept) 1.35 0.23 0.98 1.88 930 1.00Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
Intercept -9.19 0.28 -9.74 -8.65 515 1.01
period -0.02 0.01 -0.04 -0.00 5878 1.00
Now for business scientific reasons, I would like to constrain the period parameter estimate to a lower bound of 0 and otherwise estimate the same model. I try this using a non-linear setup like this:
f_priors_nl <- c(prior(student_t(3, -4.6, 2), nlpar = "globInt"),
prior(student_t(3, 0, 2), nlpar = "grp"),
prior(normal(0, .02), nlpar = "trend", lb = 0) )
f_model_nl <- brm(bf(claim_count ~ globInt + grp + trend + log(earned_exposure),
globInt ~ 1,
grp ~ 0 + 1|EG,
trend ~ 0 + period,
nl = TRUE),
family = poisson(link = "log"),
sample_prior = "yes",
prior = f_priors_nl,
data = model_data,
iter = 1500,
chains = 4,
warmup = 500,
cores = 4,
seed = 424242,
verbose = FALSE)
Which estimates this model:
Group-Level Effects:
~EG (Number of levels: 28)
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sd(grp_Intercept) 1.35 0.24 0.97 1.91 641 1.00Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
globInt_Intercept -7.04 2.18 -11.34 -2.91 2091 1.00
grp_Intercept -2.33 2.19 -6.51 1.96 2066 1.00
trend_period 0.00 0.00 0.00 0.01 5177 1.00
Seems I am doing this wrong. I want one population intercept as in the first model. How would I correctly specify this?
Thanks in advance