O'Reilly logo

Practical Data Science Cookbook - Second Edition by Abhijit Dasgupta, Benjamin Bengfort, Sean Patrick Murphy, Tony Ojeda, Prabhanjan Tattar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Defining the trend and seasonal variables, we would be able to build the linear models. We would build three linear models here:

  • with the trend variable,
  • with the seasonable variable, and
  • with both variables:
  1. Create R objects osv_time and osv_mths for the trend and seasonal variables:
osv_time <- 1 : length (osv) osv_mths <- as.factor ( rep (month.abb, times= 19 ))

Using the length function, we now have a numeric vector with values starting from 1 and ending at 228. The seasonal variable is created with the rep function, which repeats the month name 19 times successively. The month.abb is a standard character vector in R that has the month abbreviations as its content.

  1. Create the linear model using the trend variable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required