US Dairy Consumption

Time series analysis, Forecasting (sweep package)

Notable topics: Time series analysis, Forecasting (sweep package)

Recorded on: 2019-01-28

Timestamps by: Alex Cookson

## Screencast

## Timestamps

Identifying the need for a gather step

Changing snake case to title case using str_to_title and str_replace_all functions

Identifying need for separating categories into major and minor categories (e.g., "Cheese Other" can be divided into "Cheese" and "Other")

Using separate function to split categories into major and minor categories (good explanation of "extra" argument, which merges additional separations into one field)

Using coalesce function to deal with NAs resulting from above step

Dealing with graph of minor category that is linked to multiple major categories ("Other" linked to "Cheese" and "Frozen")

Introducing fct_lump function as an approach to work with many categories

Introducing facetting (facet_wrap function) as second alternative to working with many categories

Dealing with "Other" category having two parts to it by using ifelse function in the cleaning step (e.g., go from "Other" to "Other Cheese")

Looking at page for the sweep package

Using tk_ts function to coerce a tibble to a timeseries

Turning year column (numeric) into a date by adding number of years to Jan 1, 0001

Nesting time series object into each combination of category and product

Applying ETS (Error, Trend, Seasonal) model to each time series

Using sw_glance function (sweep package's version of glance function) to pull out model parameters from model field created in above step

Using sw_augment function to append fitted values and residuals from the model to the original data

Visualising actual and fitted values on the same graph to get a look at the ETS model

Using Arima function (note the capital A) as alternative to ETS (not sure what difference is between arima and Arima)

Forecasting into the future using an ETS model using various functions: unnest, sw_sweep, forecast

Using geom_ribbon function to add confidence bounds to forecast

Forecasting using auto-ARIMA (instead of ETS)

Applying two forecasting methods at the same time (auto-ARIMA and ETS) using the crossing function

Quick test of how invoke function works (used to call a function easily, e.g., when it is a character string instead of called directly)

Removing only one part of legend (line type of solid or dashed) using scale_linetype_discrete function

Using gather function to clean up new dataset

Using fct_recode to fix a typo in a categorical variable

Copy-pasting previous forecasting code to cheese and reviewing any changes needed

Discussing alternative approach: creating interactive visualisation using shiny package to do direct comparisons