O'Reilly logo

Practical Predictive Analytics by Ralph Winters

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

Automating the regressions

Now that we have seen how we can run a single time series regression, we can move on to automating separate regressions and extracting the coefficients over all of the categories.

There are several ways to do this. One way is by using the do() function within the dplyr package. Here is the sequence of events:

  • The data is first grouped by category.
  • Then, a linear regression (lm() function) is run for each category, with Year as the independent variable, and Not.Covered as the dependent variable. This is all wrapped within a do() function.
  • The coefficient is extracted from the model. The coefficient will act as a proxy for the direction and magnitude of the trend.
  • Finally, a dataframe of lists is created (fitted.models ...

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