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

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

有人可以详细解释这段代码是如何工作的吗?

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

例如,在哪一部分指定先验和后验?

我在此处给出的答案中找到了代码 How to plot Bayesian prior and posterior distributions in one panel using R?

该答案仅说明如何在同一图中绘制两条曲线,但根本不涉及在给定先验和数据的情况下计算真实后验。也就是说,它只绘制了两个具有 shape=0.1shape=0.2 的 Gamma 分布,并且在数据框中通过包含一个因子列 param 来区分它们,其中 "s.1.01""s.2.01" 表示各自的分布。