Extracting individual parameter estimates from a hierarchical model

479 views
Skip to first unread message

Andrew Ellis

unread,
Jan 9, 2017, 6:30:50 PM1/9/17
to brms-users
Is there a simple way of obtaining the estimates for each member of the grouping variable for the random effects, e.g. for each id in this model:

fit <- brm(reaction ~ days + (days | id), data = sleepstudy,  family = gaussian)

The coef() function just returns point estimates; is this already implemented in the brms package, or do I have to extract the samples from fit$fit and then manually add the fixed effect parameters to each individual?

Paul Buerkner

unread,
Jan 9, 2017, 7:11:28 PM1/9/17
to brms-users
You mean to also obtain CIs for the coefficients? Unfortunately, coef can only return point estimates as you say. I suggest the following:

# use regular expressions to extract the desired parameters
ran
<- as.matrix(fit, pars = "^r_id.*,days")
fix
<- as.vector(as.matrix(fit, pars = "^b_days"))

comb
<- ran + fix
colMeans
(comb)  # matches results of coef
<do whatever you want with the samples>

Andrew Ellis

unread,
Jan 10, 2017, 5:51:51 AM1/10/17
to brms-users
hi Paul,

thanks. I will have a look at this as soon as I have time. The random and fixed don't seem to have the same dimensionality, but I need to check this.

The reason for this is to obtain credible intervals for estimates for each individual participant in an experiment.

Tom Wallis

unread,
Mar 23, 2017, 8:46:10 AM3/23/17
to brms-users
I just encountered the same need case as this. 

Would it be possible to have coeff allow the extraction of quantiles (similar to fixef)?

Paul Buerkner

unread,
Mar 23, 2017, 12:22:57 PM3/23/17
to brms-users
I have just opened an issue for it on github (https://github.com/paul-buerkner/brms/issues/200).
Reply all
Reply to author
Forward
0 new messages