調整鏈(chains)
來練習更改鏈的數量與長度,以取得不同規模的後驗分佈。透過改變後驗的大小,你可以改變用於後驗摘要的樣本數,並影響估計所需時間。songs 資料已經載入。
本練習屬於課程
使用 rstanarm 的貝葉斯迴歸建模
練習說明
- 在所有模型中,以
song_age預測popularity。 - 估計一個有 3 條鏈的模型;每條鏈 1000 次迭代,前 500 次捨棄。
- 估計一個有 2 條鏈的模型;每條鏈 100 次迭代,前 50 次捨棄。
- 列印每個模型的摘要。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 3 chains, 1000 iterations, 500 warmup
model_3chains <- stan_glm(___ ~ ___, data = songs,
___ = ___, ___ = ___, ___ = ___)
# Print a summary of model_3chains
___(model_3chains)
# 2 chains, 100 iterations, 50 warmup
model_2chains <- stan_glm(___ ~ ___, data = songs,
___ = ___, ___ = ___, ___ = ___)
# Print a summary of model_2chains
___(model_2chains)