JAGS中的多级建模:无法解析节点

时间:2016-05-21 10:06:53

标签: r bayesian multi-level jags random-effects

我正在JAGS(JAGS版本3.4.0)中构建多级模型。我想构建不同的斜率变化截距模型。我一直收到错误信息,我不知道问题是什么以及如何处理它。我非常感谢任何帮助!

您可以在此处找到代码的数据:https://www.dropbox.com/s/ibk3nqwc1pm0kpo/Replication_Democratization%20copy.dta?dl=0

以下是代码:

UIButton

运行此代码后,我不断收到此错误消息

    library(rjags)
    load.module("glm")
    load.module("lecuyer")
    attach(soestData)

    yearDummies = model.matrix(~factor(year))
    X0  <- data.frame(1, "Population" = lag(logpwt_pop2,2), "log GDP" = lag(logGdp,2), "logTrade" = lag(logTrade,2), 
              "Civil War" = lag(civilwar,2), "FDI" = lag(wdi_fdi,2), "West Trade" = lag(westTrade,2),
              "Protest" = lag(protest,2), "Oil" = lag(oilmil,2), yearDummies)

    cat('model {
    for (i in 1:n){
       y[i] ~ dnorm (y.hat[i], tau.y)
       y.hat[i] <- inprod(b.0,X.0[i,]) + a[country[i]] + b[country[i]]*x[i] 
     }

     tau.y <- pow(sigma.y, -2) 
     sigma.y ~ dunif (0, 100)
     for (k in 1:K.0){
       b.0[k] ~ dnorm (0, .0001)
     }
     for (j in 1:J){
       a[j] <- xi.a*B.raw[j,1]
       b[j] <- xi.b*B.raw[j,2]
       B.raw[j,1:2] ~ dmnorm (B.raw.hat[j,], Tau.B.raw[,]) 
       B.raw.hat[j,1] <- mu.a.raw
       B.raw.hat[j,2] <- mu.b.raw 
     }       
     mu.a <- xi.a*mu.a.raw
     mu.b <- xi.b*mu.b.raw 
     mu.a.raw ~ dnorm (0, .0001) 
     mu.b.raw ~ dnorm (0, .0001)
     xi.a ~ dunif (0, 100) 
     xi.b ~ dunif (0, 100)
     Tau.B.raw[1:2,1:2] ~ dwish (W[,], df)
     df <- 3
     Sigma.B.raw[1:2,1:2] <- inverse(Tau.B.raw[,]) 
     sigma.a <- xi.a*sqrt(Sigma.B.raw[1,1]) 
     sigma.b <- xi.b*sqrt(Sigma.B.raw[2,2])
     rho <- Sigma.B.raw[1,2]/sqrt(Sigma.B.raw[1,1]*Sigma.B.raw[2,2]) }
       ',file={t <- tempfile()})



   W <- diag (2)
   data <- list("y"=delta2ifhpol,
         "x"=lag(dm_sancgoal,2),
         "X.0" = X0,
         "country"=cname,
         "n"=nrow(soestData),
         "J"=length(unique(cname)),
         "K.0" = ncol(X0),
         "W" = W )

        # inits
       random.no <- round(runif(3,0,1000),0)
       inits <- list( 
       list(".RNG.name"="lecuyer::RngStream", ".RNG.seed"=random.no[1]),
       list(".RNG.name"="lecuyer::RngStream", ".RNG.seed"=random.no[2]),
       list(".RNG.name"="lecuyer::RngStream", ".RNG.seed"=random.no[3]) )

      parameters.to.save <-c ("b.0", "a", "b", "mu.a", "mu.b", "sigma.y", "sigma.a","sigma.b", "rho")
      jags <- jags.model(t.easy, # temporary file
               data=data.easy,
               inits=inits,
               n.chain=3 )

我不知道这是什么问题。我指定了每个参数和每个参数,但它不起作用。我删除了所有NA,但它没有用......我不知道出了什么问题。

有什么想法吗?

0 个答案:

没有答案