-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCorondAndFluAnalysis.R
103 lines (87 loc) · 4.54 KB
/
CorondAndFluAnalysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#Q1
# This file reads influenza data (Flue) from the 'U.S.' Centers for
# Disease Control and Prevention (CDC)
# To view the data inspect https://gis.cdc.gov/grasp/fluview/fluportaldashboard.html
# Used for exercise in forcasting, Course - Production Management 1, Ariel University.
# packages
# install.packages("cdcfluview")
library(cdcfluview)
national_ili <- ilinet("national",years = c(1997,2018))
# change the our data to Time series to a mount Series
ts.mydata<-ts(data = national_ili$total_patients, end = c(2018,12), frequency = 12)
# call t he forecast package
library(forecast)
#We will make a prediction using a holt model and we will make predict for all 2019 mounts
HoltModel <- HoltWinters(ts.mydata)
predict_HoltMoedl <- predict(HoltModel, 12 , prediction.interval = FALSE)
#Q2
#read covid19 data
library(tidyquant)
library(coronavirus)
library(dplyr)
library(forecast)
library(ggplot2)
# ?????????????? ?????????????? ???????????? ?????????? ?????????? ???????????? ??????????????
Israel <-coronavirus %>%
filter(type == "confirmed",country == "Israel") %>% # ?????????? ?????? ???? ???????????? ???????? ???????? ??????????????
group_by(date) %>% # ?????????? ???????????? ?????? ?????????????? ?????????? ?????????? ???? ?????????????? ?????? ?????????????? ???? ????????
#?????????? ???? ?????????? ?????????? ?????????? ???? ????????
Israel_ts<-ts(data =Israel$cases, end = c(2021, 02), frequency = 365)
dat.lm1_Israel <- tslm(Israel_ts ~ trend) # ?????????? ?????????? ???? ?????? ???????????? ??????????????
# ????????????
feb = -966.4+ 14.2*c(374:404)
mar = -966.4+ 14.2*c(404:434)
apr = -966.4+ 14.2*c(434:454)
#?????? ?????????? ???? ?????????????? ????????????????
autoplot(Israel_ts, series="Data")+
ggtitle(paste("Covid-19 infections", "Israel")) +
xlab("Time") +
ylab("Covid-19 infections")+
autolayer(dat.lm1_Israel$fitted.values, series="Israel")
# ?????? ???????????? ?????????? ???? ???????? ???????????????? ?????? ??????
barplot(height=Israel$cases, names=Israel$date,
font.axis=1,
col.axis="blue",
cex.axis=0.7,
las = 2)
#???????? ?????????? ???????? ?????????? ??????????????, ?????????? ?????????? ?????? ???????? ???????? ???????? ?????????? ???????????? ???????????? ???? ?????????? ?????? ?????? ???? ??????????????
Russia <- coronavirus %>%
filter(type == "confirmed",country == "Russia") %>%
group_by(date,cases)
Russia_ts<-ts(data = Russia$cases, end = c(2021, 02),frequency = 365)
US <- coronavirus %>%
filter(type == "confirmed") %>%
group_by(country) %>%
filter(country == "US")
US_ts<-ts(data = US$cases, end = c(2021, 01), frequency = 365)
India <-coronavirus %>%
filter(type == "confirmed") %>%
group_by(country) %>%
filter(country == "India")
India_ts<-ts(data = India$cases, end = c(2021, 01), frequency = 365)
Canada <- coronavirus %>%
filter(type == "confirmed",country == "Canada") %>%
group_by(date) %>%
summarise(cases = sum(cases))
Canada_ts<-ts(data = Canada$cases,end = c(2021, 01), frequency = 365)
Brazil <- coronavirus %>%
filter(type == "confirmed") %>%
group_by(country) %>%
filter(country == "Brazil")
Brazil_ts<-ts(data = Brazil$cases, end = c(2021, 01), frequency = 365)
# ???????????? ???????? ?????? ???? ?????????????? ????????????
# ???????? ?????????? ?????????? ?????????????????? ??????????, ?????????? ?????????? ???? ???????????? ???? ?????????? ?????????????? ???????????? ?????? ?????????? ???????????? ?????? ?????? ?????? ?????? ????????
# ?????????? ???? ???????? ?????? ??????????????
autoplot(Russia_ts, series="Russia")+
ggtitle("Covid-19 infections Of Russia, Israel, US, India, Canada, Brazil") +
xlab("Time") +
ylab("Covid-19 infections")+
autolayer(Brazil_ts, series="Brazil")+
autolayer(Israel_ts, series="Israel")+
autolayer(US_ts, series="US")+
autolayer(India_ts, series="India")+
autolayer(Canada_ts, series="Canada")
# ????????????:
# ???????? ?????????? ???????? ?????? ?????????????? ?????????? ???????????????? ???????? ???????? ???????????? ???????????????? ?????????? ???????? ?????? ?????????? ????????????
#?????????? ?????????? ?????????????? ???????????????? ???????? ???????? ???????? ?????????? ?????? ?????????? ???????????????? ???????? ?????????????? ???????? ???? ??????
#???????????? ?????? ?????????? ?????????????? ?????????????? ?????? ????????, ???????? ???????????????? ?????? ?????????????? ???? ???????? ?????? ?????????? ???????????? ???????????? ???????????????? ?????????? ?????????? ?????? ??????