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)`