本文介绍了如何使用R在一个面板中绘制贝叶斯先验和后验分布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了几种方法,包括qqmathlattice densityplot()和许多面板功能,例如panel.mathdensitypanel.densityplot.但是,我无法让他们去做我想要他们去做的事情.

I've tried several approaches, including qqmath, lattice densityplot() and a number of panel functions like panel.mathdensity and panel.densityplot. However, I couldn't get them to do what I want them to do.

有关此主题的互联网搜索产生的结果要么集中于R中的基本图,要么不绘制同一面板中的两个分布.我可以使用R基本图形,但是,我还想绘制几个分布对,并为每个对绘制一个面板.

An internet search on this topic produces results which focus either on base plots in R or don't draw both distributions in one panel. I could use R base graphics, however, I also want to plot several distribution pairs and one panel for each pair.

"RGraphics"和"Lattice:使用R进行多元数据可视化"这两个书也无法启发我.

The books "RGraphics" and "Lattice: Multivariate Data Visualization with R" couldn't enlighten me in this area either.

数据通常看起来像这样:

The data usually looks something like this:

data <- dgamma(seq(from=0.00001,to=0.01,by=0.00001),shape = .1, scale = .01)

我对latticeggplot软件包都持开放态度,尽管我对使用lattice有更多的经验.

I'm open to either lattice or ggplot package, although I have more experience using lattice.

如果您需要更多信息来帮助我,请告诉我.

Please let me know if you need any more information to help me out here.

推荐答案

您仅给出了一个数据对象,但要求构造两个数据对象,因此我将尝试使用相同分布的两个项目使用不同的参数.当使用lattice或ggplot2时,需要构造适当排列的数据帧,通常是数据的长"格式. "group"参数指定在同一面板中以不同颜色绘制的图形.

You have only given one data-object but are asking for two to be constructed, so I'll try for two items of the same distribution with different parameters. When working with lattice or ggplot2 one need to construct a dataframe of the proper arrangement which is usually a "long" format for the data. The "group" parameter specifies plotting in the same panel with different colors.

require(lattice)
?lattice  # essential reading
dfrm <- data.frame(dgam = data, param="s.1.01")
dfrm <- rbind(dfrm, data.frame(dgam =
                                 dgamma( seq(from=0.00001,to=0.01,by=0.00001), 
                                 shape = .2, scale = .01), 
                               param="s.2.01") )
dfrm <- cbind( dfrm, X.val=seq(from=0.00001,to=0.01,by=0.00001) )
str(dfrm)
#'data.frame':  2000 obs. of  3 variables:
# $ dgam : num  5263 2817 1954 1507 1231 ...
# $ param: Factor w/ 2 levels "s.1.01","s.2.01": 1 1 1 1 1 1 1 1 1 1 ...
# $ X.val: num  1e-05 2e-05 3e-05 4e-05 5e-05 6e-05 7e-05 8e-05 9e-05 1e-04 ...
xyplot( dgam ~ X.val , 
        group=param, 
        data=dfrm, type="l")

这篇关于如何使用R在一个面板中绘制贝叶斯先验和后验分布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 14:39