+ - 0:00:00
Notes for current slide
Notes for next slide

Lab 05 - Nonlinear Models

Dr. D’Agostino McGowan

1 / 7

Recall

  • Polynomials
2 / 7

Recall

  • Polynomials
  • Step functions
2 / 7

Recall

  • Polynomials
  • Step functions
  • Linear splines
2 / 7

Recall

  • Polynomials
  • Step functions
  • Linear splines
  • Cubic Splines
2 / 7

Recall

  • Polynomials
  • Step functions
  • Linear splines
  • Cubic Splines
  • Natural Splines
2 / 7

3 / 7

Natural cubic splines

A natural cubic spline extrapolates linearly beyond the boundary knots

4 / 7

Natural cubic splines

A natural cubic spline extrapolates linearly beyond the boundary knots

  • This adds 4 extra constraints and allows us to put more internal knots for the same degrees of freedom as a regular cubic spline

4 / 7

It's really easy to do this in R!

5 / 7

It's really easy to do this in R!

  • You can transform any continuous (numeric) variable into a natural spline by using the step_ns() function in a recipe.
5 / 7

It's really easy to do this in R!

  • You can transform any continuous (numeric) variable into a natural spline by using the step_ns() function in a recipe.
  • You specify the degrees of freedom that you would like to use for that variable using the deg_free parameter
5 / 7

It's really easy to do this in R!

  • You can transform any continuous (numeric) variable into a natural spline by using the step_ns() function in a recipe.
  • You specify the degrees of freedom that you would like to use for that variable using the deg_free parameter
library(ISLR)
auto_rec <- Auto %>%
recipe(mpg ~ horsepower) %>%
step_ns(horsepower, deg_free = 2)
5 / 7

It's really easy to do this in R!

  • You can transform any continuous (numeric) variable into a natural spline by using the step_ns() function in a recipe.
  • You specify the degrees of freedom that you would like to use for that variable using the deg_free parameter
library(ISLR)
auto_rec <- Auto %>%
recipe(mpg ~ horsepower) %>%
step_ns(horsepower, deg_free = 2)

How many degrees of freedom did I allocate to the horsepower variable?

5 / 7

It's really easy to do this in R!

  • You can transform any continuous (numeric) variable into a natural spline by using the step_ns() function in a recipe.
  • You specify the degrees of freedom that you would like to use for that variable using the deg_free parameter
  • Instead of specifying deg_free you could use tune() to tune this.
6 / 7

It's really easy to do this in R!

  • You can transform any continuous (numeric) variable into a natural spline by using the step_ns() function in a recipe.
  • You specify the degrees of freedom that you would like to use for that variable using the deg_free parameter
  • Instead of specifying deg_free you could use tune() to tune this.
auto_rec <- Auto %>%
recipe(mpg ~ horsepower) %>%
step_ns(horsepower, deg_free = tune())
6 / 7

Lab 05 - Non-linear Models

  • Find Lab 05 on our website
  • Pull your starter files from GitHub into RStudio
  • Note the due date I have intentionally made this lab short so that it can be completed by Thursday
7 / 7

Recall

  • Polynomials
2 / 7
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow