-
-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to use function ppc_stat_grouped() on data including NAs #236
Comments
I think that's because the df <- data.frame(a = c(1, 3, NA, 4))
na.omit(df$a)
Maybe either of these would work: df_all_subjects$answer[!is.na(df_all_subjects$answer)]
with(df_all_subjects, answer[!is.na(answer)]) |
Thank you, jgabry, for your advice. Indeed, it seems to work better with the following: However, now I get a different error: This makes sense, since the simulated values will not contain NA values. Does anybody have an idea how to work around this issue? |
Is that because you have missing data but are still making predictions for the missing data points? Since you're using
you can instead use
In the future, I think we could relax the requirement of no NAs for the ppc_stat plots. We really don't need to error if there are NAs in y, we just need to compute the statistic dropping NAs. |
As you suggested, I substituted the NAs with the subject's median and ran the above function again: However, I get an error:
The length of y and group are the same, but the length of posterior_predict is different. should I repeat the whole modelling process with the NA-substitutes before running the ppc_stat_grouped-function? |
Hmm, I'm not sure I understand. Why is the number of columns of yrep not equal to the number of elements of y? If you replace (instead of remove) the NAs in y then shouldn't it have the same number of observations as yrep? |
I just made a branch of bayesplot that should work if there are NAs in y for ppc_stat() and ppc_stat_grouped(). You can install it with: devtools::install_github("stan-dev/bayesplot", ref = "ppc_stat_allow_NA") Does that let you use the original code you wanted to use without errors? |
Thank you for taking the time! I installed it and tried to run it. Now I do not get the NA-related error anymore. But I still get the error of different lengths:
I do not understand this, either. When I ask for the lengths, I get the following:
So, the length of the posterior predictions is much longer than the other ones, but I thought this was normal, because I expect there will be many different draws. Maybe I did something wrong when creating the model, or maybe I am using the function wrong? |
Sorry for the delay. The length of the posterior predictions will be longer because there are many draws per observation. It's the number of columns in the predictions that needs to match the length of y. But apparently that's not the case here either. What do you get for Also, is it possible to share the data and code you're using for this so I can reproduce it on my end? That would probably help me figure this out much quicker. If the data is private then fake data that also demonstrates this problem is totally fine. |
Sorry for my late reply. I ran into problems again. I downsized the dataset and uploaded it to this link, together with the brms model I created: When I run the following, I get 1066 columns:
Then, I tried running the code (below), but I get the following error:
|
Hello everyone,
I would like to use the function ppc_stat_grouped() on data that includes NAs.
model_subj_shift_brm %>% posterior_predict(draws = 5) %>% ppc_stat_grouped(y = df_all_subjects$answer, group = df_all_subjects$diagnosis, stat = "median")
I get the following error:
Error: NAs not allowed in 'y'.
I tried deleting NAs in that column:
model_subj_shift_brm %>% posterior_predict(draws = 5) %>% ppc_stat_grouped(y = na.omit(df_all_subjects$answer), group = df_all_subjects$diagnosis, stat = "median")
I get the following error message:
Error: 'y' must be a vector or 1D array.
Thank you for any advice on how to run this function.
Juliane
The text was updated successfully, but these errors were encountered: