ベイズモデルをプロットする
これまでの演習では、曲の人気度(popularity)を曲の経過年数(song_age)から予測するベイズモデルを推定しました。ここでは、そのモデルを可視化します。すでに読み込まれている songs データセットと stan_model オブジェクトを使い、推定された回帰直線とデータを ggplot2 で可視化してください。
この演習はコースの一部です
rstanarm で学ぶベイズ回帰モデリング
演習の手順
- モデルパラメータの要約を整形して
tidy_coefに保存します tidy_coefから推定された切片と傾きを取り出します- x 軸に
song_age、y 軸にpopularityをとり、データと推定回帰直線を表示するプロットを作成します
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Save the model parameters
tidy_coef <- ___(stan_model)
# Extract intercept and slope
model_intercept <- tidy_coef$___[1]
model_slope <- tidy_coef$___[2]
# Create the plot
ggplot(songs, aes(x = ___, y = ___)) +
geom_point() +
geom_abline(intercept = ___, slope = ___)