全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
18558 124
2012-11-20
在运行时出现:expected key word structure问题
display(log)
check(C:/Users/lenovo/AppData/Local/Temp/Rtmpoz2apD/gaoxueya.bug.txt)
model is syntactically correct
data(C:/Users/lenovo/AppData/Local/Temp/Rtmpoz2apD/data.txt)
expected key word structure
compile(1)
inits(1,C:/Users/lenovo/AppData/Local/Temp/Rtmpoz2apD/inits1.txt)
command #Bugs:inits cannot be executed (is greyed out)
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(1)
update(1)
command #Bugs:update cannot be executed (is greyed out)
set(a1)
command #Bugs:set cannot be executed (is greyed out)
set(a2)
command #Bugs:set cannot be executed (is greyed out)
set(a3)
command #Bugs:set cannot be executed (is greyed out)
set(a4)
command #Bugs:set cannot be executed (is greyed out)
set(intdrop)
command #Bugs:set cannot be executed (is greyed out)
set(beta1drop)
command #Bugs:set cannot be executed (is greyed out)
set(beta2drop)
command #Bugs:set cannot be executed (is greyed out)
set(beta3drop)
command #Bugs:set cannot be executed (is greyed out)
set(intlast)
command #Bugs:set cannot be executed (is greyed out)
set(beta1last)
command #Bugs:set cannot be executed (is greyed out)
set(beta2last)
command #Bugs:set cannot be executed (is greyed out)
set(beta3last)
command #Bugs:set cannot be executed (is greyed out)
set(sexlast)
command #Bugs:set cannot be executed (is greyed out)
set(agelast)
command #Bugs:set cannot be executed (is greyed out)
set(smokelast)
command #Bugs:set cannot be executed (is greyed out)
set(bmilast)
command #Bugs:set cannot be executed (is greyed out)
set(d1)
command #Bugs:set cannot be executed (is greyed out)
set(d2)
command #Bugs:set cannot be executed (is greyed out)
set(d3)
command #Bugs:set cannot be executed (is greyed out)
set(d4)
command #Bugs:set cannot be executed (is greyed out)
set(taud1)
command #Bugs:set cannot be executed (is greyed out)
set(taud2)
command #Bugs:set cannot be executed (is greyed out)
set(taud3)
command #Bugs:set cannot be executed (is greyed out)
set(taud4)
command #Bugs:set cannot be executed (is greyed out)
set(deviance)
command #Bugs:set cannot be executed (is greyed out)
dic.set()
command #Bugs:dic.set cannot be executed (is greyed out)
update(9)
command #Bugs:update cannot be executed (is greyed out)
coda(*,C:/Users/lenovo/AppData/Local/Temp/Rtmpoz2apD/coda)
command #Bugs:coda cannot be executed (is greyed out)
stats(*)
command #Bugs:stats cannot be executed (is greyed out)
dic.stats()

DIC
history(*,C:/Users/lenovo/AppData/Local/Temp/Rtmpoz2apD/history.odc)
command #Bugs:history cannot be executed (is greyed out)
save(C:/Users/lenovo/AppData/Local/Temp/Rtmpoz2apD/log.odc)
save(C:/Users/lenovo/AppData/Local/Temp/Rtmpoz2apD/log.txt)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-11-20 22:39:06
答复你的留言:
数据读入时产生错误
方便的话上传你的程序及数据
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-21 09:42:41
epoh 发表于 2012-11-20 22:39
答复你的留言:
数据读入时产生错误
方便的话上传你的程序及数据
response<-read.spss("E:/1.sav")
y<-response$y
t<-response$t
sub<-response$id3
cov<-read.spss("E:/2.sav")
sex<-cov$SEX
age<-cov$AGE
BZ<-cbind(cov$q1,cov$q2,cov$q3)
U<-cov$u/1000
nobs<-cov$nobs
n<-length(nobs)
knotD<-quantile(unique(U),seq(0,1,length=(9+2))[-c(1,(9+2))])
OMEGA_all<-(abs(outer(knotD,knotD,"-")))^3

data<-list("y","t","Nobs","sub","sex","age",)

ytsexageq1q2 q3unobs    i3
03412786889451          1
15613347898451          2  
.5621896796652          3
14511968978532          4

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-21 16:34:17
文雅13 发表于 2012-11-21 09:42
response
问题不难,
可惜没有你的数据及bug code,不易正确指出错误所在,
若有不便,数据你可以随便给,但bug code及script要正确
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-21 17:02:43
epoh 发表于 2012-11-21 16:34
问题不难,
可惜没有你的数据及bug code,不易正确指出错误所在,
若有不便,数据你可以随便给,但bug code及 ...
model{
   
    for (i in 1:n1)
     {
         
                y[i,1]~dbern(p[i,1])
                logit(p[i,1])<-etaM[i,1]
                etaM[i,1]<-beta0all+beta1all*t[(sumn-nobs+1)]}
   
     
     for (i in (n1+1):n)
     {
               y[i,1]~dbern(p[i,1])
               logit(p[i,1])<-etaM[i,1]
               etaM[i,1]<-beta0all+beta1all*t[(sumn-nobs+1)]
   
         
          for (j in 2:nobs)
           {
                 y[i,j]~dbern(p[i,j])
                 logit(p[i,j])<-delta[i,j]+gamma[i,j]*y[i,j-1]
                 etaM[i,j]<-beta0all+beta1all*t[(sumn-nobs+j)]
         
                 # MTM1Delta is a function written in the WinBUGS development
                 # interface for computing the intercept delta[i,j] to satisfy
                 # marginal mean and serial dependence simultaneously
                 delta[i,j]<-MTM1Delta(etaM[i,j],etaM[i,j-1],gamma[i,j])
                 gamma[i,j]<-cor                                    }}
   
   
     for (i in 1:n)
            {
               # intercept, race and baseline CD4 effects
               beta0all<-int+beta1*equals(race,2)
                           +beta2[1]*equals(race,3)+beta3*cd4
               int<-intdrop*step(11-nobs)+intlast*equals(nobs,12)
               beta1<-beta1drop*step(11-nobs)+beta1last*equals(nobs,12)
               beta2<-beta2drop*step(11-nobs)+beta2last*equals(nobs,12)
               
               beta3<-(a1[1]+a1[2]*U+inprod2(d1[1:9],BZ[i,1:9]))
                         *step(11-nobs)+beta3last*equals(nobs,12)
              
               # time slopes by CD4 groups
               cd4g<-cd4+1 #baseline CD4 group indicator
               
               beta1all<-(a2[cd4g,1]+a2[cd4g,2]*U
                          +inprod2(d2[cd4g,1:9],BZ[i,1:9]))
                          *step(11-nobs)+beta1alllast[cd4g]
                          *equals(nobs,12)
              
               # serial dependence
               cor<-(a3[1]+a3[2]*U+inprod2(d3[1:9],BZ[i,1:9]))
                      *step(11-nobs)+corrlast*equals(nobs,12)
             }
   
    # Priors for intercept, race effects in the dropout group
         intdrop~dnorm(0,1.0E-3)
         beta1drop~dnorm(0,1.0E-3)
         beta2drop~dnorm(0,1.0E-3)
   
    # Priors for parameters in the administrative censoring group
         intlast~dnorm(0,1.0E-3)
         beta1last~dnorm(0,1.0E-3)
         beta2last~dnorm(0,1.0E-3)
         beta3last~dnorm(0,1.0E-3)
         for(j in 1:2){beta1alllast[j]~dnorm(0,1.0E-3)}
         corrlast~dnorm(0,1.0E-3)
         interactionlast<-beta1alllast[2]-beta1alllast[1]
   
    # Priors for d0, d1, d2, d3 (random effects)
           for (k in 1:9)
               {
                  d1[k]~dnorm(0,taud1)
                  for(j in 1:2){d2[j,k]~dnorm(0,taud2[j])}
                  d3[k]~dnorm(0,taud3)
                }
     # Priors for a0, a1,a2, a3 (fixed effects)
           for (k in 1:2)
              {
                  a1[k]~dnorm(0,1.0E-3)
                  for(j in 1:2){a2[j,k]~dnorm(0,1.0E-3)}
                  a3[k]~dnorm(0,1.0E-3)
               }
     
     # Priors for the smoothing parameters
                   taud1~dgamma(1.0E-2,1.0E-2)
                   for(j in 1:2){taud2[j]~dgamma(1.0E-2,1.0E-2)}
                   taud3~dgamma(1.0E-2,1.0E-2)
      # smooth function estimates of regression coefficients
      # on 106 grid points in the range of the observed dropout times
      for (i in 1:106)
             {
               v<-(i-1)*0.02
              
               # Mv is a function written in the WinBUGS development
               # interface for computing smooth function estimates
               # with low-rank thin-plate bases
               betacd4<-Mv(a1[1:2], d1[1:9], knotD[],OMEGAu[],v)
               betac0<-Mv(a2[1,1:2], d2[1,1:9], knotD[],OMEGAu[],v)
               betac1<-Mv(a2[2,1:2], d2[2,1:9], knotD[],OMEGAu[],v)
               interaction<-betac1-betac0
               corr<-Mv(a3[1:2], d3[1:9], knotD[],OMEGAu[],v)
              }
      
       #generate posterior probability for the dropout/adminstrative
       #censoring times within the race and baseline CD4 groups
       for (i in 1:n)
              { del~dgamma(1,1)}
      
       for (k in 1:6)
        {
            for (i in nn1[k]:nn2[k])
             {pp<-del/(sum(del[nn1[k]:nn2[k]])+sum(del[nn3[k]:nn4[k]]))
             }
             for (i in nn3[k]:nn4[k])
             {pp<-del/(sum(del[nn1[k]:nn2[k]])+sum(del[nn3[k]:nn4[k]]))
              }
        }
      
        # compute marginal probability estimates averaging over
        # Bayesian bootstrap samples, on 106 grid time points
        for (j in 1:106)
        {
                vv[j]<-(j-1)*0.02
               
                for (i in 1:n)
                {
                  margin[i,j]<-pp*(exp(beta0all+beta1all*vv[j])
                              /(1+exp(beta0all+beta1all*vv[j])))
                 }
                  
                  # cd4<=200, race=latina&other
                    mean0[j]<-(sum(margin[nn1[1]:nn2[1],j])
                                   +sum(margin[nn3[1]:nn4[1],j]))
                  # cd4<=200, race=black
                  mean1[j]<-(sum(margin[nn1[2]:nn2[2],j])
                                 +sum(margin[nn3[2]:nn4[2],j]))
                  # cd4<=200, race=white
                  mean2[j]<-(sum(margin[nn1[3]:nn2[3],j])
                                 +sum(margin[nn3[3]:nn4[3],j]))
          }#end model
数据格式大致就是下面这样的
id 时间 y age sex
1 1 0 1 1
1 2 0 3 2
1 3 1 3 2
2 1 1 3 2
2 2 .
2 3 1 2 2
3 1 0 2 1

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-21 19:02:50
文雅13 发表于 2012-11-21 17:02
model{
   
    for (i in 1:n1)
你的winbugs code 就是来自
WinBUGS program for the binary CES-D HERS data

请仔细看,你少给了太多数据.

the binary outcome variable (y[,]),
the time since enrollment (t[]),
the race group indicator (race[]),
the indicator of baseline CD4 > 200 (cd4[]),
the observed dropout time (U[]),
and the design matrix of the random effects (BZ[,]) for penalized splines,
the sample size (n),
the number of individuals with only one observation (n1),
the number of observations within individuals (nobs[]),
...
...
而你给的"sub","sex","age",winbugs code 中根本没有
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群