library(tidyquant)
library(tidyverse)
library(fpp3)
library(moments)
library(tsibble)
library(tsibbledata)
library(ggfortify)
library(ggplot2)
library(readxl)
library(dplyr)
library(fabletools)
library(fable)
library(slider)
library(zoo)
GCSU_COVID <- read_excel("/Users/Peter Cook/Documents/Economics and Finance/Business Forecasting/Forecasting Data/GCSU_COVID.xlsx")
covid_cases <- GCSU_COVID %>%
mutate(Date = yearweek(Date)) %>%
as_tsibble(index = Date,
key = c(Employee_Cases, Student_Cases)
)
GCC <- GCSU_COVID %>%
select(Date, Employee_Cases, Student_Cases)%>%
pivot_longer(-Date)%>%
ggplot(aes(x = Date, y = value, colour = name)) +
geom_line() +
facet_grid(name ~ ., scales = "free_y")
GCC
#These graphs show the Covid cases per week from January 1 of 2022, up
until the present day (September 16, 2022). The chart with the blue line
displays student cases and the chart with the red line displays employee
cases.
GCCma_employee <- GCSU_COVID %>%
mutate(cma = rollmean(Employee_Cases, k = 3, fill = NA))
GCCma_employee
## # A tibble: 36 × 4
## Date Employee_Cases Student_Cases cma
## <dttm> <dbl> <dbl> <dbl>
## 1 2022-09-04 00:00:00 9 24 NA
## 2 2022-08-28 00:00:00 21 49 11.3
## 3 2022-08-22 00:00:00 4 88 11.7
## 4 2022-08-14 00:00:00 10 22 6.33
## 5 2022-08-07 00:00:00 5 0 9
## 6 2022-07-31 00:00:00 12 1 8
## 7 2022-07-24 00:00:00 7 1 9.67
## 8 2022-07-18 00:00:00 10 4 8
## 9 2022-07-10 00:00:00 7 4 8
## 10 2022-07-03 00:00:00 7 1 7.33
## # … with 26 more rows
## # ℹ Use `print(n = ...)` to see more rows
#This is a chart of the weekly Covid Cases, the cma column displaying the three period moving average of employee cases.
GCCma_student <- GCSU_COVID %>%
mutate(cma = rollmean(Student_Cases, k = 3, fill = NA))
GCCma_student
## # A tibble: 36 × 4
## Date Employee_Cases Student_Cases cma
## <dttm> <dbl> <dbl> <dbl>
## 1 2022-09-04 00:00:00 9 24 NA
## 2 2022-08-28 00:00:00 21 49 53.7
## 3 2022-08-22 00:00:00 4 88 53
## 4 2022-08-14 00:00:00 10 22 36.7
## 5 2022-08-07 00:00:00 5 0 7.67
## 6 2022-07-31 00:00:00 12 1 0.667
## 7 2022-07-24 00:00:00 7 1 2
## 8 2022-07-18 00:00:00 10 4 3
## 9 2022-07-10 00:00:00 7 4 3
## 10 2022-07-03 00:00:00 7 1 2.33
## # … with 26 more rows
## # ℹ Use `print(n = ...)` to see more rows
#This is a chart of the weekly Covid Cases, the cma column displaying the three period moving average of student cases.
covid_cases_ALLtransformed <- transform(covid_cases, Student_Cases = log(Student_Cases), Employee_Cases = log(Employee_Cases))
GCC_transformed <- covid_cases_ALLtransformed %>%
select(Date, Employee_Cases, Student_Cases) %>%
pivot_longer(-Date)%>%
ggplot(aes(x = Date, y = value, colour = name)) +
geom_line() +
facet_grid(name ~ ., scales = "free_y")
GCC_transformed
#These graphs both show the logged value of covid cases of employees and
students
#Both sets of graphs as well as the charts show us that covid cases for both students and employees see a dramatic upwards spike at the beginning of the semester (January and August see the larget single week increases). However, because of the limited number of observations in the data set, we cannot observe any seasonality. If we had more years of observations, we could say that there is potential seasonality at the start of each semester.
#For the week of September 19 to September 25, we can predict that there will be 9 total cases, with 3 employee cases and 6 student cases. These values were found by calculating the percentange changes of employee and student cases between the weeks starting on August 28 and September 4 and then applying that percentage change two weeks into the future. Our 80% prediction interval for total cases ranges from 11 to 7. This percentage change approach was utilized because total cases fell off dramatically after the first few weeks of the last semester, meaning that cases will likely do the same now.