R Interface to Stan

User-facing R functions are provided to parse, compile, test, estimate, and analyze Stan models by accessing the header-only Stan library provided by the 'StanHeaders' package. The Stan project develops a probabilistic programming language that implements full Bayesian statistical inference via Markov Chain Monte Carlo, rough Bayesian inference via 'variational' approximation, and (optionally penalized) maximum likelihood estimation via optimization. In all three cases, automatic differentiation is used to quickly and accurately evaluate gradients without burdening the user with the need to derive the partial derivatives.


News

Wed December 28 2016 (2.14.1)

  1. Bug fixes
  • Fix data parsing error that occurred in rare cases
  • expose_stan_functions() works with integer-returning functions again
  • Do not use more cores than chains when calling mclapply()
  • Fix NUTS bug (really in StanHeaders) that underestimates variance

Sun December 18 2016 (2.13.2)

  1. Bug fixes
  • Avoid using hashing to check whether a recompile is necessary
  • Use .rds extension rather than .rda extension (thanks @illarisheinen)
  • Stan file names are now allowed to start with a number
  • Fix stan_rdump writing NULL instead of zero-length objects
  • Fix for structured unconstrained parameters in plots
  • The model-fitting functions now search lexically for objects declared in the data block
  • Estimated Bayesian Fraction of Missing Information is back but will only warn if a chain is less than 0.3
  • A keep.source (by default FALSE) argument was added to read_rdump in order to speed up read times (thanks @mespe)
  • Clarify doc on constrained parameters (thatnks @davharris)
  • The expose_stan_functions function gained an env argument
  • Relaxed attempt to find rtools on Windows
  • Try to preserve path order (thanks @vdorie)
  • The rstan package now works on openCPU
  • Check for existence of log files that might be cleaned out in long runs before attempting to read from them
  • Delete unneeded files in the temporary directory
  1. Changes
  • New vignette on interfacing with external C++ code, plus supporting arguments to stanc and stan_model
  • Use forking rather than socket connections in non-Windows, non-GUI environments
  • Energy diagnostic is accessable from the pairs plot
  • Uses the bayesplot package for most plots

Sat September 10 2016 (2.12.1)

  1. Bug fixes
  • Now throws warnings even if not in interactive() mode
  • Now does not treat print statements as numerical problems
  • Update rtools.R to detect recent RTools correctly
  • Fix .libPaths() on child processes when multiple cores are used
  • Correct monitor() when a stanfit object is passed to it, which would yield wrong results otherwise
  1. Changes
  • stanc_builder() now correctly handles comments and recursive #include statements

Thu July 28 2016 (2.11.1)

  1. Bug fixes
  • Warn if Stan program has an incomplete final line, which requires recompilation. Thanks to Chris Black.
  • Fix warning in use of seq. Thanks to Watal Iwasaki and Avraham Adler.
  • Fix refererence to T and F. Thanks to Henning Redestig.
  • Fix finding RTools33. Thanks to Jared Lander.
  • Fix for space in path to StanHeaders
  • Fix compilation error by suggesting BH >= 1.60.0
  1. Changes
  • Estimated Bayesian Fraction of Missing Information is no longer printed automatically. There will be a warning if it is less than 0.3 for any chain
  • The chain identification number is passed to the data block as a non-negative integer called CHAIN_ID so it can (optionally) be utilized

Fri June 24 2016 (2.10.1)

  1. Bug fixes
  • Fix for expose_stan_functions() that use random-number generation
  • Fix crash on some platforms when R is closed
  1. Changes
  • Vignettes now use RMarkdown instead of Sweave
  • Error rather than a warning when an unknown argument is passed
  • stanc_builder() can handle #included URLs
  • expose_stan_functions() and lookup() can deal with the new Stan language syntax

Sun Feb 07 2016 (2.9.0-2)

  1. Bug fixes
  • expose_stan_functions() now works with Stan's slicing syntax
  • expose_stan_functions() now handles exceptions correctly
  • stan() and sampling() will evaluate initial values in the parent process
  • rstan.package.skeleton() correctly calls package.skeleton() now thanks to Jonathon Steinhart
  • vb() works when one parameter is a prefix of another thanks to Paul Buerkner
  • checks its version number against that of StanHeaders to ease transitions
  1. Changes
  • vb() now supports initial values for the parameters
  • parallel sampling() now uses parallel::parLapplyLB thanks to David Manheim
  • possibly works on Solaris

Tue Jan 04 2016 (2.9.0)

  1. Bug fixes
  • Should build from GitHub on Windows now
  • Fix regexes when doing chains in parallel
  • Fix handling of constant margins in pairs
  1. Changes
  • Supports ADVI (both meanfield and fullrank)
  • Introduces save_warmup flag (default TRUE)
  • Uses ggplot2 2.0.0 now

Thu Nov 26 2015 (2.8.1)

  1. Bug fixes
  • Fix vignette build for R 3.1.x on Windows
  • Fix accidentally passing stan() arguments to stanc()
  • Fix output of numerical problems under Windows / RStudio
  • Have check button in RStudio call stanc_builder() rather than stanc()

Thu Nov 19 2015 (2.8.1)

  1. Bug fixes
  • several but nothing that would affect the draws from any posterior distribution
  1. Changes
  • introduce stanc_builder() with C++-style #include statements
  • introduce rstan.package.skeleton to create a package that depends on rstan like rstanarm

Sat Sep 19 2015 (2.8.0)

  1. Bug fixes
  • lots, many of which were reported on stan-users or the rstan GitHub repository
  1. Changes
  • informational messages are consolidated now
  • progress is put into the Viewer on RStudio for Windows only
  • open_progress = TRUE no longer hardcodes particular webbrowsers
  • extract_sparse_parts() function facilitates using sparse matrix multiplication by a vector
  • switch to ggplot2-based plots of stanfit objects
  • added a log argument to pairs.stanfit()

Thu Jul 16 2015 (2.7.0)

  1. Bug fixes
  • lots
  1. Changes
  • initial CRAN release after many previous releases on GitHub and Google Code
  • parallel execution of chains via cores argument or setting options(mc.cores = 4)
  • serializing compiled models via auto_write argument or setting rstan_options(auto_write = TRUE)
  • introduce the expose_stan_functions() function for testing and simulation
  • introduce the lookup() function to find relevant Stan functions
  • option to specify initial values of a subset of parameters
  • include argument to stan, extract, etc. to allow pars to indicate which parameters to exclude
  • pairs function is more useful by default and shows any divergent transitions
  • stanfit objects waste less space on the hard disk

Tue Oct 21 2014 (2.5.0)

  1. Bug fixes
  • issue 100
  • issue 102 (add warning for passing unknown arguments)
  • issue 104
  • issue 107 (add -DEIGEN_NO_DEBUG to model compilation flags)
  1. Changes
  • issue 103 (using stan::common::initialize_state)
  • add a simple parallel exapmle for Windows
  • update pairs function

Sun Jul 20 2014 (2.4.0)

  1. changes
  • remove nesterov optim algorithm
  • fix issue 90 (https://github.com/stan-dev/rstan/issues/90)
  • use CRAN BH and RcppEigen

Mon Jun 23 2014 (2.3.0)

  1. changes
  • updates for Stan 2.3.0
  • use \n instead of \r for printing sampling progress
  • default to 2 digits after decimal place for print method for stanfit

Wed Apr 15 2014

  1. Bug fixes
  • issue 62

Wed Feb 26 2014

  1. Bug fixes
  • issue 51

Thu Feb 13 2014 (2.2.0)

Sun Feb 9 2014

  1. Bug fixes
    • index out of bounds with Rcpp 0.11

Wed Jan 22 2014

  1. Bug fixes

    • RNG seed for optimizing not used (issue #37)
  2. Changes

    • add as_vector with default value of TRUE for stanmodel@optimizing
    • read_stan_csv uses R's functions to open files so that compressed files such as gzip are supported. But a compressed file can include only one file.

Sat Dec 21 2013

  1. Changes
    • speed up stanfit@extract for permuted=TRUE (code from R. Boylan)
    • changes due to changes in Stan's interface

Sun Oct 20 2013

  1. Bug fixes
    • specify sampler parameters such as using dense_e, unit_e
  2. Changes
    • using fixed path for boost and eigen in Makefile.win

Sun Oct 15 2013

  1. Bug fixes
  2. New features
    • add window option to traceplot
    • add all optimizers in Stan
  3. Changes
    • arguments for function stan due to the changes in Stan 2.0

May 23 2013

  1. Bug fixes
    • the output csv files was using col-major order, which should be row-major order

Mar 13 2013

  1. Changes
    • showing progress of sampling at the same line (using \r instead of \n)
    • plot for stanfit allows multiple pages
  2. New features
    • add rstan:::as.mcmc.list to convert stanfit object to coda object

Fri Feb 24 2013

  1. Bug fixes
    • NA's are created when converting too large integers during data preprocessing
    • plot when there is an array parameter of length 1
  2. New features
    • expose a model's log_prob and grad_log_prob function and add functions for transforming parameters between constrained space and unconstrained space
    • add a function monitor to summarize any mcmc samples given as a 3-d array (# iter * # chains * # parameters)

Mon Dec 3 2012

  1. New features
    • add get_posterior_mean for stanfit to obtain the posterior mean for all parameters
    • add optimizing for stanmodel to get MAP point estimate
  2. Changes
    • include library Eigen (remove dependency on RcppEigen)

Sat Nov 24 2012

  1. New features
    • add read_stan_csv to create stanfit objects from sample CSV files
    • introduce an as.data.frame S3 method for stanfit objects

Sun Nov 4 2012

  1. Bug fixes
    • lp__ is not included when specifying pars (issue 79) https://code.google.com/p/stan/issues/detail?id=79
  2. Changes
    • change default value of arugment permuted from FALSE to TRUE for extract method of S4 class stanfit

Wed Oct 24 2012

  1. New features

    • return empty stanfit object upon error such as incorrect data input, wrong argument specification, etc. Previously, it will stop. The empty stanfit includes the compiled model, so it can be reused.
    • add function stan_demo() to run examples included in Stan.
    • add function sflist2stanfit() to merge a list of stanfit objects into one, to facilitate some kind of user-level parallelism.
    • add S3 method as.matrix, as.array, is.array, dim, dimnames for stanfit objects.
    • specify seed using string of digits in addition to numbers
  2. Bug fixes

    • bug of setting parameter epsilon_pm wrongly for NUTS

Tue Sep 25 2012

  1. Changes

    • print progress of sampling with carriage return
  2. New features

    • add set_cppo to set c++ compiler optimization level flag
    • support test_grad in rstan; two modes --- sampling and test_grad --- for stanfit

Mon Sep 3 2012

  1. Changes
    • parameter n_chains changed to chains
    • derive model_name from model_code or file if model_name is not specified

Wed Aug 2012

  1. Changes
    • replace dots with underscores especially in function names

Sun Aug 26 2012

  1. New features

    • get more information about the sampler such as treedepth, the log-posterior back to R.
  2. Changes

    • use underscore '_' in some output and parameter names
    • use lower case in print of stanfit for 'Mean', etc.

Sat Aug 25 2012

  1. Bug fixes
    • deal with the case that Rcpp and rstan is installed to a path with space, which causes the library linked to cannot be found.

Fri Aug 24 2012

  1. Changes use boost 1.51.0

Tue Aug 21 2012

  1. Bug fixes

    • not working binary build for Mac (not fixed last time)
    • bug fixes in Stan
  2. New features

    • add makeconf.path function to obtain the full path for file Makeconf
    • add Rhat legend for stanfit's plot
    • support saving stanfit object for reusing across R sessions
    • using <lower=, upper=> syntax for bounded variables

Sat Aug 11 2012:

  1. Bug fixes

    • plot for stanfit wide y-axis
    • print for stanfit class
    • not working binary build for Mac, this is because variables for the path of header files are using values computed when the package is built.
  2. New features

    • add standard error of mean (SE.Mean) to print of stanfit
    • function stan allow suing previous fitted stanfit object by adding parameter 'fit'
    • allow some type of interruption during sampling
    • allow data for function stan to be specified as object names
  3. Others

    • more documentation
    • use GPL for License and add LicenseNote in DESCRIPTION file

Wed Aug 8 2012: Uploaded to googlecode wiki: internally released.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rstan")

2.14.1 by Ben Goodrich, 2 months ago


https://groups.google.com/forum/#!forum/stan-users, http://mc-stan.org


Report a bug at https://github.com/stan-dev/rstan/issues/


Browse source code at https://github.com/cran/rstan


Authors: Jiqiang Guo [aut], Jonah Gabry [aut], Ben Goodrich [cre, aut], Daniel Lee [ctb], Krzysztof Sakrejda [ctb], Trustees of Columbia University [cph], Oleg Sklyar [cph] (R/cxxfunplus.R), The R Core Team [cph] (R/pairs.R, R/dynGet.R), Jens Oehlschlaegel-Akiyoshi [cph] (R/pairs.R), Hadley Wickham [cph] (R/rtools.R), Joel de Guzman [cph] (Boost), John Fletcher [cph] (Boost), Thomas Heller [cph] (Boost), Eric Niebler [cph] (Boost)


Documentation:   PDF Manual  


Task views: Bayesian Inference


GPL (>= 3) license


Imports methods, stats4, inline, gridExtra, Rcpp

Depends on ggplot2, StanHeaders

Suggests RUnit, RcppEigen, BH, parallel, KernSmooth, loo, shinystan, bayesplot, rstantools, rstudioapi, Matrix, knitr

Linking to Rcpp, RcppEigen, BH, StanHeaders


Imported by DeLorean, DrBats, MCMCvis, beanz, bmlm, brms, ctsem, dfpk, hBayesDM, prophet, rstanarm, shinystan.

Depended on by CopulaDTA, MADPop, MIXFIM, edstan, eggCounts, varian.

Suggested by bayesplot, broom, ggmcmc, nimble, raw, rstantools.


See at CRAN