-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Allow to select y_rep for PPcheck from the global environment #109
Comments
I think I can add this without much trouble. And it will also be useful for anyone doing posterior predictive simulations outside of their Stan program. |
@paul-buerkner Does the open PR #115 work in general for brms? I tried it on one of your example models and it worked ok, but you'd know better if it will work across the board. |
It works, thanks so much! I noticed 2 little problems though, that are likely not specific to using y_rep from the globalenv.
With regard to user-friendliness I have another idea, but I don't know if this is complicated to implement from your side. I wonder if it would be possible to tell shinystan the environment in which it should look for the objects for y and y_rep. That way, I could compute y_rep inside the function that calls shinystan and users would no longer be required to compute y_rep separately. |
I noticed that too. I think it's fixed by the most recent commit in the PR (at least it looks better to me but if it still has that problem for you let me know).
Weird. I'll take a look.
Something along these lines should be possible. Are you envisioning the user telling it which environment to look in or for that to be done automatically in some way? |
When I try with this example fit <- brm(time | cens(censored) ~ age + sex + (1+age||patient),
data = kidney, family = "exponential", inits = "0", warmup = 50, iter = 100)
y <- kidney$time
pp <- predict(fit)
brms::launch_shiny(fit) And I go to "Distribution of observed data vs replications" and then click on "Densities" and "Overlay" it seems to work ok (except for some warnings about row names that I need to get rid of): |
My idea was that launch_shiny.brmsfit <- function(x, rstudio = getOption("shinystan.rstudio"), ...) {
y <- model.response(model.frame(x))
y_rep <- predict(x, summary = FALSE)
shinystan::launch_shinystan(x$fit, rstudio = rstudio, env = environment(), ...)
} I am not sure though, if this is the best way to find y and y_rep computed within the function calling shinystan. |
The boxes are great now! Using your example, I still don't see the overlay even if I install the PR-version of shinystan again: Maybe I am missing something? Here is my session info: R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_0.13.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.3 nloptr_1.0.4 plyr_1.8.3 shinyjs_0.4.0 xts_0.9-7 base64enc_0.1-3 tools_3.2.3 digest_0.6.9
[9] lme4_1.1-11 statmod_1.4.22 jsonlite_0.9.19 memoise_0.2.1 nlme_3.1-124 gtable_0.1.2 lattice_0.20-33 Matrix_1.2-3
[17] yaml_2.1.13 curl_0.9.4 parallel_3.2.3 shinystan_2.1.1 gridExtra_2.0.0 coda_0.18-1 httr_1.0.0 stringr_1.0.0
[25] knitr_1.12.3 gtools_3.5.0 dygraphs_0.7 htmlwidgets_0.5 brms_0.8.0.9000 devtools_1.9.1 DT_0.1 stats4_3.2.3
[33] grid_3.2.3 inline_0.3.14 R6_2.1.2 rstan_2.9.0-3 minqa_1.2.4 reshape2_1.4.1 ggplot2_2.0.0 magrittr_1.5
[41] shinythemes_1.0.1 threejs_0.2.1 scales_0.3.0 htmltools_0.3 MASS_7.3-45 splines_3.2.3 abind_1.4-3 mime_0.4
[49] colorspace_1.2-6 xtable_1.8-2 httpuv_1.3.3 labeling_0.3 stringi_1.0-1 munsell_0.4.3 markdown_0.7.7 zoo_1.7-12 |
closed by accident. reopening |
Ok, I think this is a ggplot2 issue. I had the development version of ggplot2 installed and when I revert to the CRAN version I also don't get the y_rep densities. Can you try installing ggplot2 from GitHub and see if it works? |
On Thursday, February 18, 2016, Paul-Christian Bürkner <
|
Thanks Jonah! With the development version of ggplot2, the overlay plots are working fine. :-) |
Ok so now we just need Hadley to release the ggplot2 update. I'm not sure why it doesn't work with the current ggplot2, and I bet we could get around that but I don't know if I have the time to go down that rabbit hole. Supposedly the next ggplot2 update will be released soon. |
That's totally fine for me. I am glad that you implemented this so fast. :-) Regarding the environment thing: Shall I open another issue for it? |
Yeah let's put that in a separate issue. I just opened #116. |
As briefly discussed in #107 in would be great if one could also select
y_rep
from the global environment instead of having it saved as a model parameter. For instance, this would help using PPcheck for models fitted with brms, as they do not contain ay_rep
parameter to keep the object size reasonable.The text was updated successfully, but these errors were encountered: