始める無料で始める

事後予測分布

weight_chains データフレーム(ワークスペース内)には、身長180cmの成人の体重に対する100,000個の事後予測値 Y_180 が含まれています。

> head(weight_chains, 2)
          a        b        s iter    m_180    Y_180
1 -113.9029 1.072505 8.772007    1 79.14803 71.65811
2 -115.0644 1.077914 8.986393    2 78.96014 75.78893

これらの100,000個の予測値を使って、身長180cmの成人の体重に対する事後予測分布を近似します。bdims データはワークスペースに読み込まれています。

この演習はコースの一部です

RJAGS によるベイズモデリング

コースを見る

演習の手順

  • 10,000個の Y_180 の値を使って、身長180cmの成人の体重に対する95%事後信用区間を求めましょう。
  • 100,000個の事後予測値の密度プロットを作成しましょう。
  • bdimswgthgt の散布図を作成しましょう。
    • geom_abline() を使って、事後回帰トレンドを重ねて表示します。
    • geom_segment() を使って、hgt が180の位置に縦線を重ねて表示し、ci_180 の下限と上限(yyend)を示します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Construct a posterior credible interval for the prediction
ci_180 <- quantile(___, probs = c(___, ___))
ci_180

# Construct a density plot of the posterior predictions
ggplot(___, aes(x = ___)) + 
    geom_density() + 
    geom_vline(xintercept = ci_180, color = "red")

# Visualize the credible interval on a scatterplot of the data
ggplot(___, aes(x = ___, y = ___)) + 
    geom_point() + 
    geom_abline(intercept = mean(___), slope = mean(___), color = "red") + 
    geom_segment(x = 180, xend = 180, y = ___, yend = ___, color = "red")
コードを編集して実行