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

Non-linearity in R

Dr. D’Agostino McGowan

1 / 6

Recall

  • Polynomials
2 / 6

Recall

  • Polynomials
  • Step functions
2 / 6

Recall

  • Polynomials
  • Step functions
  • Linear splines
2 / 6

Recall

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

Recall

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

3 / 6

Natural cubic splines

A natural cubic spline extrapolates linearly beyond the boundary knots

4 / 6

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 / 6

It's really easy to do this in R!

5 / 6

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 / 6

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 / 6

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 / 6

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 / 6

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 / 6

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 / 6

Recall

  • Polynomials
2 / 6
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