Last update : June 13, 2021 Data : Jan 2021 - May EOM, 2021 FOrecast : Data + 30 Days
Weekly Consolidated Daily Report and 30 days forecast
DATA RETRIEVAL
setwd("C:/Users/admin/Desktop/DATA SCIENCE/R Files")
dohacc <- read.csv("dohacc.csv")
dohacc$date <- as.Date(dohacc$date, "%m/%d/%Y")
dohacc$year <- format(dohacc$date, format = "%Y")
dohacc$month<- format(dohacc$date, format = "%m/%Y")
dohacc$confirm <- as.numeric(dohacc$confirm)
DATA STRUCTURE AND SUMMARY
dohacc$accumulate <- as.numeric(dohacc$accumulate)
str(dohacc)
'data.frame': 468 obs. of 5 variables:
$ date : Date, format: "2020-01-30" "2020-02-03" ...
$ confirm : num 1 1 1 2 1 4 14 9 16 3 ...
$ accumulate: num 1 2 3 5 6 10 24 33 49 52 ...
$ year : chr "2020" "2020" "2020" "2020" ...
$ month : chr "01/2020" "02/2020" "02/2020" "03/2020" ...
dohacc
total <- sum(dohacc$confirm)
total
[1] 1318003
dohacc %>% ggplot(aes(date,confirm, color="red")) + geom_line() + ggtitle("Daily Confimed Cases from Jan 2020- June 13, 2021")
dohacc %>% ggplot(aes(date,accumulate)) + geom_point() + ggtitle("Accumulated Confimed Cases from Jan 2020- June 13, 2021")
FILTER DATA TO 2021 CASES ONLY
#filter 2021 cases only
cases2021 <- dohacc %>% filter(year==2021)
tail(cases2021)
PREDICTION AND FORCASTING MODEL
#Forecasting
ds <- cases2021$date
y <- cases2021$confirm
df <- data.frame(ds,y)
m <- prophet(df)
Disabling yearly seasonality. Run prophet with yearly.seasonality=TRUE to override this.
Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
future <- make_future_dataframe(m, periods=30)
forecast <- predict(m,future)
summary(forecast)
ds trend additive_terms
Min. :2021-01-01 00:00:00 Min. : -1.074 Min. :-1051.941
1st Qu.:2021-02-18 06:00:00 1st Qu.:3319.902 1st Qu.: -981.680
Median :2021-04-07 12:00:00 Median :5733.532 Median : 176.949
Mean :2021-04-07 12:00:00 Mean :5173.026 Mean : 3.962
3rd Qu.:2021-05-25 18:00:00 3rd Qu.:7151.762 3rd Qu.: 672.133
Max. :2021-07-13 00:00:00 Max. :8219.886 Max. : 835.450
additive_terms_lower additive_terms_upper weekly weekly_lower
Min. :-1051.941 Min. :-1051.941 Min. :-1051.941 Min. :-1051.941
1st Qu.: -981.680 1st Qu.: -981.680 1st Qu.: -981.680 1st Qu.: -981.680
Median : 176.949 Median : 176.949 Median : 176.949 Median : 176.949
Mean : 3.962 Mean : 3.962 Mean : 3.962 Mean : 3.962
3rd Qu.: 672.133 3rd Qu.: 672.133 3rd Qu.: 672.133 3rd Qu.: 672.133
Max. : 835.450 Max. : 835.450 Max. : 835.450 Max. : 835.450
weekly_upper multiplicative_terms multiplicative_terms_lower
Min. :-1051.941 Min. :0 Min. :0
1st Qu.: -981.680 1st Qu.:0 1st Qu.:0
Median : 176.949 Median :0 Median :0
Mean : 3.962 Mean :0 Mean :0
3rd Qu.: 672.133 3rd Qu.:0 3rd Qu.:0
Max. : 835.450 Max. :0 Max. :0
multiplicative_terms_upper yhat_lower yhat_upper trend_lower
Min. :0 Min. :-2788 Min. : 1373 Min. : -1.074
1st Qu.:0 1st Qu.: 1389 1st Qu.: 5520 1st Qu.:3319.902
Median :0 Median : 3701 Median : 7748 Median :5701.297
Mean :0 Mean : 3153 Mean : 7203 Mean :5143.739
3rd Qu.:0 3rd Qu.: 5124 3rd Qu.: 9109 3rd Qu.:7151.762
Max. :0 Max. : 6980 Max. :11129 Max. :8219.886
trend_upper yhat
Min. : -1.074 Min. :-714.7
1st Qu.:3319.902 1st Qu.:3445.4
Median :5773.834 Median :5711.4
Mean :5203.102 Mean :5177.0
3rd Qu.:7151.762 3rd Qu.:7144.4
Max. :8219.886 Max. :9028.7
MONTHLY CASES 2021 AS OF APRIL MTD
upmonth <- cases2021 %>% mutate(month_ = month(date, label = T) )
upmonth %>% ggplot(aes(month_,confirm, fill="red")) + geom_bar(stat = "identity") + scale_y_continuous(labels=scales::comma) + ggtitle("Covid-19 Daily Confirmed Cases group by monthly, Philippines 2021")
upmonth %>% group_by(month_) %>% summarise(Monthly2021_cases=sum(confirm), Avg_cases=mean(confirm))
June2021 <- upmonth %>% filter(month_=="Jun")
max(June2021$confirm)
[1] 8003
min(June2021$confirm)
[1] 4769
PLOT MODEL
dyplot.prophet(m, forecast,
main= "Jan 2021 - June 13, 2021 Data + 30 days forecast")
`select_()` was deprecated in dplyr 0.7.0.
Please use `select()` instead.Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Prepared by Dodgecarl Incila