-
Notifications
You must be signed in to change notification settings - Fork 0
/
Covid-19_maindata_Analysis and Prediction.Rmd
246 lines (175 loc) · 6.07 KB
/
Covid-19_maindata_Analysis and Prediction.Rmd
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
---
title: "Covid-19 Analysis and Prediction"
author: "Arushi Sharma"
date: "3/14/2020"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r message=FALSE}
#Importing all required libraries
library(dplyr)
library(ggplot2)
library(tidyverse)
library(arsenal)
library(caret)
library(wordcloud)
```
```{r}
#Importing dataset
covid19 <- readr :: read_csv("novel-corona-virus-2019-dataset/covid_19_data.csv")
head(covid19, 10)
tail(covid19, 10)
```
```{r}
#summary of the data
summary(covid19)
```
```{r}
#Finding deaths by country
covid19 %>% distinct(`Country/Region`) %>% count()
#%>% filter(Deaths > 0) %>% count(Deaths)
```
```{r Most_affected_countries,warning=FALSE}
tot <- covid19 %>%
filter(ObservationDate == "03/26/2020") %>%
group_by(`Country/Region`) %>%
summarise(sm= sum(Confirmed)) %>%
summarise(sm= sum(sm))
filtered <- covid19 %>% filter(ObservationDate == "03/26/2020") %>%
group_by(`Country/Region`) %>%
summarise(n=sum(Confirmed)) %>%
arrange((n)) %>%
tail(5)
ggplot(filtered) + aes(x=reorder(`Country/Region`,-n),n) +
geom_col() +
geom_col(stat = "identity",fill = "darkolivegreen") +
labs(title = " Reported cases in worst affected countries ") +
xlab("Country") +
ylab("Number of reported cases ") +
geom_text(aes(label=n), vjust=.001, color = "black")
```
```{r}
(covid19 %>% filter(ObservationDate == "03/26/2020") %>%
filter(`Country/Region` == "US") %>% summarise(sum(Confirmed)) )/tot
```
```{r message=FALSE}
covid19 %>% filter(`Country/Region` == "US") %>%
filter(ObservationDate == "03/26/2020") %>%
group_by(`Province/State`) %>%
summarise(n=sum(Confirmed)) %>%
arrange((n)) %>% tail(5) %>%
ggplot() + aes(x=reorder(`Province/State`,-n),n) +
geom_col() +geom_col(stat = "identity",fill = "darkolivegreen") +
labs(title = " Reported cases in worst affected Province/State of US ") +
xlab("Province/State of US ") +ylab("Number of reported cases ") +
geom_text(aes(label=n), vjust=.001, color = "black")
```
```{r}
covid_cases <- covid19 %>% filter(ObservationDate == "03/26/2020") %>%
group_by(`Country/Region`) %>%
summarise(confirmed_cases=sum(Confirmed),Casualities=sum(Deaths),Recovered_cases=sum(Recovered)) %>%
arrange(desc(confirmed_cases)) %>% head(5)
covid_cases
#calculating the recovery rate
covid_cases <- covid_cases %>% mutate(recovered_ratio = Recovered_cases/confirmed_cases)
covid_cases
covid_mean <- covid19 %>% filter(ObservationDate == "03/26/2020") %>%
summarise(confirmed_cases=sum(Confirmed),Casuality=sum(Deaths),Recovered_cases=sum(Recovered)) %>%
arrange(desc(confirmed_cases))
covid_mean
```
```{r}
covid19 %>% group_by(ObservationDate) %>%
summarise(datewise = sum(Confirmed)) %>%
ggplot(aes(x=ObservationDate, y=datewise, group=1)) +
geom_line(col="darkolivegreen") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = " Plot of Total Reported cases for the month of January-March 2020 ") +
xlab("Observed Date ") +ylab("Number of reported cases ")
```
```{r}
covid19 %>% filter(grepl('^01/', ObservationDate)) %>% group_by(ObservationDate) %>%
summarise(datewise = sum(Confirmed)) %>%
ggplot(aes(x=ObservationDate, y=datewise, group=1)) +
geom_line(col = "black") +labs(title="Reported cases in the month of January",x="Date", y = "Number of cases") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
```
```{r}
covid19 %>% filter(grepl('^02/', ObservationDate)) %>% group_by(ObservationDate) %>%
summarise(datewise = sum(Confirmed)) %>%
ggplot(aes(x=ObservationDate, y=datewise, group=1)) +
geom_line(col = "black") +labs(title="Reported cases in the month of February",x="Date", y = "Number of cases") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
```
```{r}
covid19 %>% filter(grepl('^03/', ObservationDate)) %>% group_by(ObservationDate) %>%
summarise(datewise = sum(Confirmed)) %>%
ggplot(aes(x=ObservationDate, y=datewise, group=1)) +
geom_line(col = "black") +labs(title="Reported cases in the month of March",x="Date", y = "Number of cases") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
```
```{r}
covid_cloud <- covid19 %>%
filter(ObservationDate == "03/26/2020" )
wordcloud(covid_cloud$`Province/State`,covid_cloud$Confirmed,random.order = FALSE,rot.per = .3,
scale = c(5,.8),max.words = 100,colors = brewer.pal(7,"Set1"))
```
```{r}
covid_cloud %>% filter(ObservationDate == "03/26/2020") %>%
group_by(`Country/Region`) %>%
summarise(confirmed_cases=sum(Confirmed),Casulty=sum(Deaths),Recovered_cases=sum(Recovered)) %>%
arrange(desc(confirmed_cases)) %>% head(5)
```
```{r}
ggplot(covid, aes(death, age, fill = death))+
geom_boxplot()+
theme_classic()+
scale_fill_manual(values = c('blue','red'))
```
```{r}
ggplot(covid, aes(death, fill = gender))+
geom_bar(position ='fill')+
theme_classic()+
scale_fill_manual(values = c('red','blue','black'))
```
```{r}
fit1 <- glm(death ~ age + gender, family=binomial(link="logit"), data=covid)
summary(fit1)
fit1
```
```{r}
c1 <- covid %>% add_predictions(fit1, type="response")
c1 %>% filter(death=="yes") %>% summarise(mean(pred),na.rm = TRUE)
summary(c1)
c1 %>% filter(death=="no" & pred_status=="no")
```
```{r}
predict(fit1, covid, type="response") %>% head()
```
```{r}
c1 <- c1 %>%
add_predictions(fit1, type="response") %>%
mutate(pred_status =ifelse(pred > 0.1, "yes", "no"))
#correct = death == pred_status )
#select(death, pred_status, correct)
c1 <- c1 %>%
mutate(
pred_status = factor(pred_status, label = c("no","yes"))
)
confusionMatrix(c1$pred_status, c1$death)
```
```{r}
cf %>% filter(death=="yes")
```
```{r}
c2<-covid %>%
add_predictions(fit1, type="response") %>%
mutate(pred4 = ifelse(pred > 0.5, "yes", "no"),
pred5 =ifelse(pred > 0.6, "yes", "no"),
pred6 =ifelse(pred > 0.7, "yes", "no")) %>%
summarize(acc4 = mean(death==pred4, na.rm=TRUE),
acc5 = mean(death==pred5, na.rm=TRUE),
acc6 =mean(death==pred6, na.rm=TRUE))
c2
```