简体   繁体   English

使用R在一个面板中绘制贝叶斯先验和后验分布的解释

[英]Explanation of plotting Bayesian prior and posterior distributions in one panel using R

Could someone explain with details how this code is working? 有人可以详细解释此代码如何工作吗?

require(lattice)
?lattice  # essential reading

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

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")

For instance, In which part is specificating the prior and posterior? 例如,在哪个部分指定先验和后验?

I've found the code in the answer given here How to plot Bayesian prior and posterior distributions in one panel using R? 我在这里给出的答案中找到了代码。 如何使用R在一个面板中绘制贝叶斯先验和后验分布?

That answer only illustrates how to plot two curves in the same plot, but does not at all involve computing a true posterior given a prior and data. 该答案仅说明了如何在同一图中绘制两条曲线,但根本不涉及计算给定先验和数据的真实后验。 Namely, it just plots two Gamma distributions with shape=0.1 and shape=0.2 , and these are distinguished in the data frame by including a factor column param where "s.1.01" and "s.2.01" indicate the respective distributions. 即,它仅绘制了两个shape=0.1shape=0.2 Gamma分布,并且在数据帧中通过包括因子列param来区分它们,其中"s.1.01""s.2.01"表示各自的分布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM