All Projects → ropensci → stantargets

ropensci / stantargets

Licence: Unknown, MIT licenses found Licenses found Unknown LICENSE MIT LICENSE.md
Reproducible Bayesian data analysis pipelines with targets and cmdstanr

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to stantargets

targets-tutorial
Short course on the targets R package
Stars: ✭ 87 (+180.65%)
Mutual labels:  make, reproducibility, targets
Targets
Function-oriented Make-like declarative workflows for R
Stars: ✭ 293 (+845.16%)
Mutual labels:  high-performance-computing, make, reproducibility
targets-minimal
A minimal example data analysis project with the targets R package
Stars: ✭ 50 (+61.29%)
Mutual labels:  high-performance-computing, reproducibility, targets
Stan
Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
Stars: ✭ 2,177 (+6922.58%)
Mutual labels:  bayesian, stan
Modelselection
Tutorial on model assessment, model selection and inference after model selection
Stars: ✭ 139 (+348.39%)
Mutual labels:  bayesian, stan
Miscellaneous R Code
Code that might be useful to others for learning/demonstration purposes, specifically along the lines of modeling and various algorithms. Now almost entirely superseded by the models-by-example repo.
Stars: ✭ 146 (+370.97%)
Mutual labels:  bayesian, stan
Bda py demos
Bayesian Data Analysis demos for Python
Stars: ✭ 781 (+2419.35%)
Mutual labels:  bayesian, stan
Bayadera
High-performance Bayesian Data Analysis on the GPU in Clojure
Stars: ✭ 342 (+1003.23%)
Mutual labels:  high-performance-computing, bayesian
Make Novice
Automation and Make
Stars: ✭ 122 (+293.55%)
Mutual labels:  make, reproducibility
Drake Examples
Example workflows for the drake R package
Stars: ✭ 57 (+83.87%)
Mutual labels:  high-performance-computing, reproducibility
Batchtools
Tools for computation on batch systems
Stars: ✭ 127 (+309.68%)
Mutual labels:  high-performance-computing, reproducibility
Accelerator
The Accelerator is a tool for fast and reproducible processing of large amounts of data.
Stars: ✭ 137 (+341.94%)
Mutual labels:  high-performance-computing, reproducibility
Projpred
Projection predictive variable selection
Stars: ✭ 76 (+145.16%)
Mutual labels:  bayesian, stan
Shinystan
shinystan R package and ShinyStan GUI
Stars: ✭ 172 (+454.84%)
Mutual labels:  bayesian, stan
Matlabstan
Matlab interface to Stan, a package for Bayesian inference
Stars: ✭ 59 (+90.32%)
Mutual labels:  bayesian, stan
bayesian
Bindings for Bayesian TidyModels
Stars: ✭ 33 (+6.45%)
Mutual labels:  bayesian, stan
Orbit
A Python package for Bayesian forecasting with object-oriented design and probabilistic models under the hood.
Stars: ✭ 346 (+1016.13%)
Mutual labels:  bayesian, stan
Bda r demos
Bayesian Data Analysis demos for R
Stars: ✭ 409 (+1219.35%)
Mutual labels:  bayesian, stan
Drake
An R-focused pipeline toolkit for reproducibility and high-performance computing
Stars: ✭ 1,301 (+4096.77%)
Mutual labels:  high-performance-computing, reproducibility
geostan
Bayesian spatial analysis
Stars: ✭ 40 (+29.03%)
Mutual labels:  bayesian, stan

stantargets

ropensci joss zenodo R Targetopia

active check codecov lint

Bayesian data analysis usually incurs long runtimes and cumbersome custom code, and the process of prototyping and deploying custom Stan models can become a daunting software engineering challenge. To ease this burden, the stantargets R package creates Stan pipelines that are concise, efficient, scalable, and tailored to the needs of Bayesian statisticians. Leveraging targets, stantargets pipelines automatically parallelize the computation and skip expensive steps when the results are already up to date. Minimal custom user-side code is required, and there is no need to manually configure branching, so stantargets is easier to use than targets and CmdStanR directly. stantargets can access all of cmdstanr’s major algorithms (MCMC, variational Bayes, and optimization) and it supports both single-fit workflows and multi-rep simulation studies.

Prerequisites

  1. The prerequisites of the targets R package.
  2. Basic familiarity with targets: watch minutes 7 through 40 of this video, then read this chapter of the user manual.
  3. Familiarity with Bayesian Statistics and Stan. Prior knowledge of cmdstanr helps.

How to get started

Read the stantargets introduction and simulation vignettes, and use https://docs.ropensci.org/stantargets/ as a reference while constructing your own workflows. Visit https://github.com/wlandau/stantargets-example-validation for an example project based on the simulation vignette. The example has an RStudio Cloud workspace which allows you to run the project in a web browser.

Example projects

Description Link
Validating a minimal Stan model https://github.com/wlandau/targets-stan
Using Target Markdown and stantargets to validate a Bayesian longitudinal model for clinical trial data analysis https://github.com/wlandau/rmedicine2021-pipeline

Installation

Install the GitHub development version to access the latest features and patches.

remotes::install_github("ropensci/stantargets")

The CmdStan command line interface is also required.

cmdstanr::install_cmdstan()

If you have problems installing CmdStan, please consult the installation guide of cmdstanr and the installation guide of CmdStan. Alternatively, the Stan discourse is a friendly place to ask Stan experts for help.

Usage

First, write a _targets.R file that loads your packages, defines a function to generate Stan data, and lists a pipeline of targets. The target list can call target factories like tar_stan_mcmc() as well as ordinary targets with tar_target(). The following minimal example is simple enough to contain entirely within the _targets.R file, but for larger projects, you may wish to store functions in separate files as in the targets-stan example.

# _targets.R
library(targets)
library(stantargets)

generate_data <- function() {
  true_beta <- stats::rnorm(n = 1, mean = 0, sd = 1)
  x <- seq(from = -1, to = 1, length.out = n)
  y <- stats::rnorm(n, x * true_beta, 1)
  list(n = n, x = x, y = y, true_beta = true_beta)
}

list(
  tar_stan_mcmc(
    name = example,
    stan_files = "x.stan",
    data = generate_data()
  )
)

Run tar_visnetwork() to check _targets.R for correctness, then call tar_make() to run the pipeline. Access the results using tar_read(), e.g. tar_read(example_summary_x). Visit the introductory vignette to read more about this example.

How it works behind the scenes

stantargets supports specialized target factories that create ensembles of target objects for cmdstanr workflows. These target factories abstract away the details of targets and cmdstanr and make both packages easier to use. For details, please read the introductory vignette.

Help

If you have trouble using stantargets, you can ask for help in the GitHub discussions forum. Because the purpose of stantargets is to combine targets and cmdstanr, your issue may have something to do with one of the latter two packages, a dependency of targets, or Stan itself. When you troubleshoot, peel back as many layers as possible to isolate the problem. For example, if the issue comes from cmdstanr, create a reproducible example that directly invokes cmdstanr without invoking stantargets. The GitHub discussion and issue forums of those packages, as well as the Stan discourse, are great resources.

Participation

Development is a community effort, and we welcome discussion and contribution. Please note that this package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Citation

citation("stantargets")
#> 
#> To cite stantargets in publications use:
#> 
#>   Landau, W. M., (2021). The stantargets R package: a workflow
#>   framework for efficient reproducible Stan-powered Bayesian data
#>   analysis pipelines. Journal of Open Source Software, 6(60), 3193,
#>   https://doi.org/10.21105/joss.03193
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Article{,
#>     title = {The stantargets {R} package: a workflow framework for efficient reproducible {S}tan-powered {B}ayesian data analysis pipelines},
#>     author = {William Michael Landau},
#>     journal = {Journal of Open Source Software},
#>     year = {2021},
#>     volume = {6},
#>     number = {60},
#>     pages = {3193},
#>     url = {https://doi.org/10.21105/joss.03193},
#>   }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].