library(fastDummies)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(generics)
## 
## Attaching package: 'generics'
## The following object is masked from 'package:caret':
## 
##     train
## The following object is masked from 'package:lubridate':
## 
##     as.difftime
## The following objects are masked from 'package:base':
## 
##     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
##     setequal, union
library(tsibble)
## 
## Attaching package: 'tsibble'
## The following object is masked from 'package:lubridate':
## 
##     interval
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, union
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:generics':
## 
##     explain
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(fpp3)
## ── Attaching packages ──────────────────────────────────────────── fpp3 0.4.0 ──
## ✓ tibble      3.1.6     ✓ feasts      0.2.2
## ✓ tidyr       1.2.0     ✓ fable       0.3.1
## ✓ tsibbledata 0.4.0
## ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
## x lubridate::date()    masks base::date()
## x dplyr::filter()      masks stats::filter()
## x tsibble::intersect() masks generics::intersect(), base::intersect()
## x tsibble::interval()  masks lubridate::interval()
## x dplyr::lag()         masks stats::lag()
## x fabletools::MAE()    masks caret::MAE()
## x fabletools::RMSE()   masks caret::RMSE()
## x tsibble::setdiff()   masks generics::setdiff(), base::setdiff()
## x tsibble::union()     masks generics::union(), base::union()
library(modeest)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Registered S3 method overwritten by 'forecast':
##   method          from  
##   predict.default statip
## 
## Attaching package: 'forecast'
## The following object is masked from 'package:modeest':
## 
##     naive
## The following objects are masked from 'package:generics':
## 
##     accuracy, forecast
## Monthly Beer Production in Australia Data Set from Kaggle
data <- read.csv("//Users//kevinclifford//Downloads//monthly-beer-production-in-austr.csv", header=TRUE)
beer.production <- data %>%
                    mutate(Month = yearmonth(Month)) %>%
                    as_tsibble(index = Month)



## Additive Decomposition
beer.production %>%
  model(
    classical_decomposition(Monthly.beer.production, type = "additive")
  ) %>%
  components() %>%
  autoplot() +
  labs(title = "Classical additive decomposition of Beer Production in Australia")
## Warning: Removed 6 row(s) containing missing values (geom_path).

## Multiplicative Decomposition
beer.production %>%
  model(
    classical_decomposition(Monthly.beer.production, type = "multiplicative")
  ) %>%
  components() %>%
  autoplot() +
  labs(title = "Classical multiplicative decomposition of Beer Production in Australia")
## Warning: Removed 6 row(s) containing missing values (geom_path).

** Attempted forecast and error calculation (realized it was producing zero so I think it is wrong set-up?) **

add <- beer.production %>% model( classical_decomposition(Monthly.beer.production, type = “additive”) ) %>% components()

addcast <- add\(season_adjust[7:103] + add\)seasonal[7:103]

adderror <- add$Monthly.beer.production[7:103] - addcast

mult <- beer.production %>% model( classical_decomposition(Monthly.beer.production, type = “multiplicative”) ) %>% components()

multcast <- mult\(season_adjust[7:103] * mult\)seasonal[7:103]

multerror <- mult$Monthly.beer.production[7:103] - addcast