{"id":13665954,"url":"https://github.com/stan-dev/rstanarm","last_synced_at":"2025-04-04T06:10:00.089Z","repository":{"id":9548662,"uuid":"11455249","full_name":"stan-dev/rstanarm","owner":"stan-dev","description":"rstanarm R package for Bayesian applied regression modeling","archived":false,"fork":false,"pushed_at":"2024-06-25T14:46:29.000Z","size":122589,"stargazers_count":388,"open_issues_count":168,"forks_count":132,"subscribers_count":43,"default_branch":"master","last_synced_at":"2024-10-29T14:21:57.215Z","etag":null,"topics":["bayesian","bayesian-data-analysis","bayesian-inference","bayesian-methods","bayesian-statistics","multilevel-models","r","r-package","rstan","rstanarm","stan","statistical-modeling"],"latest_commit_sha":null,"homepage":"https://mc-stan.org/rstanarm","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stan-dev.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"stan-dev","custom":"https://mc-stan.org/support/"}},"created_at":"2013-07-16T17:11:11.000Z","updated_at":"2024-10-08T04:45:04.000Z","dependencies_parsed_at":"2023-02-19T19:45:49.164Z","dependency_job_id":"90dd6ed5-01d9-4eaa-933b-9159b7ba00a8","html_url":"https://github.com/stan-dev/rstanarm","commit_stats":{"total_commits":2759,"total_committers":36,"mean_commits":76.63888888888889,"dds":0.4929322218194998,"last_synced_commit":"36f8c734da4424b3c63113010e9d955c244dab72"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-dev%2Frstanarm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-dev%2Frstanarm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-dev%2Frstanarm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stan-dev%2Frstanarm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stan-dev","download_url":"https://codeload.github.com/stan-dev/rstanarm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247015869,"owners_count":20869611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian","bayesian-data-analysis","bayesian-inference","bayesian-methods","bayesian-statistics","multilevel-models","r","r-package","rstan","rstanarm","stan","statistical-modeling"],"created_at":"2024-08-02T06:00:54.707Z","updated_at":"2025-04-04T06:10:00.073Z","avatar_url":"https://github.com/stan-dev.png","language":"R","readme":"# rstanarm \u003cimg src=\"man/figures/stanlogo.png\" align=\"right\" width=\"120\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![CRAN\\_Status\\_Badge](https://www.r-pkg.org/badges/version/rstanarm?color=blue)](https://cran.r-project.org/package=rstanarm)\n[![Downloads](https://cranlogs.r-pkg.org/badges/rstanarm?color=blue)](https://cran.rstudio.com/package=rstanarm)\n[![R-CMD-check](https://github.com/stan-dev/rstanarm/workflows/R-CMD-check/badge.svg)](https://github.com/stan-dev/rstanarm/actions)\n\u003c!-- badges: end --\u003e\n\n### Bayesian applied regression modeling (arm) via Stan\n\nThis is an R package that emulates other R model-fitting functions but uses\n[Stan](https://mc-stan.org) (via the **rstan** package) for the back-end\nestimation. The primary target audience is people who would be open to Bayesian\ninference if using Bayesian software were easier but would use frequentist\nsoftware otherwise. \n\nFitting models with **rstanarm** is also useful for experienced Bayesian\nsoftware users who want to take advantage the pre-compiled Stan programs that\nare written by Stan developers and carefully implemented to prioritize numerical\nstability and the avoidance of sampling problems.\n\nClick the arrows for more details:\n\u003cdetails\u003e\u003csummary\u003eMore detail\u003c/summary\u003e\n\nThe **rstanarm** package is an appendage to the **rstan** package, the R\ninterface to [Stan](https://mc-stan.org/). **rstanarm** enables many of the most\ncommon applied regression models to be estimated using Markov Chain Monte Carlo,\nvariational approximations to the posterior distribution, or optimization. The\npackage allows these models to be specified using the customary R modeling\nsyntax (e.g., like that of `glm` with a `formula` and `data.frame`).\nAdditional arguments are provided for specifying prior distributions.\n\nThe set of models supported by **rstanarm** is large (and will continue to\ngrow), but also limited enough so that it is possible to integrate them\ntightly with the [`pp_check`](https://mc-stan.org/rstanarm/reference/pp_check.stanreg.html) function for graphical posterior predictive checks using [**bayesplot**](https://mc-stan.org/bayesplot) and the\n[`posterior_predict`](https://mc-stan.org/rstanarm/reference/posterior_predict.stanreg.html)\nfunction to easily estimate the effect of specific manipulations of predictor\nvariables or to predict the outcome in a training set.\n\nThe fitted model objects returned by the **rstanarm** modeling functions are\ncalled _stanreg_ objects. In addition to all of the traditional\n[methods](https://mc-stan.org/rstanarm/reference/stanreg-methods.html)\ndefined for fitted model objects, stanreg objects can also be used with the\n[**loo**](https://mc-stan.org/rstanarm/reference/loo.stanreg.html) package for\nleave-one-out cross-validation, model comparison, and model weighting/averaging\nand the [**shinystan**](https://mc-stan.org/rstanarm/reference/shinystan.html) \npackage for exploring the posterior distribution and model diagnostics\nwith a graphical user interface. \n\nCheck out the **rstanarm** [vignettes](https://mc-stan.org/rstanarm/articles/)\nfor examples and more details about the entire process.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eModeling functions\u003c/summary\u003e\n\nThe model estimating functions are described in greater detail in their\nindividual help pages and vignettes. Here we provide a very brief overview:\n\n* [__`stan_lm`__, __`stan_aov`__,__`stan_biglm`__](https://mc-stan.org/rstanarm/reference/stan_lm.html)\n\n  Similar to  `lm` and `aov` but with novel regularizing priors on the model\n  parameters that are driven by prior beliefs about R-squared, the proportion of\n  variance in the outcome attributable to the predictors in a linear model.\n\n* [__`stan_glm`__, __`stan_glm.nb`__](https://mc-stan.org/rstanarm/reference/stan_glm.html)\n\n  Similar to `glm` but with various possible prior distributions for the\n  coefficients and, if applicable, a prior distribution for any auxiliary\n  parameter in a Generalized Linear Model (GLM) that is characterized by a\n  `family` object (e.g. the shape parameter in Gamma models). It is also possible\n  to estimate a negative binomial model similar to the `glm.nb` function\n  in the `MASS` package.\n\n* [__`stan_glmer`__, __`stan_glmer.nb`__, __`stan_lmer`__](https://mc-stan.org/rstanarm/reference/stan_glmer.html)\n\n  Similar to the `glmer`, `glmer.nb`, and `lmer` functions (__lme4__ package) in\n  that GLMs are augmented to have group-specific terms that deviate from the\n  common coefficients according to a mean-zero multivariate normal distribution\n  with a highly-structured but unknown covariance matrix (for which **rstanarm**\n  introduces an innovative prior distribution). MCMC provides more appropriate\n  estimates of uncertainty for models that consist of a mix of common and\n  group-specific parameters.\n  \n* [__`stan_nlmer`__](https://mc-stan.org/rstanarm/reference/stan_nlmer.html)\n\n  Similar to `nlmer` (__lme4__ package) package for nonlinear \"mixed-effects\"\n  models, but flexible priors can be specified for all parameters in the model, \n  including the unknown covariance matrices for the varying \n  (group-specific) coefficients.\n\n* [__`stan_gamm4`__](https://mc-stan.org/rstanarm/reference/stan_gamm4.html)\n\n  Similar to `gamm4` (__gamm4__ package), which augments a GLM (possibly with\n  group-specific terms) with nonlinear smooth functions of the predictors to\n  form a Generalized Additive Mixed Model (GAMM). Rather than calling\n  `lme4::glmer` like `gamm4` does, `stan_gamm4` essentially calls `stan_glmer`,\n  which avoids the optimization issues that often crop up with GAMMs and\n  provides better estimates for the uncertainty of the parameter estimates.\n \n* [__`stan_polr`__](https://mc-stan.org/rstanarm/reference/stan_polr.html)\n\n  Similar to `polr` (__MASS__ package) in that it models an ordinal response,\n  but the Bayesian model also implies a prior distribution on the unknown\n  cutpoints. Can also be used to model binary outcomes, possibly while\n  estimating an unknown exponent governing the probability of success.\n \n* [__`stan_betareg`__](https://mc-stan.org/rstanarm/reference/stan_betareg.html)\n\n  Similar to `betareg` (__betareg__ package) in that it models an outcome that\n  is a rate (proportion) but, rather than performing maximum likelihood\n  estimation, full Bayesian estimation is performed by default, with\n  customizable prior distributions for all parameters.\n\n* [__`stan_clogit`__](https://mc-stan.org/rstanarm/reference/stan_clogit.html)\n\n   Similar to `clogit` (__survival__ package) in that it models an binary outcome\n   where the number of successes and failures is fixed within each stratum by\n   the research design. There are some minor syntactical differences relative\n   to `survival::clogit` that allow `stan_clogit` to accept\n   group-specific terms as in `stan_glmer`.\n\n* [__`stan_mvmer`__](https://mc-stan.org/rstanarm/reference/stan_mvmer.html)\n\n   A multivariate form of `stan_glmer`, whereby the user can specify\n   one or more submodels each consisting of a GLM with group-specific terms. If\n   more than one submodel is specified (i.e. there is more than one outcome\n   variable) then a dependence is induced by assuming that the group-specific\n   terms for each grouping factor are correlated across submodels.\n\n* [__`stan_jm`__](https://mc-stan.org/rstanarm/reference/stan_jm.html)\n\n   Estimates shared parameter joint models for longitudinal and time-to-event\n   (i.e. survival) data. The joint model can be univariate (i.e. one longitudinal\n   outcome) or multivariate (i.e. more than one longitudinal outcome). A variety\n   of parameterisations are available for linking the longitudinal and event\n   processes (i.e. a variety of association structures).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eEstimation algorithms\u003c/summary\u003e\n\nThe modeling functions in the **rstanarm** package take an `algorithm`\nargument that can be one of the following:\n\n* __Sampling__ (`algorithm=\"sampling\"`):\n \n Uses Markov Chain Monte Carlo (MCMC) --- in particular, Stan's implementation\n of Hamiltonian Monte Carlo (HMC) with a tuned but diagonal mass matrix --- \n to draw from the posterior distribution of the parameters. This is the slowest\n but most reliable of the available estimation algorithms and it is __the\n default and recommended algorithm for statistical inference__.\n\n* __Mean-field__ (`algorithm=\"meanfield\"`):\n\n Uses mean-field variational inference to draw from an approximation to the\n posterior distribution. In particular, this algorithm finds the set of\n independent normal distributions in the unconstrained space that --- when\n transformed into the constrained space --- most closely approximate the\n posterior distribution. Then it draws repeatedly from these independent\n normal distributions and transforms them into the constrained space. The\n entire process is much faster than HMC and yields independent draws but\n __is not recommended for final statistical inference__. It can be useful to\n narrow the set of candidate models in large problems, particularly when\n specifying `QR=TRUE` in `stan_glm`, `stan_glmer`, and `stan_gamm4`, but is\n __only an approximation to the posterior distribution__.\n\n* __Full-rank__ (`algorithm=\"fullrank\"`):\n\n Uses full-rank variational inference to draw from an approximation to the\n posterior distribution by finding the multivariate normal distribution in\n the unconstrained space that --- when transformed into the constrained space\n --- most closely approximates the posterior distribution. Then it draws\n repeatedly from this multivariate normal distribution and transforms the\n draws into the constrained space. This process is slower than meanfield\n variational inference but is faster than HMC. Although still an\n approximation to the posterior distribution and thus __not recommended\n for final statistical inference__, the approximation is more realistic than\n that of mean-field variational inference because the parameters are not\n assumed to be independent in the unconstrained space. Nevertheless, fullrank\n variational inference is a more difficult optimization problem and the\n algorithm is more prone to non-convergence or convergence to a local\n optimum.\n\n* __Optimizing__ (`algorithm=\"optimizing\"`):\n\n Finds the posterior mode using a C++ implementation of the LBGFS algorithm. If\n there is no prior information, then this is equivalent to maximum likelihood,\n in which case there is no great reason to use the functions in the **rstanarm**\n package over the emulated functions in other packages. However, if priors are\n specified, then the estimates are penalized maximum likelihood estimates, which\n may have some redeeming value. Currently, optimization is only supported for\n `stan_glm`.\n\n\u003c/details\u003e\n\n---\n\n### Resources\n\n* [mc-stan.org/rstanarm](https://mc-stan.org/rstanarm) (online documentation, vignettes)\n* [Ask a question](https://discourse.mc-stan.org) (Stan Forums on Discourse)\n* [Open an issue](https://github.com/stan-dev/rstanarm/issues) (GitHub issues for bug reports, feature requests)\n\n### Installation\n\n#### Latest Release\n\nThe most recent **rstanarm** release can be installed from CRAN via\n\n```r\ninstall.packages(\"rstanarm\")\n```\n\n#### Development Version\n\nTo install from GitHub, first make sure that you can install the **rstan**\npackage and C++ toolchain by following these\n[instructions](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started).\nOnce **rstan** is successfully installed, you can install **rstanarm** from\nGitHub using the **remotes** package by executing the following in R:\n\n```r\n# Change 2 to however many cores you can/want to use to parallelize install\n# If you experience crashes or run out RAM during installation, try changing this to 1\nSys.setenv(MAKEFLAGS = \"-j2\")\nSys.setenv(\"R_REMOTES_NO_ERRORS_FROM_WARNINGS\" = \"true\")\nremotes::install_github(\"stan-dev/rstanarm\", INSTALL_opts = \"--no-multiarch\", force = TRUE)\n```\n\nYou can switch `build_vignettes` to `TRUE` but it takes a lot longer to install and the \nvignettes are already separately available from the \n[Stan website](https://mc-stan.org/rstanarm/articles/index.html) \nand \n[CRAN](https://cran.r-project.org/package=rstanarm/vignettes). \nIf installation fails, please let us know by [filing an issue](https://github.com/stan-dev/rstanarm/issues).\n\n#### Survival Analysis Version\n\nThe `feature/survival` branch on GitHub contains a development version of **rstanarm** that includes survival analysis functionality (via the `stan_surv` modelling function). Until this functionality is available in the CRAN release of **rstanarm**, users who wish to use the survival analysis functionality can install a binary version of the survival branch of **rstanarm** from the Stan R packages repository with:\n\n```\ninstall.packages(\"rstanarm\", repos = c('https://stan-dev.r-universe.dev', getOption(\"repos\")))\n```\n\nNote that this binary is static (i.e. it is not automatically updated) and is only hosted so that users can access the (experimental) survival analysis functionality without needing to go through the time consuming (and sometimes painful) task of installing the development version of **rstanarm** from source.\n\n### Contributing \n\nIf you are interested in contributing to the development of **rstanarm** please \nsee the [developer notes](https://mc-stan.org/rstanarm/dev-notes/index.html) page.\n","funding_links":["https://github.com/sponsors/stan-dev","https://mc-stan.org/support/"],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstan-dev%2Frstanarm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstan-dev%2Frstanarm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstan-dev%2Frstanarm/lists"}