I am currently busy with a multiple regression analysis with JAGS toolbox. I'm using runjags, however I still get an error:
Error parsing model file:
syntax error on line 3 near ","
This how my model looks like:
modelString2 = "
model {
for ( i in 1:Ntotal ) {
y[i] ~ dnorm( beta[s[i],1] + beta[s[i],2] * x[i,1] + betax[1] * x[i,2] + betax[2] * x[i,3] + betax[3] * x[i,4]), 1/sigma^2 )
}
for( j in 1 : Nsubj ) {
beta[j , 1 : 2] ~ dnorm(betamu, R)
}
for ( k in 1:NxO ){
betax[k] ~ dnorm( 0 , 1/(10)^5 )
}
betamu[1 : 2] ~ dnorm(mean, prec)
R[1 : 2 , 1 : 2] ~ dwish(Omega, df)
S<-inverse(R)
ss[1]<-sqrt(S[1,1]) #var to sd
ss[2]<-sqrt(S[2,2]) #var to sd
ss[3]<-S[1,2]/(ss[1]*ss[2]) #cov to cor
sigma ~ dunif( 1.0E-3 , 1.0E+3 )
}
"
writeLines(modelString2, con = "multiple_regression.txt")
De error should be in this line:
y[i] ~ dnorm( beta[s[i],1] + beta[s[i],2] * x[i,1] + betax[1] * x[i,2] + betax[2] * x[i,3] + betax[3] * x[i,4]), 1/sigma^2 )
However, I have no idea where the error comes from. Somebody who can help me?
It looks as if you have two closing parentheses when you should just have one in that line.
You have:
y[i] ~ dnorm( beta[s[i],1] + beta[s[i],2] * x[i,1] + betax[1] * x[i,2] + betax[2] * x[i,3] + betax[3] * x[i,4]), 1/sigma^2 )
There is a closing parentheses right after
x[i,4]
and another after1/sigma^2
fordnorm
. The correct placement for it is after1/sigma^2
so that line should instead be:y[i] ~ dnorm( beta[s[i],1] + beta[s[i],2] * x[i,1] + betax[1] * x[i,2] + betax[2] * x[i,3] + betax[3] * x[i,4], 1/sigma^2 )
.You could also create a mean (or mu) object instead of putting the linear predictor inside of
dnorm
, which may reduce the likelihood of this type of error: