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 (, 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 is a standard character vector in R that has the month abbreviations as its content.

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

Get Practical Data Science Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.