開始使用免費開始

視覺化汽車效能的不確定性

信賴區間是用來呈現模型擬合程度的關鍵視覺線索。你將在這裡練習調整信賴區間的外觀,以及變換部分效應圖的尺度。

本練習屬於課程

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, ___)
編輯並執行程式碼