我对Winbugs比较陌生。 我得到"预期变量名称"我尝试使用以下模型加载数据时出错。我无法弄清楚数据中的哪个变量名称不是模型中的varialbel名称。请帮忙。
# Normal likelihood, identity link
# Random effects model for multi-arm trials
model{ # *** PROGRAM STARTS
for(i in 1:ns){ # LOOP THROUGH STUDIES
delta[i,1] <- 0 # treatment effect is zero for control arm
mu[i] ~ dnorm(0,.0001) # vague priors for all trial baselines
for (k in 1:na[i]) { # LOOP THROUGH ARMS
var[i,k] <- pow(se[i,k],2) # calculate variances
prec[i,k] <- 1/var[i,k] # set precisions
y[i,k] ~ dnorm(theta[i,k],prec[i,k]) # normal likelihood
theta[i,k] <- mu[i] + delta[i,k] # model for linear predictor
dev[i,k] <- (y[i,k]-theta[i,k])*(y[i,k]-theta[i,k])*prec[i,k] #Deviance contribution
}
resdev[i] <- sum(dev[i,1:na[i]]) # summed residual deviance contribution for this trial
for (k in 2:na[i]) { # LOOP THROUGH ARMS
delta[i,k] ~ dnorm(md[i,k],taud[i,k]) # trial-specific LOR distributions
}
}
totresdev <- sum(resdev[]) # Total Residual Deviance
for (c in 1:(nt-1)) { # priors for all mean treatment effects
for (k in (c+1):nt) { d[c,k] ~ dnorm(0,.0001) }
}
sd ~ dunif(0,5) # vague prior for between-trial SD
tau <- pow(sd,-2) # between-trial precision = (1/between-trial variance)
} # *** PROGRAM ENDS
# Data
list(ns=15, nt=6)
t[,1] t[,2] t[,3] t[,4] t[,5] t[,6] y[,1] y[,2] y[,3] y[,4] y[,5] y[,6] se[,1] se[,2] se[,3] se[,4] se[,5] se[,6] na[]
1 2 3 3 4 4 -0.032 0.067 0.108 0.054 0.136 0.178 0.0149 0.0218 0.0263 0.0264 0.0158 0.0156 6
1 2 3 3 4 4 -0.043 0.069 0.212 0.101 0.218 0.2 0.0156 0.0222 0.0287 0.0267 0.0159 0.0156 6
1 2 3 4 NA NA 0.004 0.076 0.119 0.171 NA NA 0.0158 0.0127 0.0126 0.0126 NA NA 4
1 2 3 4 NA NA -0.031 0.093 0.129 0.207 NA NA 0.0153 0.0121 0.0119 0.0119 NA NA 4
3 3 4 4 NA NA 0.149 0.186 0.208 0.223 NA NA 0.018 0.018 0.018 0.018 NA NA 4
2 3 4 4 NA NA 0.121 0.121 0.209 0.211 NA NA 0.0189 0.0186 0.0187 0.0183 NA NA 4
1 3 4 NA NA NA -0.045 0.133 0.186 NA NA NA 0.0332 0.0232 0.0224 NA NA NA 3
3 3 5 NA NA NA 0.1 0.08 0.14 NA NA NA 0.016 0.016 0.016 NA NA NA 3
2 3 5 NA NA NA 0.09 0.08 0.17 NA NA NA 0.024 0.024 0.025 NA NA NA 3
3 6 NA NA NA NA 0.027 0.066 NA NA NA NA 0.24 0.24 NA NA NA NA 2
1 5 NA NA NA NA -0.072 0.177 NA NA NA NA 0.06 0.042 NA NA NA NA 2
3 5 NA NA NA NA 0.052 0.189 NA NA NA NA 0.028 0.017 NA NA NA NA 2
3 6 NA NA NA NA 0.17 0.34 NA NA NA NA 0.028 0.028 NA NA NA NA 2
3 6 NA NA NA NA 0.15 0.23 NA NA NA NA 0.0214 0.0205 NA NA NA NA 2
3 6 NA NA NA NA 0.12 0.2 NA NA NA NA 0.018 0.0182 NA NA NA NA 2
END
# Initial Values
# Initial values for delta can be generated by WinBUGS.
#chain 1
list(sd=1, mu=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
d = structure(.Data = c(NA,0,0,0,0,0, NA,NA,0,0,0,0, NA,NA,NA,0, 0, 0, NA,NA,NA,NA,0, 0, NA,NA,NA,NA, 0, 0), .Dim = c(5,6)))
#chain 2
list(sd=4, mu=c(-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3)),
d = structure(.Data = c(NA,-2,0,5,0,2, NA,NA,0, 2,-5,-2, NA,NA,NA,5, 2,0, NA,NA,NA,NA, 2,0,NA,NA,NA,NA, NA,0), .Dim = c(5,6)))
#chain 3
list( sd=2, mu=c(-3, 5, -1, -3, 7, -3, -4, 5, -1, -3, 7, -3, -4, 5, -1)),
d = structure(.Data = c(NA,-3,-3,-3,-3,-3, NA, NA,-3,-3,-3,-3, NA,NA,NA,-3,-3,-3, NA,NA,NA,NA,- 3,-3, NA,NA,NA,NA,NA,-3), .Dim = c(5,6)))
答案 0 :(得分:0)
检查值之间的间距。我遇到了类似的问题,可以通过将空格转换为值之间的制表符并在语法中找到不适当的空间来解决。