library(tidyverse)
## -- Attaching packages -------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.1 v purrr 0.3.2
## v tibble 2.1.3 v dplyr 0.8.3
## v tidyr 0.8.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts ----------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(mosaic)
## Loading required package: lattice
## Loading required package: ggformula
## Loading required package: ggstance
##
## Attaching package: 'ggstance'
## The following objects are masked from 'package:ggplot2':
##
## geom_errorbarh, GeomErrorbarh
##
## New to ggformula? Try the tutorials:
## learnr::run_tutorial("introduction", package = "ggformula")
## learnr::run_tutorial("refining", package = "ggformula")
## Loading required package: mosaicData
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following object is masked from 'package:tidyr':
##
## expand
## Registered S3 method overwritten by 'mosaic':
## method from
## fortify.SpatialPolygonsDataFrame ggplot2
##
## The 'mosaic' package masks several functions from core packages in order to add
## additional features. The original behavior of these functions should not be affected by this.
##
## Note: If you use the Matrix package, be sure to load it BEFORE loading mosaic.
##
## Attaching package: 'mosaic'
## The following object is masked from 'package:Matrix':
##
## mean
## The following objects are masked from 'package:dplyr':
##
## count, do, tally
## The following object is masked from 'package:purrr':
##
## cross
## The following object is masked from 'package:ggplot2':
##
## stat
## The following objects are masked from 'package:stats':
##
## binom.test, cor, cor.test, cov, fivenum, IQR, median,
## prop.test, quantile, sd, t.test, var
## The following objects are masked from 'package:base':
##
## max, mean, min, prod, range, sample, sum
library(ggformula)
library(readr)
library(fpp2)
## Loading required package: forecast
## Registered S3 method overwritten by 'xts':
## method from
## as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Registered S3 methods overwritten by 'forecast':
## method from
## fitted.fracdiff fracdiff
## residuals.fracdiff fracdiff
## Loading required package: fma
## Loading required package: expsmooth
## ETS Models Discussion Post
usgas <- read_csv("E:/WOODS/ADECXXXX/usgas.csv")
## Parsed with column specification:
## cols(
## Date = col_character(),
## GasBarrelsK = col_double()
## )
gas <- usgas$GasBarrelsK
gasts <- ts(gas, start = c(1945, 1), frequency = 12)
autoplot(gasts)

#ETS Models
#ETS Basic exponential smoothing
gasexp <- ets(gasts, model = "ANN")
## Warning in ets(gasts, model = "ANN"): Missing values encountered. Using
## longest contiguous portion of time series
summary(gasexp)
## ETS(A,N,N)
##
## Call:
## ets(y = gasts, model = "ANN")
##
## Smoothing parameters:
## alpha = 0.7417
##
## Initial states:
## l = 1325.0628
##
## sigma: 247.5968
##
## AIC AICc BIC
## 15972.10 15972.13 15986.49
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 12.66373 247.3203 193.2805 0.1766717 3.388156 1.017145
## ACF1
## Training set -0.02169056
autoplot(gasexp)

#ETS AAA: additive error, additive trend, additive seasonality; Holt-Winters algorithm.
gasAAA <- ets(gasts, model = "AAA")
## Warning in ets(gasts, model = "AAA"): Missing values encountered. Using
## longest contiguous portion of time series
summary(gasAAA)
## ETS(A,Ad,A)
##
## Call:
## ets(y = gasts, model = "AAA")
##
## Smoothing parameters:
## alpha = 0.242
## beta = 0.0145
## gamma = 0.072
## phi = 0.9751
##
## Initial states:
## l = 1451.6809
## b = 33.0415
## s = -82.3314 -112.8097 9.5379 -6.0319 306.5798 279.9161
## 312.3923 129.9725 22.5041 -112.235 -287.0032 -460.4915
##
## sigma: 140.4363
##
## AIC AICc BIC
## 14970.79 14971.57 15057.15
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 9.078645 139.0977 108.1554 0.1404372 2.011831 0.5691712
## ACF1
## Training set -0.07565933
autoplot(gasAAA)

#ETS MAM: multiplicative error, additive trend, multiplicative seasonality
gasMAM <- ets(gasts, model = "MAM")
## Warning in ets(gasts, model = "MAM"): Missing values encountered. Using
## longest contiguous portion of time series
summary(gasMAM)
## ETS(M,Ad,M)
##
## Call:
## ets(y = gasts, model = "MAM")
##
## Smoothing parameters:
## alpha = 0.2307
## beta = 0.0119
## gamma = 0.1962
## phi = 0.9785
##
## Initial states:
## l = 1403.6891
## b = 31.7562
## s = 0.9275 0.9841 1.0209 1.0549 1.0891 1.0653
## 1.0697 1.0504 1.0209 0.9413 0.8957 0.8802
##
## sigma: 0.0253
##
## AIC AICc BIC
## 15077.74 15078.52 15164.10
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 8.053713 140.6551 107.7208 0.1364234 1.895082 0.5668843
## ACF1
## Training set -0.06490072
autoplot(gasMAM)
