jags
我正在使用R2jags 包(它使用 rjags 包来运行 JAGS)的功能在 R 中运行大量 JAGS 模型。
我在控制台中打印了很多警告:
value out of range in 'lgamma'
打印这些警告似乎会严重影响计算时间。我该如何抑制这个?
警告被打印为输出,而不是 R 警告。
我尝试过但不起作用的事情包括:
try(..., silent = TRUE)
用,suppressWarnings
,invisible
或包裹我的电话capture.output
。jags.model
将呼叫更改jags
为jags.model(..., quiet = TRUE)
。
这种现象在其他地方也有提及 ,我只是想将其关闭以减少从大量不必要的打印到控制台的计算负载。
有什么建议么?
这是基于sourceforge 上相同问题的示例的长但可重复的示例。很抱歉这篇文章的长度,但我无法在任何较小的玩具模型中复制它。我不太关心这个特定的模型,但它合理地简单地复制了这个问题:
模型
cat('
model {
K <- 1.1
K.mvhypgeom <- exp( logfact(sum(n[])) - logfact(nMissing) - logfact( sum(n[]) - nMissing))
p ~ dunif(0,1)
for (t in 1:N) {
X.missing[t] ~ dpois( missRate )
}
nMissing ~ dsum(X.missing[1],X.missing[2],X.missing[3],X.missing[4],X.missing[5],X.missing[6],X.missing[7],X.missing[8],X.missing[9],X.missing[10])
for (t in 1:N) {
pX.missing[t] <- exp(logfact(n[t]) - logfact( X.missing[t]) - logfact( n[t] - X.missing[t]))
ones2[t] ~ dbern(pX.missing[t]/K.mvhypgeom)
}
for (t in 1:N) {
X[t] <- X.obs[t] + X.missing[t]
likX[t] <- dbin( X[t], p, n[t])
ones1[t] ~ dbern( likX[t] / K)
}
}
',
file = {example.model <- tempfile()},
sep = ''
)
数据
simBinTS <- function(n, p , nMissing) {
X.full <- X <- rbinom(N, size = n, prob = p)
for (i in seq_len(nMissing)) {
idx <- sample(1:N, size = 1, prob = X)
X[idx] <- X[idx] - 1
}
return(data.frame(n = n, X = X, X.full = X.full))
}
N <- 10
p <- 0.3
set.seed(123)
n <- rpois(N, lambda = 30)
nMissing <- 10
missRate <- 1/10
ts <- simBinTS(p = p, n = n, nMissing = nMissing)
X.obs <- ts$X
n <- ts$n
X.full <- ts$X.full
ones1 <- rep(1,N)
ones2 <- rep(1,N)
jags.inits <- function(){
list(X.missing = X.full-X.obs)
}
称呼
library("R2jags")
jags(data = list("X.obs", "n", "N", "nMissing", "ones1", "ones2", "missRate"),
inits = jags.inits,
parameters.to.save = "p",
model.file = example.model,
n.chains = 3,
n.iter = 1000,
n.burnin = 500,
n.thin = 1,
progress.bar = "none")
输出 (大量重复的警告被修剪 - 这些再次打印为函数输出而不是警告消息)
value out of range in 'lgamma'
value out of range in 'lgamma'
value out of range in 'lgamma'
value out of range in 'lgamma'
value out of range in 'lgamma'
value out of range in 'lgamma'
Inference for Bugs model at "D:\Users\fish\AppData\Local\Temp\RtmpWufTIC\file1614244456e1", fit using jags,
3 chains, each with 1000 iterations (first 500 discarded)
n.sims = 1500 iterations saved
mu.vect sd.vect 2.5% 25% 50% 75% 97.5% Rhat
p 0.331 0.027 0.280 0.312 0.330 0.348 0.388 1.006
deviance 812.379 2.761 808.165 810.345 811.941 814.103 818.729 1.007
n.eff
p 1300
deviance 670
For each parameter, n.eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor (at convergence, Rhat=1).
DIC info (using the rule, pD = var(deviance)/2)
pD = 3.8 and DIC = 816.2
DIC is an estimate of expected predictive error (lower deviance is better).