开始使用免费开始使用

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

本练习是课程的一部分

Bayesian Modeling with RJAGS

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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 ~ ___
}"
编辑并运行代码