kgh22
kgh22

Reputation: 1

How to specify to rjags to run hierarchical model with multiple conditions

I'm trying to run a Bayesian regression model using rjags, and my data have 4 relevant conditions. The model runs fine when collapsing across conditions, however I don't understand where/how to specify that I want this model to run separately for each condition, yet still give me a coda.samples output that allows me to compare Beta values (I would like 4 Beta0 and 4 Beta1 values, one for each condition). Here's my model:

    order_model <-
    "model {
beta_0 ~ dnorm(0, .0000001)
beta_1 ~ dnorm(0, .0000001)
sigma ~ dunif(0, 100)
sigma_u0 ~ dunif(0,100)
sigma_u1 ~ dunif(0,100)
sigma_i0 ~ dunif(0,100)


for (i in 1:num_items) {
  w_0i[i] ~ dnorm(0, 1/sigma_i0^2)
}

for (i in 1:num_subj+1) {
  u_0s[i] ~ dnorm(0, 1 / sigma_u0^2)
  u_1s[i] ~ dnorm(0, 1 / sigma_u1^2)
}
for (i in 1:length(rt)) {
  rt[i] ~ dnorm((beta_0 + w_0i[item[i]] + u_0s[subject[i]]) + (beta_1 + u_1s[subject[i]]) * order[i], 1/sigma^2)
}
}"

Where subject and item are referred to to get fixed effect offsets, and "rt" is a continuous dependent variable. Condition is coded in a vector "condition" with values 1:4.

I assume I need another for loop somewhere, but I'm not sure where.

Upvotes: 0

Views: 773

Answers (1)

Matt Denwood
Matt Denwood

Reputation: 2583

I think you just need to index beta_0 and beta_1 using condition like so:

  rt[i] ~ dnorm((beta_0[condition[i]] + w_0i[item[i]] + u_0s[subject[i]]) + (beta_1[condition[i]] + u_1s[subject[i]]) * order[i], 1/sigma^2)

[Or maybe beta_0[condition[subject[i]] depending on how the data is structured]

And:

  for(c in 1:4){
       beta_0[c] ~ dnorm(0, .0000001)
       beta_1[c] ~ dnorm(0, .0000001)
  }

You can then monitor the 4 values of beta_0 and beta_1 and compare them using the output from JAGS - either compare the credible intervals, or do pairwise comparisons by subtracting one level away from another and then look at the credible intervals for the difference.

Matt

Upvotes: 2

Related Questions