Skip to content
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

Closed
paul-buerkner opened this issue Jan 22, 2016 · 15 comments
Closed

Allow to select y_rep for PPcheck from the global environment #109

paul-buerkner opened this issue Jan 22, 2016 · 15 comments
Milestone

Comments

@paul-buerkner
Copy link

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 a y_rep parameter to keep the object size reasonable.

@jgabry jgabry added this to the 2+ milestone Jan 22, 2016
@jgabry
Copy link
Member

jgabry commented Jan 22, 2016

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.

@jgabry
Copy link
Member

jgabry commented Feb 18, 2016

@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.

@paul-buerkner
Copy link
Author

It works, thanks so much!

I noticed 2 little problems though, that are likely not specific to using y_rep from the globalenv.

  1. The boxes under select data, where you can choose the y_rep object, are pretty short so that it is hard to find the right object when you scroll through all objects.
  2. When comparing distributions of observed data and a random sample of replications using densities, the overlay plot only shows y and not y_rep for all of my examples I have tested so far.

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.

@jgabry
Copy link
Member

jgabry commented Feb 18, 2016

The boxes under select data, where you can choose the y_rep object, are pretty short so that it is hard to find the right object when you scroll through all objects.

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).

When comparing distributions of observed data and a random sample of replications using densities, the overlay plot only shows y and not y_rep for all of my examples I have tested so far.

Weird. I'll take a look.

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.

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?

@jgabry
Copy link
Member

jgabry commented Feb 18, 2016

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):

brms_shinystan

@paul-buerkner
Copy link
Author

My idea was that launch_shinystan could have an env (or similar named) argument to specify the environment to look for the objects. With regard to brms, I wouldn't require users to specify this argument. Rather, it would be set automatically be the function calling shinystan, e.g:

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.

@paul-buerkner
Copy link
Author

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:

separate
overlay

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     

@jgabry jgabry closed this as completed Feb 19, 2016
@jgabry jgabry reopened this Feb 19, 2016
@jgabry
Copy link
Member

jgabry commented Feb 19, 2016

closed by accident. reopening

@jgabry
Copy link
Member

jgabry commented Feb 19, 2016

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?

@jgabry
Copy link
Member

jgabry commented Feb 19, 2016

On Thursday, February 18, 2016, Paul-Christian Bürkner <
[email protected]> wrote:

My idea was that launch_shinystan could have an env (or similar named)
argument to specify the environment to look for the objects. With regard to
brms, I wouldn't require users to specify this argument. Rather, it would
be set automatically be the function calling shinystan

I'm not opposed to that. Let's get the plots working and then revisit this.

@paul-buerkner
Copy link
Author

Thanks Jonah! With the development version of ggplot2, the overlay plots are working fine. :-)

@jgabry
Copy link
Member

jgabry commented Feb 19, 2016

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.

@paul-buerkner
Copy link
Author

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?

@jgabry
Copy link
Member

jgabry commented Feb 24, 2016

Regarding the environment thing: Shall I open another issue for it?

Yeah let's put that in a separate issue. I just opened #116.

@jgabry
Copy link
Member

jgabry commented Apr 28, 2016

664cab5

@jgabry jgabry closed this as completed Apr 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants