You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on one of the vignettes, I'm trying to plot posterior draws using stat_slab. I was getting the following error, and I couldn't figure it out:
Warning message:
Computation failed in stat_slab():
need at least 2 points to select a bandwidth automatically
I think the problem is that spread_draws automatically converts number characters to integers, when it can. See the two datasets below, that differ only in whether subject is coded as "1"/"2" or "X"/"Y":
# This works
m_letters %>%
spread_draws(b_treatment, r_subject[subject,]) %>%
mutate(subject_estimate = b_treatment + r_subject) %>% #print()
ggplot(aes(y = subject, x = subject_estimate)) +
stat_slab()
But not the second. It does however, when I add the line commented below that transforms subject back to char.
# does not work
m_numbers %>%
spread_draws(b_treatment, r_subject[subject,]) %>%
mutate(subject_estimate = b_treatment + r_subject) %>%
#mutate(subject = as.character(subject)) %>%
ggplot(aes(y = subject, x = subject_estimate)) +
stat_slab()
I had this problem in my code even though in my (real) data I has specified subjectNumber to be both a character and a factor. If this behaviour is intended, I'm missing something (which might very well be, some parts of R remain a mystery to me). If it is intended, it would be a good idea to include a warning and/or improve the error message.
The text was updated successfully, but these errors were encountered:
Sorry for the delay! Ah yes, the issue is with orientation detection.
stat_slab() attempts to figure out whether you want to plot the densities horizontally or vertically based on the data types of the variables mapped onto the x and y aesthetics. In your second example it incorrectly thinks you want vertical slabs because y is numeric and not a factor. Then it attempts to calculate densities with too few observations and breaks.
This is why converting back to a factor fixes the problem, as then y is discrete and it correctly determines that the orientation should be horizontal.
You can force the orientation to be horizontal by passing orientation = "horizontal" manually:
Based on one of the vignettes, I'm trying to plot posterior draws using stat_slab. I was getting the following error, and I couldn't figure it out:
I think the problem is that spread_draws automatically converts number characters to integers, when it can. See the two datasets below, that differ only in whether
subject
is coded as "1"/"2" or "X"/"Y":I run the two models, in exactly the same way:
I can plot the first model just fine
But not the second. It does however, when I add the line commented below that transforms
subject
back to char.I had this problem in my code even though in my (real) data I has specified
subjectNumber
to be both a character and a factor. If this behaviour is intended, I'm missing something (which might very well be, some parts of R remain a mystery to me). If it is intended, it would be a good idea to include a warning and/or improve the error message.The text was updated successfully, but these errors were encountered: