bbolker / broom.mixed

tidy methods for mixed models in R
227 stars 23 forks source link

Output from tidy for brms mixed effects model doesn't show group level parameter estimates #98

Closed clausherther closed 3 years ago

clausherther commented 3 years ago

Hello! I've previously used broom to tidy the output from my brms hierarchical models. It seems using broom.mixed the output is quite different from the old tidy method. I don't seem to be able to to get actual group level coefficients, just the sd parameters, whereas the old tidy provided full parameter estimates.

Here's an example I pulled from my notes (I'm no longer able to reproduce the old tidy behavior) along with how this looks using broom.mixed::tidy(). Any ideas on how to the broom style output again?

OLD:

                           term    estimate  std.error        lower       upper
 1        sd_channel__Intercept   1.6474093 0.44083166   0.96718634   2.6675482
 2      sd_channel__promoBundle   1.2971393 0.41328134   0.68779600   2.2841562
 3    r_channel[Mail,Intercept]   0.2516302 0.07991207   0.09517577   0.4102641
 4    r_channel[Park,Intercept]   1.7345214 0.15116990   1.44531211   2.0432732
 5   r_channel[Email,Intercept]  -2.7998359 0.19085414  -3.18817887  -2.4402991
 6  r_channel[Mail,promoBundle]  -0.8656247 0.11177860  -1.08634350  -0.6441599
 7  r_channel[Park,promoBundle]  -0.6770537 0.16946185  -1.01534697  -0.3494785
 8 r_channel[Email,promoBundle]   1.9538332 0.27617037   1.41420835   2.4971074
 9                         lp__ -33.4911697 2.28276427 -38.84004397 -30.1020599

NEW:

 effect   component group   term            estimate std.error conf.low conf.high
  <chr>    <chr>     <chr>   <chr>              <dbl>     <dbl>    <dbl>     <dbl>
1 ran_pars cond      channel sd__(Intercept)     1.67     0.433    0.985      2.65
2 ran_pars cond      channel sd__promoBundle     1.31     0.413    0.688      2.28
clausherther commented 3 years ago

Ok, writing up an issue often clarifies things! I managed to figure this out. What I was missing was

tidy(model, effects = c("ran_vals"))
effect   component group   level term        estimate std.error conf.low conf.high
  <chr>    <chr>     <chr>   <chr> <chr>          <dbl>     <dbl>    <dbl>     <dbl>
1 ran_vals cond      channel Mail  (Intercept)    0.251    0.0798   0.0942     0.407
2 ran_vals cond      channel Park  (Intercept)    1.74     0.152    1.45       2.04 
3 ran_vals cond      channel Email (Intercept)   -2.80     0.192   -3.20      -2.44 
4 ran_vals cond      channel Mail  promoBundle   -0.865    0.112   -1.09      -0.644
5 ran_vals cond      channel Park  promoBundle   -0.678    0.170   -1.01      -0.352
6 ran_vals cond      channel Email promoBundle    1.96     0.280    1.41       2.51 

And thanks for listening...:)

bbolker commented 3 years ago

OK to close this then?