汽車效能的多變量 GAM
GAM 可以接受不同型別的多個變數。接下來的練習中,你會使用 gamair 套件中的 mpg 資料集,練習配適不同形式的模型。
本練習屬於課程
R 中的廣義加法模型(GAM)之非線性建模
練習說明
- 使用
head()與str()函式查看mpg資料集。 - 配適一個 GAM,以
weight、length與price的平滑函式相加來預測city.mpg。 - 使用提供的
plot()函式視覺化模型。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
library(mgcv)
# Examine the data
___
___
# Fit the model
mod_city <- gam(city.mpg ~ ___,
data = mpg, method = "REML")
# Plot the model
plot(mod_city, pages = 1)