开始使用免费开始使用

Normal-Normal 先验

研究人员设计了一项测试,用于评估睡眠剥夺对反应时间的影响。对受试者 i,令 \(Y\)i 表示连续 3 个睡眠不足夜晚后反应时间的「变化量」(单位:ms)。当然,人们对睡眠剥夺的反应会不同。合理的假设是 \(Y\)i 服从以某个「平均值」 \(m\) 为中心、带有「标准差」 \(s\) 的正态分布:\(Y\)i $\sim N(m, s^2)$。

在贝叶斯分析的第一步,您将模拟参数 \(m\) 和 \(s\) 的以下先验模型:$m \sim N(50, 25^2)$,以及 $s \sim Unif(0, 200)$。这需要使用 rnorm(n, mean, sd)runif(n, min, max) 函数。

本练习是课程的一部分

使用 RJAGS 的贝叶斯建模

查看课程

练习说明

  • 使用 rnorm(n, mean, sd) 从 \(m\) 的先验中抽取 10,000 个样本。将结果赋给 prior_m
  • 使用 runif(n, min, max) 从 \(s\) 的先验中抽取 10,000 个样本。将结果赋给 prior_s
  • 将这些结果存入数据框 samples 后,分别绘制 prior_m 样本的密度图和 prior_s 样本的密度图。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Take 10000 samples from the m prior


# Take 10000 samples from the s prior    


# Store samples in a data frame
samples <- data.frame(prior_m, prior_s)

# Density plots of the prior_m & prior_s samples    
ggplot(___, aes(x = ___)) + 
    ___()
ggplot(___, aes(x = ___)) + 
    ___()
编辑并运行代码