-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCOVID19_MORTALITY
More file actions
169 lines (134 loc) · 5.34 KB
/
COVID19_MORTALITY
File metadata and controls
169 lines (134 loc) · 5.34 KB
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
require(RCurl)
require(foreign)
require(tidyverse) # To tip the df from long row of dates to cols (pivot_longer())
x = getURL("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")
corona <- read.csv(textConnection(x))
corona = (read_csv(x)
%>% pivot_longer(cols = -c(`Province/State`, `Country/Region`, Lat, Long),
names_to = "date",
values_to = "cases")
%>% select(`Province/State`,`Country/Region`, date, cases)
%>% mutate(date=as.Date(date,format="%m/%d/%y"))
%>% drop_na(cases)
%>% rename(country="Country/Region", provinces="Province/State")
)
cc <- (corona
%>% filter(country %in% c("Italy","Spain","US"))
)
ccw <- (cc
%>% pivot_wider(names_from="country",values_from="cases")
%>% filter(Italy>5)
)
plot(ccw$date, ccw$Italy, type="l", lwd=3, lty=3,
ylab='',
xlab='',
log='y',
main ='Log-lin COVID-19 deaths in Spain Italy and US',
col=4,
axes=FALSE,
cex.main=0.9)
at1 <- seq(min(ccw$date), max(ccw$date)+1, by=2);
axis.Date(1, at=at1, format="%b %d", las=2, cex.axis=0.7)
at2 <- 2^seq(1,30,by=1)
axis(side=2, at2, cex.axis=0.7, las=1)
abline(h=at2, lty=2, col="grey90") # Add faint grid lines
at1 <- seq(min(ccw$date), max(ccw$date)+1, by=1);
abline(v=at1, lty=2, col="grey90") # Add faint grid lines
y = getURL("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")
corona_death <- read.csv(textConnection(y))
corona_death = (read_csv(y)
%>% pivot_longer(cols = -c(`Province/State`, `Country/Region`, Lat, Long),
names_to = "date",
values_to = "cases")
%>% select(`Province/State`, `Country/Region`, date, cases)
%>% mutate(date=as.Date(date,format="%m/%d/%y"))
%>% drop_na(cases)
%>% rename(country="Country/Region")
%>% rename(state="Province/State")
)
ccd <- (corona_death
%>% filter(country %in% c("Spain", "Italy","US"))
)
ccwd <- (ccd
%>% pivot_wider(names_from="country",values_from="cases")
%>% filter(Italy>1)
)
lines(ccwd$date, ccwd$Italy, type="l", lwd=3, lty=1,
col=4, cex.main=0.9)
lines(ccwd$date, ccwd$Spain, lwd=3, col=2)
lines(ccwd$date, ccwd$US, lwd=3)
legend(ccw$date[1], 100000,
legend=c("Italy cases","Italy deaths", "Spain deaths", "US deaths"),
col=c(4, 4, 2, 1), lty=c(3,1,1,1), lwd=3, cex=0.8,
box.lty=0)
#ccdpred <- (corona_death
# %>% filter(country %in% c("Italy"))
#)
#ccwdpred <- (ccdpred
# %>% pivot_wider(names_from="country",values_from="cases")
# %>% filter(Italy>1)
#)
china <- corona_death[corona_death$country=='China',]
provinces <- c('Hubei', 'Guangdong', 'Henan', 'Zhejiang', 'Hunan', 'Anhui',
'Jiangxi','Shandong','Jiangsu','Sichuan','Heilongjiang','Hebei',
'Fujian','Guangxi','Shaanxi','Yunnan','Hainan','Guizhou','Shanxi',
'Gansu','Hong Kong','Liaoning','Jilin','Xinjiang','Inner Mongolia',
'Ningxia','Qinghai','Macau','Tibet')
china_prov <- china[is.element(china$state,provinces),]
ccchina <- china_prov[,2:4]
temp <- aggregate(ccchina[ ,3], FUN="sum", by=list(as.Date(ccchina$date)))
ccchina[1:nrow(temp),2:3] <- temp
ccchina <- ccchina[1:nrow(temp),]
#lines(ccchina$date, ccchina$cases, lwd=3, col=2)
abline(h=max(ccchina$cases))
legend(ccw$date[1], 3000, legend=c("Deaths in China"),
col=c(1), lty=c(1), lwd=1, cex=0.8,
box.lty=0)
plot(ccwd$date, ccwd$Italy, type="l", lwd=3, lty=1,
ylab='',
xlab='',
main ='COVID-19 deaths in Spain Italy and US',
col=4,
axes=FALSE,
cex.main=0.9)
at1 <- seq(min(ccw$date), max(ccw$date)+1, by=2);
axis.Date(1, at=at1, format="%b %d", las=2, cex.axis=0.7)
at2 <- seq(0,16000,by=1000)
axis(side=2, at2, cex.axis=0.7, las=1)
abline(h=at2, lty=2, col="grey90") # Add faint grid lines
at1 <- seq(min(ccw$date), max(ccw$date)+1, by=1);
abline(v=at1, lty=2, col="grey90") # Add faint grid lines
lines(ccwd$date, ccwd$Italy, lwd=3, col=4)
lines(ccwd$date, ccwd$Spain, lwd=3, col=2)
lines(ccwd$date, ccwd$US, lwd=3)
legend(ccw$date[1], 14000,
legend=c("Italy deaths", "Spain deaths", "US deaths"),
col=c(4, 2, 1), lty=c(1,1,1), lwd=3, cex=0.8,
box.lty=0)
first.der<-diff(ccwd$Italy, lag = 1, differences = 1)
sec.der <- diff(ccwd$Italy, lag = 1, differences = 2)
plot(ccwd$date[2:length(ccwd$date)-2], sec.der,
type="l", lwd=2, lty=1,
ylab='',
xlab='',
main ='Second differences COVID-19 deaths in Italy',
col="tan",
axes=FALSE,
cex.main=0.9)
abline(h=0)
at1 <- seq(min(ccw$date)+2, max(ccw$date), by=2);
axis.Date(1, at=at1, format="%b %d", las=2, cex.axis=0.7)
axis(side=2, seq(min(sec.der),max(sec.der),50),
las=2, cex.axis=0.7)
#require(tseries)
#require(forecast)
#require(astsa)
#dif<-diff(ccwdpred$Italy)
#fit = auto.arima(dif)
#pred = predict(fit, n.ahead = 50)
#ts.plot(dif, pred$pred, lty = c(1,3), col=c(5,2))
#gtemp_pred<-gtemp[length(gtemp)]
#for(i in 1:length(pred$pred)){
# gtemp_pred[i+1]<-gtemp_pred[i]+pred$pred[i]
#}
#plot(c(gtemp,gtemp_pred),type="l")