Aan de slagGa gratis aan de slag

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\).

Deze oefening maakt deel uit van de cursus

Bayesian Modeling with RJAGS

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# DEFINE the model    
rail_model_1 <- "model{
    # Likelihood model for Y[i]
    for(i in ___){
      Y[i] ~ ___
      m[i] <- ___
    }
    
    # Prior models for a, b, s
    a ~ ___
    b[1] <- ___
    b[2] ~ ___
    s ~ ___
}"
Code bewerken en uitvoeren