1
我有點新尖齒,和我一直在貨架我的大腦試圖看到我在做什麼錯我的代碼,這是給這個錯誤信息:無法計算子表達尖齒
「無法計算precd'的子集表達式。
我附加了我的代碼,其中也有編碼的數據。我會很感激所有我能得到的幫助。
nS=number of studies,
r=number of events,
n=sample size,
tau.sq=heterogeneity,
na=number of arms,
sw='correction' for multi-arm trials.
Model<- function(){
for(i in 1:nS) {
w[i,1]<- 0
theta[i,t[i,1]]<- 0
for (k in 1:na[i]) {r[i,t[i,k]] ~ dbin(p[i,t[i,k]],n[i,t[i,k]])}
logit(p[i,t[i,1]])<- u[i]
for (k in 2:na[i]) {
logit(p[i,t[i,k]])<- u[i] + theta[i,t[i,k]]
theta[i,t[i,k]] ~ dnorm(md[i,t[i,k]],precd[i,t[i,k]])
md[i,t[i,k]]<- mean[i,k] + sw[i,k]
w[i,k]<- (theta[i,t[i,k]] - mean[i,k])
sw[i,k]<- sum(w[i,1:k-1])/(k-1)
precd[i,t[i,k]]<- prec*2*(k-1)/k
mean[i,k] <-d[t[i,k]] - d[t[i,1]]
}}
先驗爲基本參數
從這一點結果for (i in 1:nS) {u[i] ~ dnorm(0,.01)}
tau ~ dnorm(0,.01)
prec<- 1/pow(tau,2)
tau.sq<- pow(tau,2)
d[ref] <- 0
for(k in 1:(ref-1)) {d[k] ~ dnorm(0,.01)}
for(k in (ref+1):nT) {d[k] ~ dnorm(0,.01)}
保藏中心的治療
for(i in 1:(nT-1)) {
for (j in (i+1):nT) {
OR[j,i]<- exp(d[j] - d[i])
LOR[j,i]<- d[j] - d[i]}}
for(j in 1:(ref-1)){ORref[j]<- exp(d[j] - d[ref])}
for(j in (ref+1):nT) {ORref[j]<- exp(d[j] - d[ref])}
排名
for(k in 1:nT) {
order[k]<- rank(d[],k)
most.effective[k]<-equals(order[k],1)
for(j in 1:nT) {effectiveness[k,j]<- equals(order[k],j)
cumeffectiveness[k,j]<- sum(effectiveness[k,1:j])}}
for(k in 1:nT) {
SUCRA[k]<- sum(cumeffectiveness[k,1:(nT-1)]) /(nT-1)
}
for(i in 1:nS) {
for (k in 1:na[i]) {
Darm[i,k]<- -2*(r[i,t[i,k]] *log(n[i,t[i,k]]*p[i,t[i,k]]/
r[i,t[i,k]])+(n[i,t[i,k]] - r[i,t[i,k]])*log((n[i,t[i,k]]-
n[i,t[i,k]]* p[i,t[i,k]])/(n[i,t[i,k]]- r[i,t[i,k]])))}
D[i]<- sum(Darm[i,1:na[i]])}
D.bar<- sum(D[])
}
的數據被編碼下面
library(R2jags)
library(mcmc)
setwd("PATH-NAME")
# *******************************************************
# Data are coded below:
# BA -1
# BMS -2 *** REFERENCE
# DCB -3
# EES -4
# PES -5
# ROTA -6
# SES -7
# VBT -8
# *******************************************************
t_RCT = structure(.Data=c(1,6,NA,
1,6,NA,
1,2,NA,
1,2,NA,
2,6,NA,
1,2,NA,
1,8,NA,
1,8,NA,
1,8,NA,
5,8,NA,
5,8,NA,
1,5,7,
1,7,NA,
7,8,NA,
7,8,NA,
5,7,NA,
1,7,NA,
1,7,NA,
4,7,NA,
3,4,NA,
3,4,NA,
1,3,NA,
3,5,NA,
1,3,NA,
1,3,NA,
1,3,NA,
1,3,5,
3,5,NA), .Dim=c(28,3))
na_RCT <- c(2,2,2,2,2,2,2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,2)
r_RCT = structure(.Data=c(45,NA,NA,NA,NA,60,NA,NA,
45,NA,NA,NA,NA,32,NA,NA,
65,55,NA,NA,NA,NA,NA,NA,
5,1,NA,NA,NA,NA,NA,NA,
NA,8,NA,NA,NA,12,NA,NA,
7,4,NA,NA,NA,NA,NA,NA,
51,NA,NA,NA,NA,NA,NA,32,
76,NA,NA,NA,NA,NA,NA,57,
21,NA,NA,NA,NA,NA,NA,11,
NA,NA,NA,NA,19,NA,NA,40,
NA,NA,NA,NA,0,NA,NA,0,
33,NA,NA,NA,19,NA,8,NA,
24,NA,NA,NA,NA,NA,12,NA,
NA,NA,NA,NA,NA,NA,64,39,
NA,NA,NA,NA,NA,NA,3,12,
NA,NA,NA,NA,30,NA,35,NA,
8,NA,NA,NA,NA,NA,8,NA,
3,NA,NA,NA,NA,NA,0,NA,
NA,NA,NA,2,NA,NA,1,NA,
NA,NA,6,1,NA,NA,NA,NA,
NA,NA,20,7,NA,NA,NA,NA,
21,NA,5,NA,NA,NA,NA,NA,
NA,NA,4,NA,10,NA,NA,NA,
10,NA,1,NA,NA,NA,NA,NA,
14,NA,11,NA,NA,NA,NA,NA,
22,NA,4,NA,NA,NA,NA,NA,
56,NA,30,NA,17,NA,NA,NA,
NA,NA,16,NA,11,NA,NA,NA), .Dim=c(28,8))
n_RCT = structure(.Data=c(146,1,1,1,1,152,1,1,
100,1,1,1,1,100,1,1,
226,224,1,1,1,1,1,1,
29,29,1,1,1,1,1,1,
1,25,1,1,1,30,1,1,
20,20,1,1,1,1,1,1,
121,1,1,1,1,1,1,131,
232,1,1,1,1,1,1,244,
78,1,1,1,1,1,1,78,
1,1,1,1,195,1,1,201,
1,1,1,1,20,1,1,17,
100,1,1,1,100,1,100,1,
74,1,1,1,1,1,76,1,
1,1,1,1,1,1,259,125,
1,1,1,1,1,1,65,64,
1,1,1,1,225,1,225,1,
61,1,1,1,1,1,136,1,
48,1,1,1,1,1,48,1,
1,1,1,34,1,1,32,1,
1,1,95,94,1,1,1,1,
1,1,154,155,1,1,1,1,
54,1,54,1,1,1,1,1,
1,1,66,1,65,1,1,1,
25,1,25,1,1,1,1,1,
38,1,72,1,1,1,1,1,
72,1,138,1,1,1,1,1,
134,1,137,1,131,1,1,1,
1,1,109,1,106,1,1,1), .Dim=c(28,8))
dataR <- list(nS=28, nT=8, ref=2, t=t_RCT, na=na_RCT, r=r_RCT, n=n_RCT)
initR<-list(list(u=rep(0,28), tau=0.5),list(u=rep(0.2,28), tau=0.7))
Params<-c("u","OR")
ModelFit<-jags(data=dataR, inits=initR, Params, n.chains=2,
n.iter=5000, n.burnin=2500, model.file=Model, n.thin=5)
Result<-ModelFit$BUGSoutput$summary
write.table(round(Result,digits=3),
"Results.txt",row.names=T,col.names=T)
DIC<- ModelFit$BUGSoutput$DIC
write.table(round(DIC,digits=3), "Dic.txt",row.names=T,col.names=T)
postscript("PostDen.ps")
ModelFit.mcmc <- as.mcmc(ModelFit)
densplot(ModelFit.mcmc)
dev.off()
謝謝你,M_Fidino,爲你的時間! – user8749191
我也懷疑這一點,從我與其他編程語言的經驗來看,但我確定't'設置正確,因爲當t [i,k] = NA時,這意味着沒有臂研究「我」中的'k'。另外,關於使用對象't'的子集化,我已經在其他人的代碼中以相同的方式看到了它。所以,我仍然感到困惑。 – user8749191
我對你的評論有一個問題,如果我可能的話:整個模型都使用了相同的索引,爲什麼它在那一行中找到了錯誤,而不是在早期的實例中?我會很感激你的承擔。 – user8749191