由于带有所有绘图的 runjags 对象太大,我尝试run.jags
使用plot=FALSE
,将结果runjags
对象保存到文件中,在新的 R 会话中恢复它(as out
),然后通过
out.with_summaries <- extend.jags(out, sample = 0, adapt = 0)
(有关此技巧,请参见此处的讨论:https ://stackoverflow.com/a/21859618/684229 )
但是,由于未知原因,这会重新编译并再次调整模型!即使我设置了sample = 0, adapt = 0
!
require(runjags)
t1 <- proc.time()
out.sum <- extend.jags(out, sample = 0, adapt = 0)
# Re-compiling rjags model and adapting...
# Calculating the Gelman-Rubin statistic for 4 variables....
# Convergence may have failed for this run for 4 parameters after 500
# iterations (multi-variate psrf = 214.873)
# Finished running the simulation
t2 <- proc.time()
print(t2 - t1)
# user system elapsed
# 345.67 0.08 352.30
仅绘制图形就需要很长时间,这很烦人。当我用绘图计算 runjags 对象然后尝试摆脱它们以将 runjags 对象存储为小时,也会发生同样的情况:
t1 <- proc.time()
out.no_sum <- extend.jags(out.sum, sample = 0, adapt = 0, summarise=FALSE, plot=FALSE)
# Loading required package: rjags
# Loading required package: coda
# Loading required package: lattice
# Linked to JAGS 3.3.0
# Loaded modules: basemod,bugs
# Re-compiling rjags model and adapting...
# Finished running the simulation
t2 <- proc.time()
print(t2 - t1)
# user system elapsed
# 327.53 0.05 329.73
关于如何解决这个问题的任何提示(除了编写我自己的绘图函数)?
警告:第二次extend.jags
在同一个 runjags 对象上运行该函数已经很快了。但是,如果您保存 runjags 对象并在新会话中再次加载它,则会再次extend.jags
变慢。似乎runjags
JAGS 正在缓存某些东西(但不在原始 runjags 对象中)。