The prior model Alicia Johnson Associate Professor, Macalester - - PowerPoint PPT Presentation

the prior model
SMART_READER_LITE
LIVE PREVIEW

The prior model Alicia Johnson Associate Professor, Macalester - - PowerPoint PPT Presentation

DataCamp Bayesian Modeling with RJAGS BAYESIAN MODELING WITH RJAGS The prior model Alicia Johnson Associate Professor, Macalester College DataCamp Bayesian Modeling with RJAGS Course Goals Explore foundational, generalizable Bayesian models


slide-1
SLIDE 1

DataCamp Bayesian Modeling with RJAGS

The prior model

BAYESIAN MODELING WITH RJAGS

Alicia Johnson

Associate Professor, Macalester College

slide-2
SLIDE 2

DataCamp Bayesian Modeling with RJAGS

Course Goals

Explore foundational, generalizable Bayesian models (eg: Beta-Binomial, Normal- Normal, and Bayesian regression) Define, compile, and simulate Bayesian models using RJAGS Conduct Bayesian posterior inference using RJAGS output

slide-3
SLIDE 3

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: The prior

slide-4
SLIDE 4

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: The prior

slide-5
SLIDE 5

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: The prior

slide-6
SLIDE 6

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: The data

slide-7
SLIDE 7

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: The posterior

slide-8
SLIDE 8

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: New data

slide-9
SLIDE 9

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: New posterior

slide-10
SLIDE 10

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: Newer data

slide-11
SLIDE 11

DataCamp Bayesian Modeling with RJAGS

Bayesian elections: Newer posterior

slide-12
SLIDE 12

DataCamp Bayesian Modeling with RJAGS

Bayesian thinking

A Bayesian posterior model... combines insights from the prior model & observed data evolves as new data come in

slide-13
SLIDE 13

DataCamp Bayesian Modeling with RJAGS

Building a prior model

p = proportion that support you p is between 0 and 1 The prior model for p is a Beta distribution with shape parameters 45 and 55 p ∼ Beta(45,55)

slide-14
SLIDE 14

DataCamp Bayesian Modeling with RJAGS

Tuning the prior

slide-15
SLIDE 15

DataCamp Bayesian Modeling with RJAGS

Let's practice!

BAYESIAN MODELING WITH RJAGS

slide-16
SLIDE 16

DataCamp Bayesian Modeling with RJAGS

Data & the likelihood

BAYESIAN MODELING WITH RJAGS

Alicia Johnson

Associate Professor, Macalester College

slide-17
SLIDE 17

DataCamp Bayesian Modeling with RJAGS

Polling Data

parameter p = proportion that support you data X = 6 of n = 10 polled voters plan to vote for you insights You are more likely to have observed these data if p ≈ 0.6 than if p < 0.5.

slide-18
SLIDE 18

DataCamp Bayesian Modeling with RJAGS

Modeling the dependence of X on p

Poll assumptions: voters are independent p = probability that a voter supports you X = number of n polled voters that support you (count of successes in n independent trials, each having probability of success p) Conditional distribution of X given p: X ∼ Bin(n,p)

slide-19
SLIDE 19

DataCamp Bayesian Modeling with RJAGS

Dependence of X on p

slide-20
SLIDE 20

DataCamp Bayesian Modeling with RJAGS

Dependence of X on p

slide-21
SLIDE 21

DataCamp Bayesian Modeling with RJAGS

Dependence of X on p

slide-22
SLIDE 22

DataCamp Bayesian Modeling with RJAGS

Dependence of X on p

slide-23
SLIDE 23

DataCamp Bayesian Modeling with RJAGS

What's the likelihood?

slide-24
SLIDE 24

DataCamp Bayesian Modeling with RJAGS

Likelihood

The likelihood function summarizes the likelihood of observing polling data X under different values of the underlying support parameter p. It is a function of p. high likelihood ⇒ p is compatible with the data low likelihood ⇒ p is not compatible with the data

slide-25
SLIDE 25

DataCamp Bayesian Modeling with RJAGS

Let's practice!

BAYESIAN MODELING WITH RJAGS

slide-26
SLIDE 26

DataCamp Bayesian Modeling with RJAGS

The posterior model

BAYESIAN MODELING WITH RJAGS

Alicia Johnson

Associate Professor, Macalester College

slide-27
SLIDE 27

DataCamp Bayesian Modeling with RJAGS

Bayesian election model

prior: p ∼ Beta(45,55)

slide-28
SLIDE 28

DataCamp Bayesian Modeling with RJAGS

Bayesian election model

prior: p ∼ Beta(45,55) likelihood: X ∼ Bin(10,p)

slide-29
SLIDE 29

DataCamp Bayesian Modeling with RJAGS

Bayesian election model

prior: p ∼ Beta(45,55) likelihood: X ∼ Bin(10,p)

slide-30
SLIDE 30

DataCamp Bayesian Modeling with RJAGS

Posterior model of p

prior: p ∼ Beta(45,55) likelihood: X ∼ Bin(10,p) Bayes' Rule: posterior ∝ prior * likelihood

slide-31
SLIDE 31

DataCamp Bayesian Modeling with RJAGS

Getting Started with RJAGS

RJAGS combines the power of R with the JAGS (Just Another Gibbs Sampler) engine.

To get started: Download the JAGS program outside R Within R, install the rjags package

slide-32
SLIDE 32

DataCamp Bayesian Modeling with RJAGS

Bayesian Models in RJAGS: DEFINE

X ∼ Bin(n,p) p ∼ Beta(a,b) Warning: the rjags function dbin() is different than base dbinom()

# DEFINE the model vote_model <- "model{ # Likelihood model for X X ~ dbin(p, n) # Prior model for p p ~ dbeta(a, b) }"

slide-33
SLIDE 33

DataCamp Bayesian Modeling with RJAGS

Bayesian Models in RJAGS: COMPILE

# DEFINE the model vote_model <- "model{ # Likelihood model for X X ~ dbin(p, n) # Prior model for p p ~ dbeta(a, b) }" # COMPILE the model vote_jags_A <- jags.model(textConnection(vote_model), data = list(a = 45, b = 55, X = 6, n = 10), inits = list(.RNG.name = "base::Wichmann-Hill", .RNG.seed = 100))

slide-34
SLIDE 34

DataCamp Bayesian Modeling with RJAGS

Bayesian Models in RJAGS: SIMULATE

# DEFINE the model vote_model <- "model{ # Likelihood model for X X ~ dbin(p, n) # Prior model for p p ~ dbeta(a, b) }" # COMPILE the model vote_jags <- jags.model(textConnection(vote_model), data = list(a = 45, b = 55, X = 6, n = 10), inits = list(.RNG.name = "base::Wichmann-Hill", .RNG.seed = 100)) # SIMULATE the posterior vote_sim <- coda.samples(model = vote_jags, variable.names = c("p"), n.iter = 10000)

slide-35
SLIDE 35

DataCamp Bayesian Modeling with RJAGS

Bayesian Models in RJAGS: SIMULATE

# PLOT the simulated posterior plot(vote_sim, trace = FALSE)

slide-36
SLIDE 36

DataCamp Bayesian Modeling with RJAGS

Let's practice!

BAYESIAN MODELING WITH RJAGS