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
##DISCUSSION WEEK 7
## READ IN US GAS DATA
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)

## Create Train and Test Data Sets
## Create Test and Training Sets - split out 2018 onward, about 30 months
train <- window(gasts, start = 1945, end=c(2016,12))
test <- window(gasts, start =c(2017,1))

# Fit Neural Net Model
netmod <- nnetar(train, lambda = 0)
fcnetmod <- forecast(netmod,h=60)
autoplot(fcnetmod) + ylab("Gas Barrels - 1000") + xlab("Monthly Demand") + theme_bw()

netmod2 <- nnetar(train, lambda = 1)
fcnetmod2 <- forecast(netmod2,h=60)
autoplot(fcnetmod2) + ylab("Gas Barrels - 1000") + xlab("Monthly Demand") + theme_bw()

fcnetmod2PI <- forecast(netmod2,PI=TRUE, h=60)
autoplot(fcnetmod2PI) + ylab("Gas Barrels - 1000") + xlab("Monthly Demand") + theme_bw()