可视化分类-连续交互

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...