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.


Wed September 12 2018

  1. Bug fixes
  • Variational Bayes variable names were off-by-one in some circumstances
  • get_makefile_text() works on multiarch systems
  • The chain ID is printed in the intermediate output again
  • Low BFMI threshold is changed to 0.2 from 0.3
  1. Features
  • Requires the C++14 standard and hence R >= 3.4.0
  • Calculates effective sample size more correctly, which can result in an effective sample size greater than the nominal sample size due to negative first order autocorrelation for some quantities of interest
  • Utilizes the pkgbuild R package
  • Specifying refresh = 0 suppresses all intermediate output
  • expose_stan_functions() uses a new, more robust procedure to generate the Stan code to be exposed to R
  • read_stan_csv() is faster with less memory consumed
  • unconstrain_pars() gains a NULL default to its pars argument, in which case the entire matrix of unconstrained parameters is returned
  • If the list of initial values passed to Stan has named elements, these names are retained in the output
  • There is now a loo.stanfit() method
  • HMC diagnostics can be obtained in a more programmatic way via get_divergent_iterations(), get_max_treedepth_iterations(), get_num_leapfrog_per_iteration(), get_num_divergent(), get_num_max_treedepth()

Fri January 19 2018 (2.17.3)

  1. Bug fixes
  • Might build on Solaris again
  • Might propogate exception messages when there are parser errors on a Mac
  • Propogate error messages when the list of data passed is inconsistent with the data block in a Stan program

Wed December 20 2017 (2.17.2)

  1. Bug fixes
  • Now handles data types consistently when passed by string
  • expose_stan_functions() now does not obfuscate model names
  • Now works on Macs using the clang4 compiler from the AT&T website

Sun July 2, 2017 (2.16.1)

  1. Bug fixes
  • Now throws warnings even if there is only one chain
  • get_inits() handles its iter argument more correctly
  1. Features
  • expose_stan_functions() now has a ... argument allowing things to be passed to Rcpp::sourceCpp()

Wed April 19, 2017 (2.15.1)

  1. Bug fixes
  • expose_stan_functions() works with functions that return real containers

Sat March 18, 2017 (2.14.2)

  1. Bug fixes
  • Crashes less often when calling stan() repeatedly without assigning the resulting stanfit object to a symbol
  • expose_stan_functions() handles functions that produce integer arrays again
  • Improved regex for class names (thanks to Torsti Schulz)
  • Passing a list of matrices to the data argument works again
  1. Changes
  • When the sample_file and / or diagnostic_file arguments to sampling() were specified and the chains were run in parallel, the resulting file names were different than if the chains were run serially. The behavior in the parallel case has been changed to match the serial case; i.e. the file will be named "foo_#.csv" where # is the chain number rather than "foo.csv#". Some scripts that expect the old behavior may now be broken, but they should be fixed easily.

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 [email protected]
    • 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 [email protected] 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
  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.


2.21.2 by Ben Goodrich, a year ago

https://mc-stan.org/rstan, https://discourse.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] , Sebastian Weber [aut] , Daniel Lee [ctb] , Krzysztof Sakrejda [ctb] , Modrak Martin [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) , John Maddock [cph] (gamma.hpp) , Paul Bristow [cph] (gamma.hpp) , Nikhar Agrawal [cph] (gamma.hpp) , Christopher Kormanyos [cph] (gamma.hpp) , Bronder Steve [ctb]

Documentation:   PDF Manual  

Task views: Bayesian Inference

GPL (>= 3) license

Imports methods, stats4, inline, gridExtra, Rcpp, RcppParallel, loo, pkgbuild, withr, V8

Depends on StanHeaders, ggplot2

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

Linking to Rcpp, RcppEigen, BH, StanHeaders, RcppParallel

System requirements: GNU make, pandoc

Imported by AovBay, BANOVA, BINtools, BayesSenMC, CNVRG, CausalQueries, DAMisc, DCPO, DeLorean, EpiNow2, FlexReg, HuraultMisc, LMMELSM, MCMCvis, MIRES, MetaStan, OncoBayes2, PoolTestR, PosteriorBootstrap, RBesT, Rlgt, SSNbayes, StanMoMo, TriDimRegression, YPBP, YPPE, adnuts, baggr, bayes4psy, bayesGAM, bayesZIB, bayesbr, bayesdfa, bayesforecast, bayesmodels, beanz, bellreg, bistablehistory, bkmrhat, blavaan, bmgarch, bmggum, bmlm, bpcs, breathteststan, brms, brxx, bsem, cbq, conStruct, ctsem, dclone, densEstBayes, eggCounts, epidemia, fishflux, gastempt, ggfan, glmmfields, gppm, hBayesDM, hsstan, idem, isotracer, lgpr, llbayesireg, metaBMA, mrbayes, multinma, pcFactorStan, pivmet, prophet, publipha, qmix, rater, rbioacc, rcbayes, rmBayes, rmdcev, rmsb, rstanarm, rstanemax, shinybrms, shinystan, spatialfusion, spsurv, ssMousetrack, survHE, themetagenomics, thurstonianIRT, trialr, ubms.

Depended on by BayesianFROC, CopulaDTA, DrBats, GPP, GPRMortality, JMbayes, MADPop, MIXFIM, PandemicLP, bayesvl, bmscstan, clinDR, dfped, dfpk, edstan, evidence, fergm, iCARH, psrwe, tmbstan, varian, visit, walker.

Suggested by BCEA, BayesTools, RoBMA, SoupX, StanHeaders, bayesImageS, bayesian, bayesnec, bayesplot, bayestestR, bridgesampling, broom.mixed, concurve, finalfit, loo, makemyprior, modeltime, pollimetry, rstantools, sjstats, tidybayes, unifed.

Enhanced by DHARMa, mrregression.

See at CRAN