Intercepts while nl=TRUE and random effects

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.00

Population-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.00

Population-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

So you are wondering why there is a grp_Intercept? I think this is because you didn’t set brackets around the 1|EG term. As a rule of thumb, always set brackets around these terms, that is use (1 | EG). I tope this should solve it.

Thanks - tried this but does not solve. with grp ~ (1|EG) inside of bf()…

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.00

Population-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_pd 0.00 0.00 0.00 0.01 5177 1.00

I also at first tried grp ~ 0 + (1|EG) but this results in an error:

Error: The following priors do not corresp> ond to any model parameter:

b_grp ~ student_t(3, 0, 2)
Function ‘get_prior’ might be helpful to you.

Ok disregard - when I add class = “sd” to the prior it works now. Here’s working code for future reference

f_priors_nl <- c(prior(student_t(3, -4.6, 2), nlpar = "globInt"),
                 prior(student_t(3, 0, 2), , class = "sd", 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 + pd,
                     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)