Coder Social home page Coder Social logo

stan-dev / shinystan Goto Github PK

View Code? Open in Web Editor NEW
194.0 33.0 51.0 33.64 MB

shinystan R package and ShinyStan GUI

Home Page: https://mc-stan.org/shinystan

License: GNU General Public License v3.0

R 76.38% CSS 18.91% HTML 4.71%
stan mcmc r-package statistical-graphics shiny-apps r bayesian bayesian-statistics bayesian-inference bayesian-data-analysis

shinystan's Introduction

ShinyStan

CRAN_Status_Badge RStudio CRAN Mirror Downloads Codecov

ShinyStan provides immediate, informative, customizable visual and numerical summaries of model parameters and convergence diagnostics for MCMC simulations. The ShinyStan interface is coded primarily in R using the Shiny web application framework and is available via the shinystan R package.

Resources

Installation

  • Install the latest release from CRAN:
install.packages("shinystan")
  • Install the development version from GitHub (requires devtools package):
if (!require("devtools")) {
  install.packages("devtools")
}
devtools::install_github("stan-dev/shinystan", build_vignettes = TRUE)

Demo

After installing run

library("shinystan")
launch_shinystan_demo()

Screenshots

About ShinyStan

Applied Bayesian data analysis is primarily implemented through the MCMC algorithms offered by various software packages. When analyzing a posterior sample obtained by one of these algorithms the first step is to check for signs that the chains have converged to the target distribution and also for signs that the algorithm might require tuning or might be ill-suited for the given model. There may also be theoretical problems or practical inefficiencies with the specification of the model.

ShinyStan provides interactive plots and tables helpful for analyzing a posterior sample, with particular attention to identifying potential problems with the performance of the MCMC algorithm or the specification of the model. ShinyStan is powered by RStudio's Shiny web application framework and works with the output of MCMC programs written in any programming language (and has extended functionality for models fit using RStan and the No-U-Turn sampler).

Saving and deploying (sharing)

The shinystan package allows you to store the basic components of an entire project (code, posterior samples, graphs, tables, notes) in a single object. Users can save many of the plots as ggplot2 objects for further customization and easy integration in reports or post-processing for publication.

shinystan also provides the deploy_shinystan function, which lets you easily deploy your own ShinyStan apps online using RStudio's ShinyApps service for any of your models. Each of your apps (each of your models) will have a unique url and is compatible with Safari, Firefox, Chrome, and most other browsers.

Licensing

The shinystan R package and ShinyStan interface are open source licensed under the GNU Public License, version 3 (GPLv3).

shinystan's People

Contributors

avehtari avatar csgillespie avatar danschrage avatar dpastoor avatar jgabry avatar jonmcalder avatar martinmodrak avatar veenduco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shinystan's Issues

Add upload .csv to shinystan on shinyapps

From @bgoodri on stan-dev:

On Sun, Mar 1, 2015 at 6:35 AM, Ben Goodrich [email protected] wrote:
The other killer feature for the shinyapps version would be to have a button where people could upload the .csv files produced by whatever interface to Stan they happened to use. Then call read_stan_csv to create a stanfit object and launch_shinystan() on that.

Move show/hide customization

From Bob Carpenter on stan-dev:

The show/hide customization thing on the parameters plot is hard to see. I think we'll need conventions as to where these general controls go. For something this general, not having it on the display itself makes sense to me if that's possible.

Installation fails when building vignettes

I have knitr version 1.9, and the installation appears to ensure that I have the latest version of knitr when it runs, but I am still getting the error message:

Error: processing vignette 'using-shinyStan.Rmd' failed with diagnostics:
'html_vignette' is not an exported object from 'namespace:rmarkdown'

This prevents the installation from completing.

way to stop shinyStan from shinyStan?

Is there a way to stop shinyStan from shinyStan?

The instructions for Shiny (http://shiny.rstudio.com/articles/running.html) have this:

To stop the application you simply interrupt R – you can do this by pressing the Ctrl-C in some R front ends, or the Escape key in RStudio,or by clicking the stop button if your R environment provides one.

Ctrl-C doesn't work in the R GUI (at least on Mac OS X). I had to just kill the whole session and workspace from the outside.

pairs plot

From @mhandreae:

I think it would be nice to have a ggpairs plot to quickly assess the correlation of all beta regression coefficients quickly and efficiently for simple models for the beginning or intermediate user of Stan.

Copied from original issue: jgabry/SHINYstan#30

warning about disabled javascript

Many people include the NoScript or similar add-ons that block JavaScript execution by default. In that case, shinystan launches but does not do much of anything. In that case, there should be a warning / explanation somewhere that the user should allow JavaScript to execute from that local URL.

summary stats table resets when changing decimal places

From Bob Carpenter on stan-dev:

I went into view table options and changing decimal places reset everything --- this is probably not what you want to happen in general. Destructive ops with no "back" button need strong warnings to users, maybe in the form of a modal dialog box.

Error: object "coord" not found

Hi,

I'm just trying to install shinystan for the first time, but quickly run into the following error when I try to run the demo:

> library(shinystan)
Loading required package: shiny

This is shinystan version 2.0.1

> launch_shinystan_demo()

Listening on http://127.0.0.1:6177
Error in get(x, envir = ns, inherits = FALSE) : object 'coord' not found
Error in get(x, envir = ns, inherits = FALSE) : object 'coord' not found
Error in get(x, envir = ns, inherits = FALSE) : object 'coord' not found

I get the same error message up in my browser (or in RStudio when I view the output there). Any suggestions what could be going wrong here? Session Info follows.

Mark

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.1 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_NZ.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_NZ.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_NZ.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_NZ.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shinystan_2.0.1 shiny_0.12.2   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.1        magrittr_1.5       munsell_0.4.2      colorspace_1.2-6  
 [5] xtable_1.7-4       lattice_0.20-33    R6_2.1.1           stringr_1.0.0     
 [9] plyr_1.8.3         shinythemes_1.0.1  tools_3.2.2        xts_0.9-7         
[13] DT_0.1             grid_3.2.2         gtable_0.1.2       shinyjs_0.2.3     
[17] gtools_3.5.0       htmltools_0.2.6    digest_0.6.8       gridExtra_2.0.0   
[21] reshape2_1.4.1     ggplot2_1.0.1.9003 base64enc_0.1-3    htmlwidgets_0.5   
[25] dygraphs_0.5       mime_0.4           stringi_1.0-1      scales_0.3.0      
[29] threejs_0.2.1      markdown_0.7.7     httpuv_1.3.3       zoo_1.7-12        
> 

Problems deploying a shinyStan app

Thanks for this fantastic software. The shinyStan apps I've created work beautifully when I run them locally, but can't be deployed to shinyapps. I've tried different models, reinstalling everything etc.

Here's the "Deploy" output in R-Studio. I'm guessing it's a problem with threejs, but I'm not sure. I have the packages installed that are mentioned in the output.

Is deployment supposed to work with shinyStan?

Preparing to deploy application...DONE
Uploading application bundle...DONE
Deploying application: 33649...
Waiting for task: 12884152
  building: Parsing manifest
  building: Fetching packages
  building: Building package: threejs
################################## Begin Log ################################## 
}} Clipped -- Everything works until here {{
[2015-02-27T02:36:32.185118664+0000] Building R package: threejs (0.2.1)
/mnt/packages/build /mnt
Warning in untar2(tarfile, files, list, exdir, restore_times) :
  skipping pax global extended headers
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘threejs’ ...
** R
** inst
** preparing package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called ‘maps’
ERROR: lazy loading failed for package ‘threejs’
* removing ‘/usr/local/lib/R/site-library/threejs’
################################### End Log ################################### 
Error: Unhandled Exception: Child Task 12884157 failed: Error building image: Error building threejs (0.2.1). Build exited with non-zero status: 1
In addition: Warning messages:
1: In FUN(c("gtools", "xts", "dygraphs", "threejs", "shinyStan", "xtable" :
  Package 'threejs' not available in repository or locally
2: In FUN(c("gtools", "xts", "dygraphs", "threejs", "shinyStan", "xtable" :
  Package 'shinyStan' not available in repository or locally
Execution halted

dynamic trace error

From @mhandreae:

dynamic trace throws error
dimnames_zoo" not resolved from current namespace (xts)
everything else seems to run fine....

Error in ggplot2::theme(...) : could not find function "element_blank"

I am developing a package which has one function that calls shinystan to visualize/diagnose my MCMC sampling. The specific function call would be:

library(my_package)
## assuming this.df is in the correct dimensions
shinystan::launch_shinystan(shinystan::as.shinystan(this.df)

And then I get this error:

Loading...
Note: for large models ShinyStan may take a few moments to launch.
Loading required package: shiny

Listening on http://127.0.0.1:6658
Error in ggplot2::theme(...) : could not find function "element_blank"
Error in ggplot2::theme(...) : could not find function "element_blank"

It seems like ggplot2 was not loaded, because library(shinystan) or library(ggplot2) fixes this problem. I understand that I only imported 2 functions fromshinystan, and ggplot2 would still need to be libraried somewhere in my code. Is there anyway around this without having to depend on shinystan or ggplot2?

Allow renaming (or labelling) parameters

From Ben on stan-dev:

With the rstan on GitHub, it is technically possible to reassign names now, but you have to know what you are doing and it is difficult to then only print a subset of the renamed parameters.

So if shinyStan (whether offline or online) had a more convenient way to do this, I think it would help a lot.

ggplot import support

tracking progress of explicitly calling ggplot

  • geoms
  • base ggplot calls
  • theme elements
  • scales
  • qplot calls
  • aesthetics

Displaying shinystan output in pdf (knitr)

Hello!

I'm building an R package that implements MCMC sampling, and for the past few weeks I have been using shinystan to look at the statistical tests / traceplots / 3D plots on my chains. Super excited that shinystan is now on CRAN!!

I am in the process of writing my vignette, and I would like make the results transparent and reproducible. Is there anyway that I could display shinystan output (say, traceplot or 3D plot, or histogram of rhat),
through knitr, just like how I could display a ggplot2 graph. Right now I just take a few screenshots, but I am hoping there is a more clever/reproducible way of doing this.

Many thanks!

depends vs imports on ggplot/shiny

In regards to #82 it might be worth discussing the pros/cons of depends/imports.

With the depends, since the package requires loading on startup, you can 'get away' with not explicitly calling functions referencing the ggplot2 namespace. This makes it faster/easier to code inside the package, but results in situations like the above issue.

Also, anecdotally, I have run into some funky behavior with packages that force attaching as if you have similarly named functions your expectation of where a function sits in the namespace path can get screwy.

For example using the classic plyr/dplyr issue of using same verb names:

given a library poor_dependencies the depends on plyr,

library(dplyr)
library(poor_dependencies)

will result in plyr being attached second thus overwriting dplyr, which was hell to track down the first time this occurred.

Shiny and ggplot are reasonably well-behaved and have explicit-enough naming conventions that it is usually pretty easy to stay away from namespace clashes, so for your package I don't think those concerns are too big of a deal, and given shinystan, there is essential functionality in ggplot, so even by hadley's suggestions it is reasonable to use depends in this situation.

I guess the question is do we want to track down all the ggplot elements in all the source code :-o

if you want to move that direction, let me know and I'll start tracking things down in the update_ggplot_elements branch

shiny and stan look for "shinyStan" but package is "shinystan" -- case matters in R

Hi,
I've successfully installed package "shinystan" from CRAN (and have also successfully installed it from GitHub).

If I try to run "stan(...)" , I get the following error message:

mcmcStan <- stan(file = 'mymodel.stan', data = myData, chains = 0) # Prep run ("chains=0") to compile model.
Loading required package: shinyStan
Error in .requirePackage(package) :
unable to find required package ‘shinyStan’
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘shinyStan’

Or even if I try to reinstall shiny (just fishing), R complains:

install.packages("shiny")
Loading required package: shinyStan
Error in .requirePackage(package) :
unable to find required package ‘shinyStan’
Installing package into ‘C:/xxxxxxxxxxxx/win-library/3.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.2/shiny_0.12.2.zip'
Content type 'application/zip' length 1866824 bytes (1.8 MB)
downloaded 1.8 MB

Note that the asked for package name in the error message is camelcase "shinyStan", which of course is not the same as the all lowercase name of the actual installed package "shinystan".

Am I missing something? How do I get stan to run again -- I've only had this problem since upgrading to the latest version of rstan?

Thanks.

partial autocorrelations

Bill Harris commented on Andrew's blog that we should add an option for partial autocorrelations.

as.shinystan throws error when fed list of matrices without colnames

This is a simple to fix but surprisingly frustrating bug. As.shinystan expects any lists of matrices of mcmc output to have column names; if it doesn't, it will throw an uninformative error regarding subscripts out of range:

Error in out[, i, ] <- chain_list[[i]] :
number of items to replace is not a multiple of replacement length

An easy fix is to put in a check for colnames in the chains2shinystan() and then to generate colnames for the matrices via an lapply/paste0 combination.

I don't have a fully replicable example, but if that is necessary I can provide one.

Error when doing autocorrelation diagnostic

Showing multiview or autocorrelation diagnostics for my model causes shinystan to error out with the following messages:
Error in eval(substitute(expr), envir, enclos) :
invalid subscript type 'closure'
Error: invalid subscript type 'closure'

I'm happy to provide any of the files you might need, but I don't know how to dump out the stanfit object or how to send them to you.

I am using rstan 2.5 and R 3.1 on Arch Linux.

Rhat over time

From @mhandreae:

Could we have a plot of Rhat over time to assess convergence over time and consider an appropriate burn-in or compare model efficiency? Compare with Kruschke's diagMCMC, lower left plot.

Copied from original issue: jgabry/SHINYstan#11

Shinystan breaks under new ggplot2 (2.0)

This could be an easy fix, but under the new ggplot2 version 2.0, launch_shinystan fails with the following message:

Error in get(x, envir = ns, inherits = FALSE) : object 'coord' not found

It still opens a browser window to display the model, but there is no web site displayed (HTTP 500 error).

Options(error=recover) yields the following:

1: launch_shinystan(all_fits[[40]])
2: launch(object, rstudio, ...)
3: shiny::runApp(system.file("ShinyStan", package = "shinystan"), launch.browser = launch.browser, ...)
4: shinyCallingHandlers(while (!.globals$stopped) {
serviceApp()
Sys.sleep(0.001)
})
5: withCallingHandlers(expr, error = function(e) {
handle <- getOption("shiny.error")
if (is.function(handle))

6: serviceApp()
7: timerCallbacks$timeToNextEvent()
8: dim(.times)
9: dim.data.frame(.times)

Selecting option 9 shows the following function:

function (x)
c(.row_names_info(x, 2L), length(x))

Sorry I can't be of more help. Uninstalling ggplot2 2.0 and re-installing 1.0 or 1.1 from source resolves the problem.

diagnostics with unconstrained parameters

The various plots should have an checkbox to utilize the parameters in the unconstrained space. These can be obtained with something like

pars <- extract(stanfit, permuted = FALSE, inc_warmup = maybe)
skeleton <- get_inits(stanfit)[[1]]
upars <- apply(pars, 1:2, FUN = function(theta) {
  unconstrain_pars(stanfit, relist(theta, skeleton))
})
upars <- aperm(upars, c(2,3,1))
dimnames(upars) <- c(dimnames(pars)[1:2], list(parameters = 
                     head(dimnames(pars)[[3]], dim(upars)[3])))

error: subscript out of bounds

If you do

fit1 <- stan_glm(Volume ~ log(Girth) + log(Height), data = trees,  family = gaussian(link = 'log'))
launch_shinystan(fit1)

and go to NUTS (Plots), you get the error message and in the console it says

Error in samps_post_warmup[if (!is.null(sel)) sel, , "lp__"] : 
  subscript out of bounds

This may have to do with it being renamed "log-posterior"?

specify parameters by regexp

Particularly for something like an object produced by stan_glmer, it is tedious to specify which group-level parameters you want to plot or whatever because they are not part of a larger array. In this case, it would be nice if you could specify all parameters that match a regular expression.

Latex export is not affected by Decimal places

In Posterial summary statistics, I want to export latex format using "Decimal places" for 3 digits, however, the result always stays at 2 digits. Is there any temporary alternative now? Thanks

Error when calling launch_shinystan

This works fine under Linux:

library (rstan)
library (shinystan)

scode <- "
parameters {
  real y[2]; 
} 
model {
  y[1] ~ normal(0, 1);
  y[2] ~ double_exponential(0, 2);
} 
"
fit1 <- stan(model_code = scode, iter = 10, verbose = FALSE) 

sso <- launch_shinystan(fit1)

But within Windows it produces this:

Loading... 
Note: for large models ShinyStan may take a few moments to launch.

Listening on http://127.0.0.1:6405
Error in a("Stan Modeling Language User's Guide and Reference Manual",  : 
  unused argument (href = "http://mc-stan.org/documentation/")

I'm running from within RStudio for both OSs. This is happening with all models I've tried (above is from the first example in the ?stan help), and with rstudio=TRUE. I've tried this after installing ShinyStan from either CRAN or GitHub.

Any ideas?

PS. ShinyStan is a very, very cool package! Thanks for all the work.

Add lines to scatterplot

From @andrewgelman on stan-dev:

I think that in shinystan it would be good to plot the scatterplot between 2 variables with light lines connecting the dots so that it gives some sense of the trace as well as of the joint distribution of the simulation.

check for R version first

I tried to install shinyStan, and after a whole lot of packages whirling by, it finally said it couldn't do it because my R was too old. Is there a way to check for that first?

free up horizontal space on summary stats page

From Bob Carpenter:

The posterior summary stats is wasting a lot of horizontal space (super premium on the web) for the
control. Is there some way to minimize that when it's not being used? Maybe put it above or below the plot?

shinyStan license

shinyStan needs an explicitly stated license.

The options are

  • BSD (what Stan C++ and CmdStan use)
  • GPLv3 (what R, RStan, and PyStan use)

BSD is more liberal in the sense that it's more flexible for users. But even if shinyStan is BSD, the combination of shinyStan + R is going to have the same copyleft (GPL) implications as R itself. So probalby GPLv3 would be easier. It'll also make it easier when you write it up for JStatSoft :-)

I'm still unhappy about PyStan using GPLv3 because Python isn't as restrictive as R, but it's what Allen wanted to go with.

I'm about to update the Stan web pages to include a link to shinyStan and I'll indicate that it's GPLv3.

Wiki landing page and index

Currently, the top-level Wiki page is redundant with the installation page. I'd suggest following the pattern used by Stan itself to have the landing Wiki page be an index and description of what's available. At least until there's another web page for shinyStan I can link to from the Stan home page.

Graphical posterior predictive checks

For users with posterior predictive simulations from generated quantity block we should allow them to input their original data from R and shinyStan should automatically generate a bunch of plots for graphical posterior predictive checking

Expand pp checking

First version of pp checking will be included in v1.1.0 to be released soon.

Opening this issue to keep improving and expanding pp checking capabilities on the to-do list.

allow users to add their own plots to personal panel

Add a new tab for displaying user's personal plots. They can add plots by

  • pointing shinyStan to a ggplot2 object in their R global environment
  • uploading .RData file containing a ggplot2 object
  • upload an image (e.g. png, etc.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.