[R] Error message R2Jags
alexB
alexandre.budria at helsinki.fi
Wed Nov 28 19:37:53 CET 2012
Hi,
I'm trying to generate a GLMM for Y following a negative binomial
distribution. The first step I'm taking as a beginner in the use of R2Jags
is to generate a GLM for Y following a Poisson distribution (I heard it's
good in order to get used to the coding language), so here I am and here I
face the first error message for which I can't find any mistake of spelling.
Could you please give me your opinion about it?
I'm modelling the abundance of Thersitina parasites as a response to the
standard size of the host fish (=Standard), the type of site where it was
sampled (Site, two levelled factor: C, E) month of sampling (Month, 3
levelled factor: May, June, July).
Here's what I did:
MM1 <- model.matrix(~ Site * Month + Standard, data = Data)
head(MM1)
#
# (Intercept) SiteE MonthJune MonthJuly Standard SiteE:MonthJune
SiteE:MonthJuly
#1 1 0 0 0 5.14
0 0
#2 1 1 0 0 5.49
0 0
#3 1 1 0 0 5.20
0 0
#4 1 1 0 0 5.57
0 0
#5 1 0 0 0 4.90
0 0
#6 1 0 0 0 5.99
0 0
#
win.data1 <- list(Y = Data$Thersitina,
Eut = MM1[,2], # SiteE
M2 = MM1[,3], # Month2_June
M3 = MM1[,4], # Month3_July
Std = MM1[,5], # Standard
I2 = MM1[,6], # SiteE:Month2_June
I3 = MM1[,7], # SiteE:Month3_July
N = nrow(Data))
sink("GLM.txt")
cat("
model {
#Likelihood(data | parameters)
for (i in 1:N) { # N is the sample
size
Y[i] ~ dpois(mu[i])
eta[i] <- b[1] +
b[2] * Eut[i] +
b[3] * M2[i] +
b[4] * M3[i] +
b[5] * Std[i] +
b[6] * I2[i] +
b[7] * I3[i]
log(mu[i]) <- max(-20, min(20, eta[i]))
PRes[i] <- (Y[i] - mu[i]) / sqrt(mu[i]) #estimate residuals (=
observed - expected / sqrt(variance))
#Discrepancy measures (used for checking overdispersion)
YNew[i] ~ dpois(mu[i]) #New data
PResNew[i] <- (YNew[i] - mu[i]) / sqrt(mu[i])
D[i] <- pow(PRes[i], 2)
DNew[i] <- pow(PResNew[i], 2)
}
# Add up discrepancy measures
fit <- sum(D[1:N])
fit.new <- sum(DNew[1:N])
for (i in 1:6) { b[i] ~ dnorm(0.0, 0.01)
# b[i] ~ dunif(-20, +20)
}
}
",fill = TRUE)
sink()
inits1 <- function () {
list(b = rnorm(7, 0, 0.01))}
out1 <- jags(data = win.data1,
inits = inits1,
parameters = params1,
model.file = "GLM.txt",
n.thin = nt,
n.chains = nc,
n.burnin = nb,
n.iter = ni)
That's when R returns this error message:
#
#Compiling model graph
# Resolving undeclared variables
# Allocating nodes
#Deleting model
#
#Error in jags.model(model.file, data = data, inits = init.values, n.chains
= n.chains, :
# RUNTIME ERROR:
#Compilation error on line 13.
#Subset out of range: b[7]
#
So I guess there's a problem with line 13 of the code (i.e. b[7] * I3[i])
causing the problem, but why... I really don't see the problem :(
Any guess?
Thanks in advance,
aB
--
View this message in context: http://r.789695.n4.nabble.com/Error-message-R2Jags-tp4651178.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list