Exercise

RJAGS simulation with categorical variables

Consider the Normal regression model of volume \(Y\)i by weekday status \(X\)i:

  • likelihood: \(Y\)i \(\sim N(m\)i, \(s^2)\) where \(m\)i \(= a + b X\)i
  • priors: \(a \sim N(400, 100^2)\), \(b \sim N(0, 200^2)\), \(s \sim Unif(0, 200)\)

You explored the relationship between \(Y\)i and \(X\)i for the 90 days recorded in RailTrail (in your workspace). In light of these data and the priors above, you will update your posterior model of this relationship. This differs from previous analyses in that \(X\)i is categorical. In rjags syntax, its coefficient \(b\) is defined by two elements, b[1] and b[2], which correspond to the weekend and weekday levels, respectively. For reference, b[1] is set to 0. In contrast, b[2] is modeled by the prior for \(b\).

Instructions 1/3

undefined XP
    1
    2
    3

DEFINE your Bayesian model.

  • Define the likelihood model of Y[i] given m[i] and s where m[i] <- a + b[X[i]]. Note the new notation b[X[i]] here!
  • Specify the priors for a, b (via b[1] and b[2]), and s.
  • Store the model string as rail_model_1.