I noticed that when I set
save_pars = save_pars(all=TRUE)
there is a parameter called b_Intercept and one called Intercept in my model. Intercept does not show up in the summary, but in the $fit. When not all parameters are saved, there is only b_Intercept.
What does Intercept mean? It has a different value than b_Intercept.
Should I set a prior for this? I am working with a custom family where the default priors usually don’t make much sense.
A minimal example on what the Intercept and b_Intercept can look like in a very simple model:
data = data.frame(x = c(1,2,2,1,4,5,6,5), y = c(1,1,1,1,2,2,2,2))
test_fit1 = brm(data = data,
formula = x ~ y,
seed = 1,
save_pars = save_pars(all=TRUE))
summary(test_fit1)
test_fit1$fit
mcmc_plot(test_fit1, pars = c('Intercept', 'y', 'sigma'))
the output of test_fit1$fit
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
b_Intercept -2.00 0.02 1.03 -4.16 -2.59 -2.00 -1.41 0.08 2536 1
b_y 3.50 0.01 0.66 2.16 3.12 3.49 3.86 4.84 2574 1
sigma 0.90 0.01 0.35 0.48 0.66 0.81 1.04 1.79 1406 1
Intercept 3.24 0.01 0.34 2.53 3.05 3.25 3.44 3.88 2154 1
lp__ -13.30 0.05 1.52 -17.26 -14.02 -12.90 -12.16 -11.56 1083 1
P.S. I am pretty new to this so I apologize if this should be obvious. Any hints are appreciated
Thank you for the suggestion, unfortunately reading it did not help me.
If I am not mistaken, the model I specify above is
x ~ N(b_Intercept + b_y * y, sigma)
So what do I need the additional parameter ‘Intercept’ for?
To start with data should be
data = data.frame(x = c(1,2,2,1,4,5,6,5), y = c(1,1,1,1,2,2,2,2))
Your are right, of course. I edited my original post.
Thanks for cleaning up the code. That will help other folks who have the same question.
Let me tag in some brms folks. I looked this up once but have since forgotten. @paul.buerkner
Hi Britta,
If you look at the underlying Stan code for the model using:
make_stancode(data = data,
formula = x ~ y,
seed = 1,
save_pars = save_pars(all=TRUE))
You’ll see the respective definitions:
parameters {
vector[Kc] b; // population-level effects
real Intercept; // temporary intercept for centered predictors
real<lower=0> sigma; // residual SD
}
...
generated quantities {
// actual population-level intercept
real b_Intercept = Intercept - dot_product(means_X, b);
}
This is referring to the fact that brms mean-centers the predictors prior to analysis, so the Intercept parameter is on the mean-centered scale. The b_Intercept parameter is this mean-centered intercept back-transformed to the original scale of the predictors
To OPs question about setting a prior for Intercept, I’ve read a couple of posts that suggest that the prior we set with class “Intercept” should be for the mean-centered scaled parameter, i.e. “Intercept” not “b_Intercept”. Is that also your understanding?
To understand the distinction between what brms calls “Intercept” and “b_Intercept,” you want to spend some time reading through the Parameterization of the population-level intercept and set_prior sections of the brms reference manual. This generally isn’t a big deal if you use default priors (which is fine for students and other beginners), but it can make a big difference if you attempt to set the priors yourself (which I personally think is best for professional work). I’ve also written about it in this blog post.