metropolis: Metropolis algorithm

Description Usage Arguments Examples

Description

Simple Metropolis algorithm implementations for simple models.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
metro_bern(
  x,
  n,
  step_size = 0.01,
  start = 0.5,
  num_steps = 10000,
  prior = dunif,
  ...
)

metro_norm(
  y,
  num_steps = 1e+05,
  step_size = 1,
  start = list(mu = 0, log_sigma = 0)
)

Arguments

x

number of success in data

n

number of failures in data

step_size

sd of (normal) jump distribution(s)

start

starting value(s) for MCMC

num_steps

how long to run MCMC

prior

a function describing the prior

...

additional arguments for the prior

y

vecctor of numeric response values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Metro <-
  metro_bern(10, 30, step_size = 0.1, prior = dbeta, shape1 = 4, shape2 = 4)
# posterior density
Metro %>%
  gf_dens(~ theta) %>%
  gf_dist("beta", shape1 = 14, shape2 = 24, color = "red")
# trace plot
Metro %>%
  gf_line(theta ~ step)

metro_norm(rnorm(25, 10, 1), start = list(mu = 5, log_sigma = log(5))) %>%
  gf_density( ~ mu)

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