1. Learn
  2. /
  3. Courses
  4. /
  5. Bayesian Modeling with RJAGS

Connected

Exercise

Plotting the Poisson regression model

Recall the likelihood structure for your Bayesian Poisson regression model of volume \(Y\)i by weekday status \(X\)i and temperature \(Z\)i: \(Y\)i \(\sim Pois(l\)i) where

  • \(log(l\)i\() \; = a + b \; X\)i \(+ c \; Z\)i; thus
  • \(l\)i\( \; = exp(a + b \; X\)i \(+ c \; Z\)i\()\)

Your 10,000 iteration RJAGS simulation of the model posterior, poisson_sim, is in your workspace along with a data frame of the Markov chain output:

> head(poisson_chains, 2)
         a b.1.       b.2.          c
1 5.019807    0 -0.1222143 0.01405269
2 5.018642    0 -0.1217608 0.01407691

You will use these results to plot the posterior Poisson regression trends. These nonlinear trends can be added to a ggplot() using stat_function(). For example, specifying fun = function(x){x^2} would return a quadratic trend line.

Instructions

100 XP

Construct a scatterplot of volume by hightemp with the following features:

  • Use color to distinguish between weekdays & weekends.
  • Superimpose a red curve that represents the posterior mean Poisson regression trend \(l\)i of the linear relationship between volume and hightemp for weekends: l = exp(a + c Z)
  • Superimpose a turquoise3 curve that represents the posterior mean Poisson regression trend \(l\)i of the linear relationship between volume and hightemp for weekdays: l = exp((a + b.2.) + c Z)