Multivariate GAMs

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Noam Ross

Senior Research Scientist, EcoHealth Alliance

Our working dataset: mpg

mpg
  symbol loss         make  fuel aspir doors ... eng.loc    wb length width
1      3   NA  alfa-romero   gas   std   two ...   front  88.6  168.8  64.1
2      3   NA  alfa-romero   gas   std   two ...   front  88.6  168.8  64.1
3      1   NA  alfa-romero   gas   std   two ...   front  94.5  171.2  65.5
4      2  164         audi   gas   std  four ...   front  99.8  176.6  66.2
5      2  164         audi   gas   std  four ...   front  99.4  176.6  66.4
6      2   NA         audi   gas   std   two ...   front  99.8  177.3  66.3
7      1  158         audi   gas   std  four ...   front 105.8  192.7  71.4
8      1   NA         audi   gas   std  four ...   front 105.8  192.7  71.4
9      1  158         audi   gas turbo  four ...   front 105.8  192.7  71.4
10     0   NA         audi   gas turbo   two ...   front  99.5  178.2  67.9
...
Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Multiple smooths (1)

model <- gam(hw.mpg ~ s(weight), data = mpg,
             method = "REML")

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Multiple smooths (2)

model <- gam(hw.mpg ~ s(weight), data = mpg,
             method = "REML")
model2 <- gam(hw.mpg ~ s(weight) + s(length), data = mpg,
              method = "REML")
Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Multiple smooths (3)

model2 <- gam(hw.mpg ~ s(weight) + s(length), data = mpg,
              method = "REML")

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Linear terms

model2 <- gam(hw.mpg ~ s(weight) + length, data = mpg,
              method = "REML")

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Linear terms (2)

model2b <- gam(hw.mpg ~ s(weight) + s(length, sp = 1000),
               data = mpg, method = "REML")

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Categorical terms (1)

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

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Categorical terms (2)

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

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Categorical terms (3)

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

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Let's practice!

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Preparing Video For Download...