bbolker / broom.mixed

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

augment.brmsfit() does not return data #90

Closed wpetry closed 4 years ago

wpetry commented 4 years ago

augment.brmsfit() returns predictions without the associated data/newdata columns.

Reproducible example:

library(brms)
library(broom.mixed)
library(tibble)
library(tidyr)

# fit model (from brm() examples)
bprior1 <- prior(student_t(5,0,10), class = b) + prior(cauchy(0,2), class = sd)
fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
            data = epilepsy, family = poisson(), prior = bprior1)

augment(fit1)  # only returns columns .fitted, .se.fit, .resid
augment(fit1, newdata = tidyr::crossing(zAge = 0, zBase = 0, Trt = 0, patient = 1:10))  # only returns columns .fitted, .se.fit

Expected output when not supplying new data:

bind_cols(as_tibble(fit1$data), augment(fit1))
# A tibble: 236 x 8
   count    zAge  zBase Trt   patient .fitted
   <dbl>   <dbl>  <dbl> <fct> <fct>     <dbl>
 1     5  0.425  -0.757 0     1          3.52
 2     3  0.265  -0.757 0     2          3.55
 3     2 -0.533  -0.944 0     3          2.76
 4     4  1.22   -0.870 0     4          3.30
 5     7 -1.01    1.30  0     5         13.7 
 6     5  0.106  -0.158 0     6          5.48
 7     6  0.425  -0.720 0     7          3.15
 8    40  2.18    0.778 0     8         22.7 
 9     5  1.38   -0.308 0     9          5.50
10    14 -0.0541 -0.795 0     10         7.67
# … with 226 more rows, and 2 more variables:
#   .se.fit <dbl>, .resid <dbl>