mjskay / tidybayes

Bayesian analysis + tidy data + geoms (R package)
http://mjskay.github.io/tidybayes
GNU General Public License v3.0
710 stars 59 forks source link

add_epred_draws on model with measurement error term #309

Closed amynang closed 1 year ago

amynang commented 1 year ago

Hi, Not sure if this is a limitation or a special case where proceeding is un-intuitive: In models with measurement error term, add_epred_draws() throws an error:

library(brms)
library(modelr)
library(tidybayes)

d = data.frame(con = rep(1:5, each = 6),
               cat = rep(letters[1:2], each =3),
               res = abs(rnorm(30,100,25)),
               err = abs(rnorm(30)))

m = brm(bf(res | mi(err) ~ 1 + con + cat + con:cat),
        chains = 1,
        iter = 1000,
        data = d)

summary(m)

d %>%
  group_by(cat) %>% 
  data_grid(con = seq_range(con, n = 101)) %>%
  add_epred_draws(m) %>%
  ggplot(aes(x = con, y = res, color = cat)) +
  stat_lineribbon(aes(y = .epred))

Error: The following variables can neither be found in 'data' nor in 'data2': 'err'

Is there a way around this?

mjskay commented 1 year ago

you might need to supply an err column in the input data?

amynang commented 1 year ago

Ok, I misunderstood the role group_by plays... Thanks! tidybayes is awesome 😃

mjskay commented 1 year ago

great, glad it worked!

also thanks :)