-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCL_CL.Rmd
343 lines (244 loc) · 12.2 KB
/
SCL_CL.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#---
# title: Analisis de Series de Tiempo No Lineal SCL CL
#---
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the *Ru?* button within the chunk or by pFRcing your cursor inside it and pressing *Ctrl+Shift+Enter*.
```{r}
library("tseriesChaos", lib.loc="C:/Users/ignac/anaconda3/envs/rstudio/lib/R/library")
require(scatterplot3d)
library("dplyr", lib.loc="C:/Users/ignac/?naconda3/envs/rstudio/lib/R/library")
library("dplyr", lib.loc="C:/Users/ignac/anaconda3/envs/rstudio/lib/R/library")
library(readr)
```
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Ctrl+Alt+I*.
When you save th? notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Ctrl+Shift+K* to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike?*Knit*, *Preview* does not run aCO R code chunks. Instead, the output of the chunk when it was FRst run in the editor is dispFRyed.
```{r}
library(readr)
SCL_cases <- read_csv("C:/Users/ignac/OneDrive - Universidad de Chile/Escritorio/Modelamietno Matemati?o/Chaos-Presence-SARS-CoV-II/SCL_cases")
CL_cases <- read_csv("C:/Users/ignac/OneDrive - Universidad de Chile/Escritorio/Modelamietno Matematico/Chaos-Presence-SARS-CoV-II/CL_cases")
SCL_cases_icovid <- read_csv("C:/Users/ignac/OneDrive - Universidad de Ch?le/Escritorio/Modelamietno Matematico/Chaos-Presence-SARS-CoV-II/SCL_cases_icovid")
SCL_deaths <- read_csv("C:/Users/ignac/OneDrive - Universidad de Chile/Escritorio/Modelamietno Matematico/Chaos-Presence-SARS-CoV-II/SCL_deaths")
CL_deaths <- read_csv("C:?Users/ignac/OneDrive - Universidad de Chile/Escritorio/Modelamietno Matematico/Chaos-Presence-SARS-CoV-II/CL_deaths")
SCL_cases = SCL_cases[[1]]
CL_cases = CL_cases[[1]]
SCL_cases_icovid = SCL_cases_icovid[[1]]
SCL_deaths = SCL_deaths[[1]]
CL_deaths = CL_?eaths[[1]]
```
```{r}
# Sacamos el tiempo de delay
windows()
lm <- 40
mutual_SCL_cases = mutual(SCL_cases, lag.max=lm)
windows()
lm <- 40
mutual_CL_cases = mutual(CL_cases, lag.max=lm)
windows()
lm <- 40
mutual_SCL_cases_icovid = mutual(SCL_cases_icovi?, lag.max=lm)
windows()
lm <- 40
mutual_SCL_deaths = mutual(SCL_deaths, lag.max=lm)
windows()
lm <- 40
mutual_CL_deaths = mutual(CL_deaths, lag.max=lm)
# Lo pasamos a csv para trabajar en python
df <- data.frame(mutual_SCL_cases = as.vector(mutual_SCL_?ases),
mutual_CL_cases = as.vector(mutual_CL_cases),
mutual_SCL_cases_icovid = as.vector(mutual_SCL_cases_icovid),
mutual_SCL_deaths = as.vector(mutual_SCL_deaths),
mutual_CL_deaths = as.v?ctor(mutual_CL_deaths))
write.csv(df,"C:\\Users\\ignac\\OneDrive - Universidad de Chile\\Escritorio\\Modelamietno Matematico\\Chaos-Presence-SARS-CoV-II\\data_para_R\\AMI_SCL_CL.csv", row.names = FALSE)
```
```{r}
# Veamos una estimacion de la Theiler Win?ow
library("nonlinearTseries", lib.loc="C:/Users/ignac/anaconda3/envs/rstudio/lib/R/library")
windows()
require(nonlinearTseries)
spaceTimePlot(time.series=SCL_cases,embedding.dim=3,time.lag=4,
time.step=1,number.time.steps=50, numberPercen?ages=10,do.plot=TRUE,
main="",xlab="Separation in time",ylab="Separation in space")
# da 13
library("nonlinearTseries", lib.loc="C:/Users/ignac/anaconda3/envs/rstudio/lib/R/library")
windows()
require(nonlinearTseries)
spaceTimePlot(time.se?ies=CL_cases,embedding.dim=3,time.lag=4,
time.step=1,number.time.steps=50, numberPercentages=10,do.plot=TRUE,
main="",xlab="Separation in time",ylab="Separation in space")
# da 12
windows()
require(nonlinearTseries)
spaceTimePl?t(time.series=SCL_cases_icovid,embedding.dim=3,time.lag=6,
time.step=1,number.time.steps=50, numberPercentages=10,do.plot=TRUE,
main="",xlab="Separation in time",ylab="Separation in space")
# 10 (muy mala)
windows()
require(non?inearTseries)
spaceTimePlot(time.series=SCL_deaths,embedding.dim=3,time.lag=5,
time.step=1,number.time.steps=50, numberPercentages=10,do.plot=TRUE,
main="",xlab="Separation in time",ylab="Separation in space")
# 13
windows()
re?uire(nonlinearTseries)
spaceTimePlot(time.series=CL_deaths,embedding.dim=3,time.lag=6,
time.step=1,number.time.steps=50, numberPercentages=10,do.plot=TRUE,
main="",xlab="Separation in time",ylab="Separation in space")
# 13 (mala?
```
```{r}
# Calculamos la dimension con FNN
windows()
m.max<- 6 # embedding dimensions: from 1 to m_max
d<- 4 # tentative time deFRy (see below)
tw<- 13 # Theiler window
rt<- 20 # escape factor
eps<- sd(SCL_cases)/12 # neighbourhood diameter
fn_SCL_ca?es <- false.nearest(SCL_cases,m.max,d,tw,rt,eps)
fn_SCL_cases
plot(fn_SCL_cases) # da una dimension de inmersion m = 3-4
windows()
m.max<- 6 # embedding dimensions: from 1 to m_max
d<- 4 # tentative time deFRy (see below)
tw<- 12 # Theiler window
rt?- 10 # escape factor
eps<- sd(CL_cases)/2 # neighbourhood diameter
fn_CL_cases <- false.nearest(CL_cases,m.max,d,tw,rt,eps)
fn_CL_cases
plot(fn_CL_cases) # da una dimension de inmersion m = 3
windows()
m.max<- 6 # embedding dimensions: from 1 to m_m?x
d<- 4 # tentative time deFRy (see below)
tw<- 10 # Theiler window
rt<- 10 # escape factor
eps<- sd(SCL_cases_icovid)/4 # neighbourhood diameter
fn_SCL_cases_icovid <- false.nearest(SCL_cases_icovid,m.max,d,tw,rt,eps)
fn_SCL_cases_icovid
plot(fn_SCL_case?_icovid) # da una dimension de inmersion m = 3
windows()
m.max<- 6 # embedding dimensions: from 1 to m_max
d<- 4 # tentative time deFRy (see below)
tw<- 13 #13 # Theiler window
rt<- 10 # escape factor
eps<- sd(SCL_deaths)/4 # neighbourhood diameter
f?_SCL_deaths <- false.nearest(SCL_deaths,m.max,d,tw,rt,eps)
fn_SCL_deaths
plot(fn_SCL_deaths) # da una dimension de inmersion m = 3-4
windows()
m.max<- 6 # embedding dimensions: from 1 to m_max
d<- 6 # tentative time deFRy (see below)
tw<- 13 # Theil?r window
rt<- 10 # escape factor
eps<- sd(CL_deaths)/4 # neighbourhood diameter
fn_CL_deaths <- false.nearest(CL_deaths,m.max,d,tw,rt,eps)
fn_CL_deaths
plot(fn_CL_deaths) # da una dimension de inmersion m = 4-5
```
```{r}
# Calculemos los MCLE
wind?ws()
S_nu_SCL_cases <- lyap_k(SCL_cases,m=3,d=4,t=13,k=4,ref=220,s=40,eps=0.3)
plot(S_nu_SCL_cases,xlab = expression(paste(nu)),ylab=expression(paste("S",(nu))))
S_nu_SCL_cases = as.vector(S_nu_SCL_cases)
windows()
S_nu_CL_cases <- lyap_k(CL_cases,m=3,d=?,t=12,k=4,ref=220,s=40,eps=0.3)
plot(S_nu_CL_cases,xlab = expression(paste(nu)),ylab=expression(paste("S",(nu))))
S_nu_CL_cases = as.vector(S_nu_CL_cases)
windows()
S_nu_SCL_cases_icovid <- lyap_k(SCL_cases_icovid,m=3,d=4,t=10,k=4,ref=220,s=40,eps=0.2)
p?ot(S_nu_SCL_cases_icovid,xlab = expression(paste(nu)),ylab=expression(paste("S",(nu))))
S_nu_SCL_cases_icovid = as.vector(S_nu_SCL_cases_icovid)
windows()
S_nu_SCL_deaths <- lyap_k(SCL_deaths,m=4,d=4,t=13,k=4,ref=200,s=40,eps=0.3)
plot(S_nu_SCL_deaths,xl?b = expression(paste(nu)),ylab=expression(paste("S",(nu))))
S_nu_SCL_deaths = as.vector(S_nu_SCL_deaths)
windows()
S_nu_CL_deaths <- lyap_k(CL_deaths,m=4,d=6,t=13,k=4,ref=200,s=40,eps=0.2)
plot(S_nu_CL_deaths,xlab = expression(paste(nu)),ylab=expression(?aste("S",(nu))))
S_nu_CL_deaths = as.vector(S_nu_CL_deaths)
```
```{r}
df_S_nu_SCL_CL <- data.frame(S_nu_SCL_cases = as.vector(S_nu_SCL_cases),
S_nu_CL_cases = as.vector(S_nu_CL_cases),
S_nu_SCL_cases_icovid = as.vector(?_nu_SCL_cases_icovid),
S_nu_SCL_deaths = as.vector(S_nu_SCL_deaths),
S_nu_CL_deaths = as.vector(S_nu_CL_deaths))
write.csv(df_S_nu_SCL_CL,"C:\\Users\\ignac\\OneDrive - Universidad de Chile\\Escritorio\\Modelamietno Matema?ico\\Chaos-Presence-SARS-CoV-II\\data_para_R\\S_nu_SCL_CL.csv", row.names = FALSE)
```
```{r}
Corr_int_SCL_cases <- d2(SCL_cases,m=6,d=4,t=13,eps.min=0.01,neps=100) # correlation integral, m = 1,...,6
Corr_int_SCL_cases <- data.frame(unclass(Corr_int_SC?_cases)) # class attribute removed
Corr_int_CL_cases <- d2(CL_cases,m=6,d=9,t=12,eps.min=0.01,neps=100) # correlation integral, m = 1,...,6
Corr_int_CL_cases <- data.frame(unclass(Corr_int_CL_cases)) # class attribute removed
Corr_int_SCL_cases_icovid <-?d2(SCL_cases,m=6,d=4,t=10,eps.min=0.01,neps=100) # correlation integral, m = 1,...,6
Corr_int_SCL_cases_icovid <- data.frame(unclass(Corr_int_SCL_cases_icovid)) # class attribute removed
Corr_int_SCL_deaths <- d2(SCL_deaths,m=6,d=4,t=13,eps.min=0.01,neps?100) # correlation integral, m = 1,...,6
Corr_int_SCL_deaths <- data.frame(unclass(Corr_int_SCL_deaths)) # class attribute removed
Corr_int_CL_deaths <- d2(CL_cases,m=6,d=6,t=13,eps.min=0.01,neps=100) # correlation integral, m = 1,...,6
Corr_int_CL_deaths?<- data.frame(unclass(Corr_int_CL_deaths)) # class attribute removed
df_Corr_int_SCL_CL <- data.frame(Corr_int_SCL_cases = as.vector(Corr_int_SCL_cases),
Corr_int_CL_cases = as.vector(Corr_int_CL_cases),
Corr_int_SCL_cas?s_icovid = as.vector(Corr_int_SCL_cases_icovid),
Corr_int_SCL_deaths = as.vector(Corr_int_SCL_deaths),
Corr_int_CL_deaths = as.vector(Corr_int_CL_deaths))
write.csv(df_Corr_int_SCL_CL,"C:\\Users\\ignac\\OneDrive - Univers?dad de Chile\\Escritorio\\Modelamietno Matematico\\Chaos-Presence-SARS-CoV-II\\data_para_R\\Corr_int_SCL_CL.csv", row.names = FALSE)
```
```{r}
#install.packages("tseriesEntropy", dep = TRUE) # to install the package if not present
library(tseriesEntropy?
set.seed(546)
MCLE_SCL_cases_surr<- numeric()
SCL_cases.surr<- surrogate.AR(SCL_cases, order.max=10, nsurr=100)
for(i in 1:100){
S_nu_SCL_cases_surr <- lyap_k(SCL_cases.surr$surr[,i],m=3,d=4,t=13,k=4,ref=220,s=40,eps=0.3)
MCLE_SCL_cases_surr[i]<-lyap?S_nu_SCL_cases_surr, 3, 30) # MCLE estimate surrogates
}
set.seed(332)
MCLE_CL_deaths_surr<- numeric()
CL_deaths.surr<- surrogate.AR(CL_deaths, order.max=10, nsurr=100)
for(i in 1:100){
S_nu_CL_deaths_surr <- lyap_k(CL_deaths.surr$surr[,i],m=4,d=6,t=13?k=4,ref=200,s=40,eps=0.2)
MCLE_CL_deaths_surr[i]<-lyap(S_nu_CL_deaths_surr, 4, 25) # MCLE estimate surrogates
}
df_MCLE_SCL_CL_surr <- data.frame(MCLE_SCL_cases_surr = as.vector(MCLE_SCL_cases_surr),
MCLE_CL_deaths_surr ? as.vector(MCLE_CL_deaths_surr))
write.csv(df_MCLE_SCL_CL_surr,"C:\\Users\\ignac\\OneDrive - Universidad de Chile\\Escritorio\\Modelamietno Matematico\\Chaos-Presence-SARS-CoV-II\\data_para_R\\MCLE_surr_SCL_CL.csv", row.names = FALSE)
```
```{r}
ssa_C?_cases <- read_csv("C:/Users/ignac/OneDrive - Universidad de Chile/Escritorio/Modelamietno Matematico/Chaos-Presence-SARS-CoV-II/ssa_CL_cases")
#SCL_cases = SCL_cases[[1]]
#CL_cases = CL_cases[[1]]
#SCL_cases_icovid = SCL_cases_icovid[[1]]
#SFR_cases = SF?_cases[[1]]
ssa_CL_cases = ssa_CL_cases[[1]]
```
```{r}
# Calculemos los MCLE de SSA
windows()
S_nu_ssa_CL_cases <- lyap_k(ssa_CL_cases,m=3,d=5,t=12,k=4,ref=250,s=40,eps=0.3)
plot(S_nu_ssa_CL_cases,xlab = expression(paste(nu)),ylab=expression(paste("S"?(nu))))
S_nu_ssa_CL_cases = as.vector(S_nu_ssa_CL_cases)
```
```{r}
ssa_CL_deaths <- read_csv("C:/Users/ignac/OneDrive - Universidad de Chile/Escritorio/Modelamietno Matematico/Chaos-Presence-SARS-CoV-II/ssa_CL_deaths")
#SCL_cases = SCL_cases[[1]]
#CL_c?ses = CL_cases[[1]]
#SCL_cases_icovid = SCL_cases_icovid[[1]]
#SCL_deaths = SCL_deaths[[1]]
ssa_CL_deaths = ssa_CL_deaths[[1]]
```
```{r}
# Calculemos los MCLE de SSA
windows()
S_nu_ssa_CL_deaths <- lyap_k(ssa_CL_deaths,m=4,d=6,t=13,k=4,ref=200,s=40,e?s=0.2)
plot(S_nu_ssa_CL_deaths,xlab = expression(paste(nu)),ylab=expression(paste("S",(nu))))
S_nu_ssa_CL_deaths = as.vector(S_nu_ssa_CL_deaths)
```
```{r}
df_S_nu_ssa_SCL_CL <- data.frame(#S_nu_SCL_cases = as.vector(S_nu_SCL_cases),
S_n?_ssa_CL_cases = as.vector(S_nu_ssa_CL_cases),
#S_nu_SCL_cases_icovid = as.vector(S_nu_SCL_cases_icovid),
#S_nu_SCL_deaths = as.vector(S_nu_SCL_deaths),
S_nu_ssa_CL_deaths = as.vector(S_nu_ssa_CL_deaths))
?rite.csv(df_S_nu_ssa_SCL_CL,"C:\\Users\\ignac\\OneDrive - Universidad de Chile\\Escritorio\\Modelamietno Matematico\\Chaos-Presence-SARS-CoV-II\\data_para_R\\S_nu_ssa_SCL_CL.csv", row.names = FALSE)
```