-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContagiRestrizioni.R
161 lines (139 loc) · 6.23 KB
/
ContagiRestrizioni.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
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
library(sm)
library(gam)
library(fpp2)
library(lmtest)
library(DIMORA)
#library(rpanel)
library(splines)
library(ggplot2)
library(forecast)
library(lubridate)
source("support.R")
source("complexitynonparam.R")
# - Amazon #FF9B00
# - Netflix #E50914
# - Zoom #2D8CFF
# Import data----
AMZN_weekly <- read.timeseries.stocks("./data/AMZN_weekly.csv")
NFLX_weekly <- read.timeseries.stocks("./data/NFLX_weekly.csv")
ZOOM_weekly <- read.timeseries.stocks("./data/ZM_weekly.csv")
ZOOM_weekly <- backcast.ZOOM(ZOOM_weekly)
Google_Trends <- read.csv("./data/Google Trends Data.csv",
na = "0", skip = 1)
names(Google_Trends) <- c("Date", "Amazon", "Netflix", "Zoom")
covid.data <- read.covid.data("./data/Contagi_and_restrictions.csv")
names(covid.data) <- c("Date", "New_cases", "AvgStringencyIndex")
### AMZN stock----
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, AMZN_weekly$Close,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Avg Stringency Index & AMZN", col = "#FF9B00") # first plot
par(new = TRUE)
plot(covid.data$Date, covid.data$AvgStringencyIndex,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$AvgStringencyIndex)))
mtext("z", side=4, line=3)
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, AMZN_weekly$Close,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Weekly COVID cases & AMZN", col = "#FF9B00")
par(new = TRUE)
plot(covid.data$Date, covid.data$New_cases,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$New_cases)))
mtext("z", side=4, line=3)
### NFLX stock----
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, NFLX_weekly$Close,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Avg Stringency Index & NFLX", col = "#E50914")
par(new = TRUE)
plot(covid.data$Date, covid.data$AvgStringencyIndex,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$AvgStringencyIndex)))
mtext("z", side=4, line=3)
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, NFLX_weekly$Close,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Weekly COVID cases & NFLX", col = "#E50914") # first plot
par(new = TRUE)
plot(covid.data$Date, covid.data$New_cases,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$New_cases)))
mtext("z", side=4, line=3)
### ZOOM stock----
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, ZOOM_weekly$Close,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Avg Stringency Index & ZM", col = "#2D8CFF")
par(new = TRUE)
plot(covid.data$Date, covid.data$AvgStringencyIndex,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$AvgStringencyIndex)))
mtext("z", side=4, line=3)
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, ZOOM_weekly$Close,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Weekly COVID cases & ZM", col = "#2D8CFF") # first plot
par(new = TRUE)
plot(covid.data$Date, covid.data$New_cases,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$New_cases)))
mtext("z", side=4, line=3)
### AMZN trends----
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, Google_Trends$Amazon,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Avg Stringency Index & Amazon popularity", col = "#FF9B00")
par(new = TRUE)
plot(covid.data$Date, covid.data$AvgStringencyIndex,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$AvgStringencyIndex)))
mtext("z", side=4, line=3)
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, Google_Trends$Amazon,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Weekly COVID cases & Amazon popularity", col = "#FF9B00")
par(new = TRUE)
plot(covid.data$Date, covid.data$New_cases,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$New_cases)))
mtext("z", side=4, line=3)
### NFLX trends----
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, Google_Trends$Netflix,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Avg Stringency Index & Netflix popularity", col = "#E50914")
par(new = TRUE)
plot(covid.data$Date, covid.data$AvgStringencyIndex,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$AvgStringencyIndex)))
mtext("z", side=4, line=3)
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, Google_Trends$Netflix,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Weekly COVID cases & Netflix popularity", col = "#E50914")
par(new = TRUE)
plot(covid.data$Date, covid.data$New_cases,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$New_cases)))
mtext("z", side=4, line=3)
### ZOOM trends----
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, Google_Trends$Zoom,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Avg Stringency Index & Zoom popularity", col = "#2D8CFF")
par(new = TRUE)
plot(covid.data$Date, covid.data$AvgStringencyIndex,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$AvgStringencyIndex)))
mtext("z", side=4, line=3)
par(mar = c(5.1, 4.1, 4.1, 2.1) + 0.3) # Leave space for z axis
plot(covid.data$Date, Google_Trends$Zoom,
type = "l", lwd = 2, xlab = "Time", ylab = "",
main = "Weekly COVID cases & Zoom popularity", col = "#2D8CFF")
par(new = TRUE)
plot(covid.data$Date, covid.data$New_cases,
type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "", lwd = 2)
axis(side=4, at = pretty(range(covid.data$New_cases)))
mtext("z", side=4, line=3)