DATA 521: Time Series Analysis and Forecasting

DATA 521: Forecasting COVID-19

This is the summary forecasting page. This contains a few examples that are more or less complete on their own.

The course textbook:

Daily Weather Forecasting

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.

Forecasting the Weather

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.

NYT COVID Forecast Aggregation

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.

NYT COVID Forecast Aggregation (Box-Cox)

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.

NYT COVID-19 Aggregates

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.

TBATS for COVID-19 Data

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.