視覺化類別-連續交互作用

R 中的廣義加法模型(GAM)之非線性建模

Noam Ross

Senior Research Scientist, EcoHealth Alliance

類別-連續交互作用

model4b <- gam(hw.mpg ~ s(weight, by = fuel) + fuel, 
              data = mpg, 
              method = "REML")

R 中的廣義加法模型(GAM)之非線性建模

因子樣條(factor-smooths)

model4c <- gam(hw.mpg ~ s(weight, fuel, bs = "fs"),
               data = mpg,
               method = "REML")
R 中的廣義加法模型(GAM)之非線性建模
summary(model4c)
Family: gaussian 
Link function: identity 
Formula:
hw.mpg ~ s(weight, fuel, bs = "fs")

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   28.644      7.615   3.761 0.000223 ***
 ---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
                edf Ref.df     F p-value    
s(weight,fuel) 7.71     19 53.12  <2e-16 ***
 ---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.832   Deviance explained = 83.8%
-REML = 518.54  Scale est. = 7.9735    n = 205
R 中的廣義加法模型(GAM)之非線性建模

繪製因子樣條

plot(model4c)
vis.gam(model4c, theta = 125, plot.type = "persp")

R 中的廣義加法模型(GAM)之非線性建模

一起來練習吧!

R 中的廣義加法模型(GAM)之非線性建模

Preparing Video For Download...