将模型改为使用信息量先验
当前显示的代码是您在第 2 章从零开始构建的旧模型。
本练习是课程的一部分
R 中的贝叶斯数据分析基础
练习说明
- 请将此模型改为使用您刚刚选定的
proportion_clicks信息量先验:
rbeta(n_draws, shape1 = 5, shape2 = 95)
交互式实操练习
通过完成这段示例代码来试试这个练习。
n_draws <- 100000
n_ads_shown <- 100
# Change the prior on proportion_clicks
proportion_clicks <-
runif(n_draws, min = 0.0, max = 0.2)
n_visitors <-
rbinom(n_draws, size = n_ads_shown,
prob = proportion_clicks)
prior <-
data.frame(proportion_clicks, n_visitors)
posterior <-
prior[prior$n_visitors == 13, ]
# This plots the prior and the posterior in the same plot
par(mfcol = c(2, 1))
hist(prior$proportion_clicks,
xlim = c(0, 0.25))
hist(posterior$proportion_clicks,
xlim = c(0, 0.25))