Basis Functions and Smoothing

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Noam Ross

Senior Research Scientist, EcoHealth Alliance

Getting the right fit

  • Close to the data (avoiding under-fitting)
  • Not fitting the noise (avoiding over-fitting)
Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Balancing Wiggliness

$$\LARGE \text{Fit} = \text{Likelihood} - \lambda \times \text{Wiggliness}$$

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Choosing the right smoothing parameter

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Smoothing syntax

Setting a fixed smoothing parameter

gam(y ~ s(x), data = dat, sp = 0.1)
gam(y ~ s(x, sp = 0.1), data = dat)

Smoothing via restricted maximum likelihood

gam(y ~ s(x), data = dat, method = "REML")
Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Number of basis functions

Nonlinear Modeling with Generalized Additive Models (GAMs) in R

Basis function syntax

Setting number of basis functions

gam(y ~ s(x, k = 3), data = dat, method = "REML")

gam(y ~ s(x, k = 10), data = dat, method = "REML")

Use the defaults

gam(y ~ s(x), data = dat, 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...