計算傳統統計的 R-squared
來練習計算 R-squared。先從傳統統計的 R-squared 著手,可以把你手算 R-squared 的公式,和傳統統計摘要中的數值交叉比對。lm_model 與 lm_summary 物件已經在你的環境中。
本練習屬於課程
使用 rstanarm 的貝葉斯迴歸建模
練習說明
- 列印
lm_summary物件中的 R-squared 值。 - 計算
lm_model的殘差變異數。 - 計算
lm_model的預測值變異數。 - 計算 R-squared 值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the R-squared from the linear model
lm_summary$___
# Calulate sums of squares
ss_res <- ___(___(lm_model))
ss_fit <- ___(___(lm_model))
# Calculate the R-squared
1 - (___ / (___ + ___))