runjags 的大型监视器列表

Large Monitor List for runjags

使用 运行jags,我试图监视大量值。监视器列表的格式是一串值,在这种情况下,我只要求监视 3, Y[14], Y[15], Y[3].

run.jags(model="model.MC.txt",data=list(Y=Y.NA.Rep,sizes=sizesB,cumul=cumul),
                monitor=c("thetaj", "Y[14]", "Y[15]","Y[3]"))

假设我想监控数百个值。我可以创建这个字符串,但它只是 returns 到提示符“+”。并且未能 运行.

对于可以创建并作为参数传入的字符串的大小是否有一些上限?

是否有更好的方法(非字符串)将此列表传递给 run.jags?

我能够将其添加到 运行 的唯一方法是粘贴字符串文字 在函数调用中,包含字符串的变量不起作用。

较长的 运行 列表如下所示:

run.jags(model="model.MC.txt",data=list(Y=Y.NA.Rep,sizes=sizesB,cumul=cumul)
,monitor=c('Y[14]',   'Y[15]',   'Y[18]',   'Y[26]',   'Y[41]',   
'Y[55]',   'Y[62]',   'Y[72]',   'Y[80]',   'Y[81]',   'Y[128]',   'Y[138]',   
'Y[180]',   'Y[188]',   'Y[191]',   'Y[209]',   'Y[224]',   'Y[244]',   ' 
'Y[255]',   'Y[263]',   'Y[282]',   'Y[292]',   'Y[303]',   'Y[324]',   
'Y[349]',   'Y[358]',   'Y[359]',   'Y[365]',   'Y[384]',   

...删除多行

'Y[1882]',   'Y[1895]',   'Y[1899]',   'Y[1903]',   'Y[1918]',   'Y[1922]',   
'Y[1929]',   'Y[1942]',   'Y[1953]',   'Y[1990]'))

我不确定这是不是 runjags 的问题 - 以下代码有 1002 个监视器并且运行正常:

model <- "model {
for(i in 1 : N){ #data# N
    Y[i] ~ dnorm(true.y[i], precision) #data# Y
    true.y[i] <- (m * X[i]) + c #data# X
}
m ~ dnorm(0, 10^-3)
c ~ dnorm(0, 10^-3)
precision ~ dgamma(10^-3, 10^-3)
}"

X <- 1:1000
Y <- rnorm(length(X), 2*X + 10, 1)
N <- length(X)

monitors <- c('m','c',paste0('Y[',1:1000,']'))


results <- run.jags(model, n.chains=2, monitor=monitors, sample=100, method='rjags')
results <- run.jags(model, n.chains=2, monitor=monitors, sample=100, method='inter')

我还尝试使用以下方法将字符串直接写入函数调用:

cat('monitor = c("'); cat(monitors, sep='", "'); cat('")\n')

...和 ​​copy/pasting 生成的文本作为监视器参数 - 在 R.app 中仍然对我有用,但是当粘贴到 RStudio 中时,我得到:

> results <- run.jags(model, n.chains=2, monitor = c("m", "c", "Y[1]", "Y[2]", "Y[3]", "Y[4]", "Y[5]", "Y[6]", "Y[7]", "Y[8]", "Y[9]", "Y[10]", "Y[11]", "Y[12]", "Y[13]", "Y[14]", "Y[15]", "Y[16]", "Y[17]", "Y[18]", "Y[19]", "Y[20]", "Y[21]", "Y[22]", "Y[23]", "Y[24]", "Y[25]", "Y[26]", "Y[27]", "Y[28]", "Y[29]", "Y[30]", "Y[31]", "Y[32]", "Y[33]", "Y[34]", "Y[35]", "Y[36]", "Y[37]", "Y[38]", "Y[39]", "Y[40]", "Y[41]", "Y[42]", "Y[43]", "Y[44]", "Y[45]", "Y[46]", "Y[47]", "Y[48]", "Y[49]", "Y[50]", "Y[51]", "Y[52]", "Y[53]", "Y[54]", "Y[55]", "Y[56]", "Y[57]", "Y[58]", "Y[59]", "Y[60]", "Y[61]", "Y[62]", "Y[63]", "Y[64]", "Y[65]", "Y[66]", "Y[67]", "Y[68]", "Y[69]", "Y[70]", "Y[71]", "Y[72]", "Y[73]", "Y[74]", "Y[75]", "Y[76]", "Y[77]", "Y[78]", "Y[79]", "Y[80]", "Y[81]", "Y[82]", "Y[83]", "Y[84]", "Y[85]", "Y[86]", "Y[87]", "Y[88]", "Y[89]", "Y[90]", "Y[91]", "Y[92]", "Y[93]", "Y[94]", "Y[95]", "Y[96]", "Y[97]", "Y[98]", "Y[99]", "Y[100]", "Y[101]", "Y[102]", "Y[103]", "Y[104]", "Y[105]... <truncated>
+                                                    
+ 

与您的描述有些相似。所以我猜你正在使用 RStudio,问题是 RStudio 可以解释的代码行的最大长度。

如果是这样,修复方法是简单地硬包装命令,以便将其分成多行 - 我尝试使用 72 个字符宽度(100 多行),它在 RStudio 中运行良好。如果我的假设不正确,请修改您的问题以提供更多关于您 运行 R 和您的系统使用的详细信息:

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] runjags_2.0.4-2

loaded via a namespace (and not attached):
[1] compiler_3.4.0  tools_3.4.0     parallel_3.4.0  coda_0.19-1     grid_3.4.0      rjags_4-6       lattice_0.20-35