All Projects → stan-dev → Bayesplot

stan-dev / Bayesplot

Licence: gpl-3.0
bayesplot R package for plotting Bayesian models

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Bayesplot

Shinystan
shinystan R package and ShinyStan GUI
Stars: ✭ 172 (-37.68%)
Mutual labels:  mcmc, bayesian, stan, r-package
cmdstanr
CmdStanR: the R interface to CmdStan
Stars: ✭ 82 (-70.29%)
Mutual labels:  bayesian, stan, r-package, mcmc
BAS
BAS R package https://merliseclyde.github.io/BAS/
Stars: ✭ 36 (-86.96%)
Mutual labels:  bayesian, r-package, mcmc
Projpred
Projection predictive variable selection
Stars: ✭ 76 (-72.46%)
Mutual labels:  bayesian, stan, r-package
Rstan
RStan, the R interface to Stan
Stars: ✭ 760 (+175.36%)
Mutual labels:  mcmc, stan, r-package
Tidybayes
Bayesian analysis + tidy data + geoms (R package)
Stars: ✭ 557 (+101.81%)
Mutual labels:  ggplot2, stan, r-package
walker
Bayesian Generalized Linear Models with Time-Varying Coefficients
Stars: ✭ 38 (-86.23%)
Mutual labels:  bayesian, stan, mcmc
Bda r demos
Bayesian Data Analysis demos for R
Stars: ✭ 409 (+48.19%)
Mutual labels:  mcmc, bayesian, stan
Rstanarm
rstanarm R package for Bayesian applied regression modeling
Stars: ✭ 285 (+3.26%)
Mutual labels:  bayesian, stan, r-package
Posterior
The posterior R package
Stars: ✭ 75 (-72.83%)
Mutual labels:  mcmc, bayesian, r-package
Ggmcmc
Graphical tools for analyzing Markov Chain Monte Carlo simulations from Bayesian inference
Stars: ✭ 95 (-65.58%)
Mutual labels:  mcmc, ggplot2, stan
Bda py demos
Bayesian Data Analysis demos for Python
Stars: ✭ 781 (+182.97%)
Mutual labels:  mcmc, bayesian, stan
geostan
Bayesian spatial analysis
Stars: ✭ 40 (-85.51%)
Mutual labels:  bayesian, stan, r-package
covidestim
Bayesian nowcasting with adjustment for delayed and incomplete reporting to estimate COVID-19 infections in the United States
Stars: ✭ 20 (-92.75%)
Mutual labels:  stan, r-package, mcmc
ggHoriPlot
A user-friendly, highly customizable R package for building horizon plots in ggplot2
Stars: ✭ 115 (-58.33%)
Mutual labels:  ggplot2, r-package
MultiBUGS
Multi-core BUGS for fast Bayesian inference of large hierarchical models
Stars: ✭ 28 (-89.86%)
Mutual labels:  bayesian, mcmc
LogDensityProblems.jl
A common framework for implementing and using log densities for inference.
Stars: ✭ 26 (-90.58%)
Mutual labels:  bayesian, mcmc
DynamicHMCExamples.jl
Examples for Bayesian inference using DynamicHMC.jl and related packages.
Stars: ✭ 33 (-88.04%)
Mutual labels:  bayesian, mcmc
stantargets
Reproducible Bayesian data analysis pipelines with targets and cmdstanr
Stars: ✭ 31 (-88.77%)
Mutual labels:  bayesian, stan
mapr
Map species occurrence data
Stars: ✭ 34 (-87.68%)
Mutual labels:  ggplot2, r-package

bayesplot

CRAN_Status_Badge Downloads R-CMD-check codecov

Overview

bayesplot is an R package providing an extensive library of plotting functions for use after fitting Bayesian models (typically with MCMC). The plots created by bayesplot are ggplot objects, which means that after a plot is created it can be further customized using various functions from the ggplot2 package.

Currently bayesplot offers a variety of plots of posterior draws, visual MCMC diagnostics, and graphical posterior (or prior) predictive checking. Additional functionality (e.g. for forecasting/out-of-sample prediction and other inference-related tasks) will be added in future releases.

The idea behind bayesplot is not only to provide convenient functionality for users, but also a common set of functions that can be easily used by developers working on a variety of packages for Bayesian modeling, particularly (but not necessarily) those powered by RStan.

Getting started

If you are just getting started with bayesplot we recommend starting with the tutorial vignettes, the examples throughout the package documentation, and the paper Visualization in Bayesian workflow:

Resources

Installation

  • Install from CRAN:
install.packages("bayesplot")
  • Install latest development version from GitHub (requires devtools package):
if (!require("devtools")) {
  install.packages("devtools")
}
devtools::install_github("stan-dev/bayesplot", dependencies = TRUE, build_vignettes = FALSE)

This installation won't include the vignettes (they take some time to build), but all of the vignettes are available online at mc-stan.org/bayesplot/articles.

Examples

Some quick examples using MCMC draws obtained from the rstanarm and rstan packages.

library("bayesplot")
library("rstanarm")
library("ggplot2")

fit <- stan_glm(mpg ~ ., data = mtcars)
posterior <- as.matrix(fit)

plot_title <- ggtitle("Posterior distributions",
                      "with medians and 80% intervals")
mcmc_areas(posterior, 
           pars = c("cyl", "drat", "am", "wt"), 
           prob = 0.8) + plot_title
color_scheme_set("red")
ppc_dens_overlay(y = fit$y, 
                 yrep = posterior_predict(fit, draws = 50))
# also works nicely with piping
library("dplyr")
color_scheme_set("brightblue")
fit %>% 
  posterior_predict(draws = 500) %>%
  ppc_stat_grouped(y = mtcars$mpg, 
                   group = mtcars$carb, 
                   stat = "median")

# with rstan demo model
library("rstan")
fit2 <- stan_demo("eight_schools", warmup = 300, iter = 700)
posterior2 <- extract(fit2, inc_warmup = TRUE, permuted = FALSE)

color_scheme_set("mix-blue-pink")
p <- mcmc_trace(posterior2,  pars = c("mu", "tau"), n_warmup = 300,
                facet_args = list(nrow = 2, labeller = label_parsed))
p + facet_text(size = 15)
# scatter plot also showing divergences
color_scheme_set("darkgray")
mcmc_scatter(
  as.matrix(fit2),
  pars = c("tau", "theta[1]"), 
  np = nuts_params(fit2), 
  np_style = scatter_style_np(div_color = "green", div_alpha = 0.8)
)
color_scheme_set("red")
np <- nuts_params(fit2)
mcmc_nuts_energy(np) + ggtitle("NUTS Energy Diagnostic")
# another example with rstanarm
color_scheme_set("purple")

fit <- stan_glmer(mpg ~ wt + (1|cyl), data = mtcars)
ppc_intervals(
  y = mtcars$mpg,
  yrep = posterior_predict(fit),
  x = mtcars$wt,
  prob = 0.5
) +
  labs(
    x = "Weight (1000 lbs)",
    y = "MPG",
    title = "50% posterior predictive intervals \nvs observed miles per gallon",
    subtitle = "by vehicle weight"
  ) +
  panel_bg(fill = "gray95", color = NA) +
  grid_lines(color = "white")
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].