開始使用免費開始

Bayesian 模型的 R-squared

現在來計算 Bayesian 模型的 R-squared,以評估使用 stan_glm 估計之模型的預測表現。stan_model 物件已經載入。

本練習屬於課程

使用 rstanarm 的貝葉斯迴歸建模

檢視課程

練習說明

  • 計算 stan_model 殘差的變異數
  • 計算 stan_model 擬合值的變異數
  • 計算 R-squared

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Save the variance of residulas
ss_res <- ___(___(stan_model))

# Save the variance of fitted values
ss_fit <- ___(___(stan_model))

# Calculate the R-squared
1 - (___ / (___ + ___))
編輯並執行程式碼