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

no applicable method for 'ungroup' applied to an object of class "c('double', 'numeric')" #288

Closed tjmahr closed 2 years ago

tjmahr commented 2 years ago

This is just some light feedback about something I tripped over. Here is the problem and how to fix it.

I was running some old code.

> draws_item <- new_data_draws_item %>% 
+   add_fitted_draws(
+     m_freq_prob_comp, 
+     n = 10000, 
+     allow_new_levels = TRUE
+   )
Warning message:
`fitted_draws` and `add_fitted_draws` are deprecated as their names were confusing.
Use [add_]epred_draws() to get the expectation of the posterior predictive.
Use [add_]linpred_draws() to get the distribution of the linear predictor.
For example, you used [add_]fitted_draws(..., scale = "response"), which
means you most likely want [add_]epred_draws(...). 

This is very helpful. I change fitted to epred:

> draws_item <- new_data_draws_item %>% 
+   add_epred_draws(
+     m_freq_prob_comp, 
+     n = 10000, 
+     allow_new_levels = TRUE
+   ) 
Error in UseMethod("ungroup") : 
  no applicable method for 'ungroup' applied to an object of class "c('double', 'numeric')"

Huh? After messing around, I figured out the problem was using n instead of ndraws.

draws_item <- new_data_draws_item %>% 
  add_epred_draws(
    m_freq_prob_comp, 
    ndraws = 10000, 
    allow_new_levels = TRUE
  ) 
# works

I don't think you should change the add_() functions to have a n argument that you have to warn about. But maybe the first warning should also tell users about n being deprecated.

Anyway, if anyone else has this problem, here's what to do!

mjskay commented 2 years ago

Thanks, this is very helpful! Adding a note about argument name changes to the warning...