https://github.com/corymccartan/adjustr

An R package to help assess the sensitivity of a Bayesian model (fitted with Stan) to the specification of its likelihood and priors

https://github.com/corymccartan/adjustr

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.9%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

An R package to help assess the sensitivity of a Bayesian model (fitted with Stan) to the specification of its likelihood and priors

Basic Info
Statistics
  • Stars: 10
  • Watchers: 3
  • Forks: 0
  • Open Issues: 1
  • Releases: 4
Created about 6 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog License

README.md

adjustr

Lifecycle: experimental R-CMD-check Codecov test coverage <!-- badges: end -->

Sensitivity analysis is a critical component of a good modeling workflow. Yet as the number and power of Bayesian computational tools has increased, the options for sensitivity analysis have remained largely the same: compute importance sampling weights manually, or fit a large number of similar models, dramatically increasing computation time. Neither option is satisfactory for most applied modeling.

adjustr is an R package which aims to make sensitivity analysis faster and easier, and works with Bayesian models fitted with Stan. Users provide a series of alternate sampling specifications, and the package uses Pareto-smoothed importance sampling to estimate the posterior under each specification. The package also provides functions to summarize and plot how posterior quantities change across specifications.

The package provides simple interface that makes it as easy as possible for researchers to try out various adjustments to their Stan models, without needing to write any specific Stan code or even recompile or rerun their model.

The package works by parsing Stan model code, so everything works best if the model was written by the user. Models made using brms may in principle be used as well. Models made using rstanarm are constructed using more complex model templates, and cannot be used.

Getting Started

The basic adjustr workflow is as follows:

  1. Use make_spec to specify the set of alternative model specifications you'd like to fit.

  2. Use adjust_weights to calculate importance sampling weights which approximate the posterior of each alternative specification.

  3. Use summarize and spec_plot to examine posterior quantities of interest for each alternative specification, in order to assess the sensitivity of the underlying model.

To illustrate, the package lets us do the following: ```r extractsampstmts(eightschools_m)

> Sampling statements for model 2c8d1d8a30137533422c438f23b83428:

> parameter eta ~ std_normal()

> data y ~ normal(theta, sigma)

makespec(eta ~ studentt(0, 1, df), df=1:10) %>% adjustweights(eightschoolsm) %>% summarize(wasserstein(mu))

> # A tibble: 11 x 5

> df .samp .weights .pareto_k wasserstein(mu)

>

> 1 1 eta ~ student_t(df, 0, 1) 1.02 0.928

> 2 2 eta ~ student_t(df, 0, 1) 1.03 0.736

> 3 3 eta ~ student_t(df, 0, 1) 0.915 0.534

> 4 4 eta ~ student_t(df, 0, 1) 0.856 0.411

> 5 5 eta ~ student_t(df, 0, 1) 0.826 0.341

> 6 6 eta ~ student_t(df, 0, 1) 0.803 0.275

> 7 7 eta ~ student_t(df, 0, 1) 0.782 0.234

> 8 8 eta ~ student_t(df, 0, 1) 0.753 0.195

> 9 9 eta ~ student_t(df, 0, 1) 0.736 0.166

> 10 10 eta ~ student_t(df, 0, 1) 0.721 0.151

> 11 NA -Inf 0

```

The tutorial vignette walks through a full sensitivity analysis for this 8-schools example. Smaller examples are also included in the package documentation.

Installation

Install the latest version from GitHub:

r if (!require("devtools")) { install.packages("devtools") } devtools::install_github("corymccartan/adjustr@*release")

References

Vehtari, A., Simpson, D., Gelman, A., Yao, Y., & Gabry, J. (2015). Pareto smoothed importance sampling. arXiv preprint arXiv:1507.02646.

Owner

  • Name: Cory McCartan
  • Login: CoryMcCartan
  • Kind: user
  • Company: New York University

Faculty Fellow at NYU's Center for Data Science, working on computational social science problems and open-source R software.

GitHub Events

Total
  • Watch event: 1
  • Create event: 1
Last Year
  • Watch event: 1
  • Create event: 1

Issues and Pull Requests

Last synced: over 1 year ago

All Time
  • Total issues: 4
  • Total pull requests: 0
  • Average time to close issues: 29 days
  • Average time to close pull requests: N/A
  • Total issue authors: 4
  • Total pull request authors: 0
  • Average comments per issue: 2.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • ManfredKloebl (1)
  • mguzmann (1)
  • rpetrovska (1)
  • maswiebe (1)
Pull Request Authors
Top Labels
Issue Labels
bug (1)
Pull Request Labels

Dependencies

DESCRIPTION cran
  • R >= 3.6.0 depends
  • dplyr >= 1.0.0 depends
  • loo * imports
  • purrr * imports
  • rlang * imports
  • rstan * imports
  • stringr * imports
  • tidyselect * imports
  • covr * suggests
  • extraDistr * suggests
  • ggplot2 * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat * suggests
  • tidyr * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • actions/upload-artifact main composite
  • r-lib/actions/setup-pandoc v1 composite
  • r-lib/actions/setup-r v1 composite
.github/workflows/pkgdown.yaml actions
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v1 composite
  • r-lib/actions/setup-r v1 composite