knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
library(ggformula)
library(R2jags)
library(CalvinBayes)

CalvinBayes

The goal of CalvinBayes is to collect up some data sets and utilities for learning/teaching Bayesian Data analysis.

Installation

Github

You can install the development version of CalvinBayes from GitHub with

devtools::install_github("rpruim/CalvinBayes")

CRAN

This package is not on CRAN.

Example

Here is an example that demonstrates the use of the posterior() function to extract isamples from the posterior distribution of an object fit using the R2jags package.

library(R2jags)
library(CalvinBayes)
data("z15N50")
glimpse(z15N50)
# describe the model
bern_model <- function() {
  for (i in 1:N) {
    # each response is Bernoulli with fixed parameter theta
    y[i] ~ dbern(theta)  
  }
  theta ~ dbeta(1, 1)    # prior for theta
}
# Fit the model
bern_jags <- 
  jags(
    data = list(y = z15N50$y, N = nrow(z15N50)),
    model.file = bern_model,
    parameters.to.save = c("theta")
  )
glimpse(posterior(bern_jags))
library(ggformula)
gf_density(~ theta, data = posterior(bern_jags))


rpruim/CalvinBayes documentation built on April 12, 2021, 1:49 p.m.