I'm new to JAGS, and I'm trying to run a simple logistic regression. My data file is very simple: the response is binary and the one predictor I'm using has three levels. Like this:
col1: 1 2 2 2 1 1 1 2 1 2 ...
col2: HLL, HLL, LHL, LLL, LHL, HLL ...
Dummy coding
The levels in col2
are HLL, LHL, LLL
. I dummy coded it and created a data frame that looks like this:
(intercept) HLL LHL LLL
1 1 0 0 1
2 1 0 0 1
4 1 0 0 1
5 1 0 1 0
6 1 0 1 0
7 1 0 0 1
Data list
My data file (myList
), then, looks like this:
List of 5
$ y : num [1:107881] 2 2 2 2 2 2 2 2 2 2 ...
$ N : num 500
$ HLL: num [1:107881] 0 0 0 0 0 0 0 0 0 0 ...
$ LHL: num [1:107881] 0 0 0 1 1 0 0 0 0 1 ...
$ LLL: num [1:107881] 1 1 1 0 0 1 1 1 1 0 ...
I'm using N=500
because the full data frame is huge and I just want to test it.
Model
cat(
"model {
for( i in 1 : N ){
y[i] ~ dbern(mu[i])
mu[i] <- 1/(1+exp(-(a + b*HLL[i] + c*LHL[i] + d*LLL[i])))
}
a ~ dnorm(0, 1.0e-12)
b ~ dnorm(0, 1.0e-12)
c ~ dnorm(0, 1.0e-12)
d ~ dnorm(0, 1.0e-12)
}", file = "model.txt"
)
Running model + error
model = jags.model(file = "model.txt",
data = myList,
n.chains = 3, n.adapt = 500)
Error I get
Error in jags.model(file = "model.txt", data = antPenList, n.chains = 3, :
Error in node y[1]
Node inconsistent with parents