視覺化汽車效能的不確定性
信賴區間是用來呈現模型擬合程度的關鍵視覺線索。你將在這裡練習調整信賴區間的外觀,以及變換部分效應圖的尺度。
本練習屬於課程
R 中的廣義加法模型(GAM)之非線性建模
練習說明
- 繪製使用
mpg資料的模型(mod),只畫出weight的部分效應。將信賴區間設為陰影並使用"hotpink"著色。 - 另做一張
weight的部分效應圖,這次使用shift參數以截距值平移尺度,並用seWithMean參數將模型截距的不確定性一併納入。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
library(mgcv)
# Fit the model
mod <- gam(hw.mpg ~ s(weight) + s(rpm) + s(price) + comp.ratio,
data = mpg, method = "REML")
# Plot the weight effect with colored shading
plot(mod, select = 1, ___)
# Make another plot adding the intercept value and uncertainty
plot(mod, select = 1, ___)