Normal-Normal 先驗
研究人員設計了一個測驗,用來評估睡眠剝奪對反應時間的影響。對於受試者 $i$,令 \(Y\)i 為在經過 3 個晚上的睡眠剝奪後,反應時間(毫秒) 的「變化量」。當然,每個人對睡眠剝奪的反應不同。合理的假設是,\(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 = ___)) +
___()