This is the summary forecasting page. This contains a few examples that are more or less complete on their own.
The course textbook:
Preliminary Steps Load some libraries.
library(kableExtra) library(distributional) library(tidyverse) library(lubridate) library(hrbrthemes) library(fpp3) library(magrittr) Loading NWS Data Load the data.
# There is one blank variable name and some garbage at the top. Skip the first # six rows and label M and - as missing. NWS <- read.csv(url("https://www.weather.gov/source/pqr/climate/webdata/Portland_dailyclimatedata.csv"), skip = 6, na.strings = c("M", "-")) %>% rename(Variable = X) One thing that will prove troublesome is that /A appears in a few places.
Loading NWS Data Load the data.
# There is one blank variable name and some garbage at the top. Skip the first # six rows and label M and - as missing. NWS <- read.csv(url("https://www.weather.gov/source/pqr/climate/webdata/Portland_dailyclimatedata.csv"), skip = 6, na.strings = c("M", "-")) %>% rename(Variable = X) One thing that will prove troublesome is that /A appears in a few places. I want to remove it. I will ask R to find all of the character columns and remove /A.
New York Times Data on COVID I will grab the dataset from the NYT COVID data github. I will create two variables, New Cases and New Deaths to model. The final line uses aggregation to create the national data.
NB: This file takes a really long time to run; forecasting deaths took just under six hours.
NYT.COVIDN <- read.csv(url("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv")) # Define a tsibble; the date is imported as character so mutate that first.
New York Times Data on COVID I will grab the dataset from the NYT COVID data github. I will create two variables, New Cases and New Deaths to model. The final line use aggregation to create the national data.
NYT.COVIDN <- read.csv(url("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv")) # Define a tsibble; the date is imported as character so mutate that first. NYT.COVID <- NYT.COVIDN %>% mutate(date = as.Date(date)) %>% as_tsibble(index = date, key = state) %>% group_by(state) %>% mutate(New.
New York Times Data on COVID I will grab the dataset from the NYT COVID data github. I will create two variables, New Cases and New Deaths to model. The final line use aggregation to create the national data.
NYT.COVIDN <- read.csv(url("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv")) # Define a tsibble; the date is imported as character so mutate that first. NYT.COVID <- NYT.COVIDN %>% mutate(date = as.Date(date)) %>% as_tsibble(index = date, key = state) %>% group_by(state) %>% mutate(New.
Load the Previous Results for Comparison Because this project was undertaken over more than one day, the live download of New York Times COVID-19 data will not necessarily match up. To sidestep this problem, I will load the data that I worked with previously.
load("data/AggForecast.RData") New Cases First, I will manipulate the data to fit the old style of time series needed by TBATS.
# To use tbats, I need an old style time series First, select the data of # interest: New.