晶格问题:晶格对象来自 JAGS,但无法设置设备

发布于 2024-08-09 02:13:42 字数 345 浏览 8 评论 0原文

我在 R 中使用 runjags 运行了 JAGS,并得到了一个巨大的列表(本例的命名结果)。

每当我访问结果$密度时,默认石英设备中都会弹出两个点阵图(每个参数一个)。

我需要将它们与 par(mfrow=c(2, 1)) 或类似的方法结合起来,并将它们发送到 pdf 设备

我尝试过的一切都不起作用。有什么想法吗?

我尝试过 dev.printpdf()dev.off() 等,但没有成功。

I ran JAGS with runjags in R and I got a giant list back (named results for this example).

Whenever I access results$density, two lattice plots (one for each parameter) pop up in the default quartz device.

I need to combine these with par(mfrow=c(2, 1)) or with a similar approach, and send them to the pdf device.

Nothing I tried is working. Any ideas?

I've tried dev.print, pdf() with dev.off(), etc. with no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼波传意 2024-08-16 02:13:42

以下是通过操纵网格结构来放弃“V1”面板的方法:

p1 <- results$density$c
p2 <- results$density$m

p1$layout <- c(1,1)
p1$index.cond[[1]] <- 1   # remove second index
p1$condlevels[[1]] <- "c"   # remove "V1"
class(p1) <- "trellis"   # overwrite class "plotindpages"

p2$layout <- c(1,1)
p2$index.cond[[1]] <- 1   # remove second index
p2$condlevels[[1]] <- "m"   # remove "V1"
class(p2) <- "trellis"   # overwrite class "plotindpages"

library(grid)
layout <- grid.layout(2, 1, heights=unit(c(1, 1), c("null", "null")))
grid.newpage()
pushViewport(viewport(layout=layout))
pushViewport(viewport(layout.pos.row=1))
print(p1, newpage=FALSE)
popViewport()
pushViewport(viewport(layout.pos.row=2))
print(p2, newpage=FALSE)
popViewport()
popViewport()

pot of c .trellis() 结果 http://img142.imageshack.us/img142/3272/ctrellisa.png

Here's a way to ditch the "V1" panels by manipulation of the Trellis structure:

p1 <- results$density$c
p2 <- results$density$m

p1$layout <- c(1,1)
p1$index.cond[[1]] <- 1   # remove second index
p1$condlevels[[1]] <- "c"   # remove "V1"
class(p1) <- "trellis"   # overwrite class "plotindpages"

p2$layout <- c(1,1)
p2$index.cond[[1]] <- 1   # remove second index
p2$condlevels[[1]] <- "m"   # remove "V1"
class(p2) <- "trellis"   # overwrite class "plotindpages"

library(grid)
layout <- grid.layout(2, 1, heights=unit(c(1, 1), c("null", "null")))
grid.newpage()
pushViewport(viewport(layout=layout))
pushViewport(viewport(layout.pos.row=1))
print(p1, newpage=FALSE)
popViewport()
pushViewport(viewport(layout.pos.row=2))
print(p2, newpage=FALSE)
popViewport()
popViewport()

pot of c.trellis() result http://img142.imageshack.us/img142/3272/ctrellisa.png

兲鉂ぱ嘚淚 2024-08-16 02:13:42

组合图的最简单方法是使用 results$mcmc 中存储的结果:

# prepare data, see source code of "run.jags"
thinned.mcmc <- combine.mcmc(list(results$mcmc),
                             collapse.chains=FALSE,
                             return.samples=1000)
print(densityplot(thinned.mcmc[,c(1,2)], layout=c(1,2),
                  ylab="Density", xlab="Value"))

The easiest way to combine the plots is to use the results stored in results$mcmc:

# prepare data, see source code of "run.jags"
thinned.mcmc <- combine.mcmc(list(results$mcmc),
                             collapse.chains=FALSE,
                             return.samples=1000)
print(densityplot(thinned.mcmc[,c(1,2)], layout=c(1,2),
                  ylab="Density", xlab="Value"))
对不⑦ 2024-08-16 02:13:42

例如,对于 run.jags 中包含的示例,使用检查列表的结构

sink("results_str.txt")
str(results$density)
sink()

然后您将看到名为 layout 的组件。每个变量的两个图的布局可以使用设置。

results$density$m$layout <- c(1,2)
print(results$density$m)

不同参数的图可以使用latticeExtra包中的c.trellis方法组合。

class(results$density$m) <- "trellis"   # overwrite class "plotindpages"
class(results$density$c) <- "trellis"   # overwrite class "plotindpages"
library("latticeExtra")
update(c(results$density$m, results$density$c), layout=c(2,2))

c.trellis 的输出 http://img88.imageshack.us/img88/6481/ctrellis .png

另一种方法是使用 grid 视口:

library("grid")
results$density$m$layout <- c(2,1)
results$density$c$layout <- c(2,1)
class(results$density$m) <- "trellis"
class(results$density$c) <- "trellis"
layout <- grid.layout(2, 1, heights=unit(c(1, 1), c("null", "null")))
grid.newpage()
pushViewport(viewport(layout=layout))
pushViewport(viewport(layout.pos.row=1))
print(results$density$m, newpage=FALSE)
popViewport()
pushViewport(viewport(layout.pos.row=2))
print(results$density$c, newpage=FALSE)
popViewport()
popViewport()

网格输出http://img88.imageshack.us/img88/5967/grida.png

For instance, for the included example from run.jags, check the structure of the list using

sink("results_str.txt")
str(results$density)
sink()

Then you will see components named layout. The layout for the two plots of each variable can be set using

results$density$m$layout <- c(1,2)
print(results$density$m)

The plots for different parameters can be combined using the c.trellis method from the latticeExtra package.

class(results$density$m) <- "trellis"   # overwrite class "plotindpages"
class(results$density$c) <- "trellis"   # overwrite class "plotindpages"
library("latticeExtra")
update(c(results$density$m, results$density$c), layout=c(2,2))

output of c.trellis http://img88.imageshack.us/img88/6481/ctrellis.png

Another approach is to use grid viewports:

library("grid")
results$density$m$layout <- c(2,1)
results$density$c$layout <- c(2,1)
class(results$density$m) <- "trellis"
class(results$density$c) <- "trellis"
layout <- grid.layout(2, 1, heights=unit(c(1, 1), c("null", "null")))
grid.newpage()
pushViewport(viewport(layout=layout))
pushViewport(viewport(layout.pos.row=1))
print(results$density$m, newpage=FALSE)
popViewport()
pushViewport(viewport(layout.pos.row=2))
print(results$density$c, newpage=FALSE)
popViewport()
popViewport()

grid output http://img88.imageshack.us/img88/5967/grida.png

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文