-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 33.5 KB
/
.Rhistory
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
w_write("## ntranのVARモデル", append=F, file="ntran_sum.csv")
w_write("## toutvのVARモデル", append=F, file="toutv_sum.csv")
w_write("## toutvのVARモデル", append=F)
w_write("## ntranのVARモデル", append=F, f="ntran_sum.csv")
w_write("## ntranのVARモデル", append=F, f="ntran_sum.")
knitr::opts_chunk$set(echo = TRUE)
library(RPostgreSQL)
library(tseries)
library(xts)
library(zoo)
library(knitr)
library(kableExtra)
library(vars)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,dbname="bitcoin",host="localhost",port=5432,user="takumi",password="takumi")
options(digits=5)
options(scipen=20)
w_adf.test <- function(x) { return(suppressWarnings(adf.test(x))) }
w_kable_styling <- function(x) { return(kable_styling(x, bootstrap_options = c("striped", "hover"))) }
vm_1_aic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_1_sic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=2, type="const")
vm_2_aic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=7, type="const")
vm_2_sic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=3, type="const")
vm_3_aic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_3_sic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=3, type="const")
names <- c("VAR(8) - toutv - 1st AIC", "VAR(2) - toutv - 2nd AIC", "VAR(7) - toutv - 3rd AIC", "VAR(3) - toutv - 1st SIC", "VAR(8) - toutv - 2nd SIC", "VAR(3) - toutv - 3rd SIC")
write("## toutvのVARモデル", append=T, file="toutv_sum.csv")
sums <- list(summary(vm_1_aic)[[2]][[1]], summary(vm_2_aic)[[2]][1], summary(vm_3_aic)[[2]][1], summary(vm_1_sic)[[2]][1], summary(vm_2_sic)[[2]][1], summary(vm_3_sic)[[2]][1])
for ( i in 1:6) {
sum_out <- capture.output(sums[i])
write("#####", append=T, file="toutv_sum.csv")
write(names[[i]], append=T, file="toutv_sum.csv")
write("Call:", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Call:", sum_out) + 1]], append=T, file="toutv_sum.csv")
write("Residuals:", append=T, file="toutv_sum.csv")
write.table(as.list(summary(sum$residuals)), append=T, file="toutv_sum.csv", sep=",", row.names=F)
write("Coefficients:", append=T, file="toutv_sum.csv")
write.table(sum$coefficients, append=T, file="toutv_sum.csv", sep=",")
write("---", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Signif. codes:", sum_out)]], append=T, file="toutv_sum.csv")
write("Multiple R-squared:", append=T, file="toutv_sum.csv")
write(sum$r.squared, append=T, file="toutv_sum.csv")
write("Adjusted R-squared:", append=T, file="toutv_sum.csv")
write(sum$adj.r.squared, append=T, file="toutv_sum.csv")
write(sum_out[grep("^F-statistic:", sum_out)], append=T, file="toutv_sum.csv")
write("#####", append=T, file="toutv_sum.csv")
}
options(warn=-1)
vm_1_aic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_1_sic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=2, type="const")
vm_2_aic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=7, type="const")
vm_2_sic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=3, type="const")
vm_3_aic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_3_sic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=3, type="const")
names <- c("VAR(8) - toutv - 1st AIC", "VAR(2) - toutv - 2nd AIC", "VAR(7) - toutv - 3rd AIC", "VAR(3) - toutv - 1st SIC", "VAR(8) - toutv - 2nd SIC", "VAR(3) - toutv - 3rd SIC")
write("## toutvのVARモデル", append=T, file="toutv_sum.csv")
sums <- list(summary(vm_1_aic)[[2]][[1]], summary(vm_2_aic)[[2]][1], summary(vm_3_aic)[[2]][1], summary(vm_1_sic)[[2]][1], summary(vm_2_sic)[[2]][1], summary(vm_3_sic)[[2]][1])
for ( i in 1:6) {
sum_out <- capture.output(sums[i])
write("#####", append=T, file="toutv_sum.csv")
write(names[[i]], append=T, file="toutv_sum.csv")
write("Call:", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Call:", sum_out) + 1]], append=T, file="toutv_sum.csv")
write("Residuals:", append=T, file="toutv_sum.csv")
write.table(as.list(summary(sum$residuals)), append=T, file="toutv_sum.csv", sep=",", row.names=F)
write("Coefficients:", append=T, file="toutv_sum.csv")
write.table(sum$coefficients, append=T, file="toutv_sum.csv", sep=",")
write("---", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Signif. codes:", sum_out)]], append=T, file="toutv_sum.csv")
write("Multiple R-squared:", append=T, file="toutv_sum.csv")
write(sum$r.squared, append=T, file="toutv_sum.csv")
write("Adjusted R-squared:", append=T, file="toutv_sum.csv")
write(sum$adj.r.squared, append=T, file="toutv_sum.csv")
write(sum_out[grep("^F-statistic:", sum_out)], append=T, file="toutv_sum.csv")
write("#####", append=T, file="toutv_sum.csv")
}
vm_1_aic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_1_sic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=2, type="const")
vm_2_aic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=7, type="const")
vm_2_sic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=3, type="const")
vm_3_aic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_3_sic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=3, type="const")
names <- c("VAR(8) - toutv - 1st AIC", "VAR(2) - toutv - 2nd AIC", "VAR(7) - toutv - 3rd AIC", "VAR(3) - toutv - 1st SIC", "VAR(8) - toutv - 2nd SIC", "VAR(3) - toutv - 3rd SIC")
write("## toutvのVARモデル", append=T, file="toutv_sum.csv")
sums <- list(summary(vm_1_aic)[[2]][[1]], summary(vm_2_aic)[[2]][1], summary(vm_3_aic)[[2]][1], summary(vm_1_sic)[[2]][1], summary(vm_2_sic)[[2]][1], summary(vm_3_sic)[[2]][1])
options(warn=-1)
for ( i in 1:6) {
sum_out <- capture.output(sums[i])
write("#####", append=T, file="toutv_sum.csv")
write(names[[i]], append=T, file="toutv_sum.csv")
write("Call:", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Call:", sum_out) + 1]], append=T, file="toutv_sum.csv")
write("Residuals:", append=T, file="toutv_sum.csv")
write.table(as.list(summary(sum$residuals)), append=T, file="toutv_sum.csv", sep=",", row.names=F)
write("Coefficients:", append=T, file="toutv_sum.csv")
write.table(sum$coefficients, append=T, file="toutv_sum.csv", sep=",")
write("---", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Signif. codes:", sum_out)]], append=T, file="toutv_sum.csv")
write("Multiple R-squared:", append=T, file="toutv_sum.csv")
write(sum$r.squared, append=T, file="toutv_sum.csv")
write("Adjusted R-squared:", append=T, file="toutv_sum.csv")
write(sum$adj.r.squared, append=T, file="toutv_sum.csv")
write(sum_out[grep("^F-statistic:", sum_out)], append=T, file="toutv_sum.csv")
write("#####", append=T, file="toutv_sum.csv")
}
vm_1_aic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_1_sic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=2, type="const")
vm_2_aic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=7, type="const")
vm_2_sic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=3, type="const")
vm_3_aic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_3_sic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=3, type="const")
options(warn=-1)
names <- c("VAR(8) - toutv - 1st AIC", "VAR(2) - toutv - 2nd AIC", "VAR(7) - toutv - 3rd AIC", "VAR(3) - toutv - 1st SIC", "VAR(8) - toutv - 2nd SIC", "VAR(3) - toutv - 3rd SIC")
write("## toutvのVARモデル", append=T, file="toutv_sum.csv")
sums <- list(summary(vm_1_aic)[[2]][[1]], summary(vm_2_aic)[[2]][1], summary(vm_3_aic)[[2]][1], summary(vm_1_sic)[[2]][1], summary(vm_2_sic)[[2]][1], summary(vm_3_sic)[[2]][1])
for ( i in 1:6) {
sum_out <- capture.output(sums[i])
write("#####", append=T, file="toutv_sum.csv")
write(names[[i]], append=T, file="toutv_sum.csv")
write("Call:", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Call:", sum_out) + 1]], append=T, file="toutv_sum.csv")
write("Residuals:", append=T, file="toutv_sum.csv")
write.table(as.list(summary(sum$residuals)), append=T, file="toutv_sum.csv", sep=",", row.names=F)
write("Coefficients:", append=T, file="toutv_sum.csv")
write.table(sum$coefficients, append=T, file="toutv_sum.csv", sep=",")
write("---", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Signif. codes:", sum_out)]], append=T, file="toutv_sum.csv")
write("Multiple R-squared:", append=T, file="toutv_sum.csv")
write(sum$r.squared, append=T, file="toutv_sum.csv")
write("Adjusted R-squared:", append=T, file="toutv_sum.csv")
write(sum$adj.r.squared, append=T, file="toutv_sum.csv")
write(sum_out[grep("^F-statistic:", sum_out)], append=T, file="toutv_sum.csv")
write("#####", append=T, file="toutv_sum.csv")
}
knitr::opts_chunk$set(echo = TRUE)
library(RPostgreSQL)
library(tseries)
library(xts)
library(zoo)
library(knitr)
library(kableExtra)
library(vars)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,dbname="bitcoin",host="localhost",port=5432,user="takumi",password="takumi")
options(digits=5)
options(scipen=20)
w_adf.test <- function(x) { return(suppressWarnings(adf.test(x))) }
w_kable_styling <- function(x) { return(kable_styling(x, bootstrap_options = c("striped", "hover"))) }
vm_1_aic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_1_sic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=2, type="const")
vm_2_aic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=7, type="const")
vm_2_sic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=3, type="const")
vm_3_aic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_3_sic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=3, type="const")
names <- c("VAR(8) - toutv - 1st AIC", "VAR(2) - toutv - 2nd AIC", "VAR(7) - toutv - 3rd AIC", "VAR(3) - toutv - 1st SIC", "VAR(8) - toutv - 2nd SIC", "VAR(3) - toutv - 3rd SIC")
write("## toutvのVARモデル", file="toutv_sum.csv")
sums <- list(summary(vm_1_aic)[[2]][[1]], summary(vm_2_aic)[[2]][1], summary(vm_3_aic)[[2]][1], summary(vm_1_sic)[[2]][1], summary(vm_2_sic)[[2]][1], summary(vm_3_sic)[[2]][1])
for ( i in 1:6) {
sum_out <- capture.output(sums[i])
write("#####", append=T, file="toutv_sum.csv")
write(names[[i]], append=T, file="toutv_sum.csv")
write("Call:", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Call:", sum_out) + 1]], append=T, file="toutv_sum.csv")
write("Residuals:", append=T, file="toutv_sum.csv")
write.table(as.list(summary(sum$residuals)), append=T, file="toutv_sum.csv", sep=",", row.names=F)
write("Coefficients:", append=T, file="toutv_sum.csv")
write.table(sum$coefficients, append=T, file="toutv_sum.csv", sep=",")
write("---", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Signif. codes:", sum_out)]], append=T, file="toutv_sum.csv")
write("Multiple R-squared:", append=T, file="toutv_sum.csv")
write(sum$r.squared, append=T, file="toutv_sum.csv")
write("Adjusted R-squared:", append=T, file="toutv_sum.csv")
write(sum$adj.r.squared, append=T, file="toutv_sum.csv")
write(sum_out[grep("^F-statistic:", sum_out)], append=T, file="toutv_sum.csv")
write("#####", append=T, file="toutv_sum.csv")
}
vm_1_aic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_1_sic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(6,2,7:10,12:13,16)])), p=2, type="const")
vm_2_aic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=7, type="const")
vm_2_sic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(6,2,7:10,12:13,16)])), p=3, type="const")
vm_3_aic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=8, type="const")
vm_3_sic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(6,2,7:10,12:13,16)])), p=3, type="const")
names <- c("VAR(8) - toutv - 1st AIC", "VAR(2) - toutv - 2nd AIC", "VAR(7) - toutv - 3rd AIC", "VAR(3) - toutv - 1st SIC", "VAR(8) - toutv - 2nd SIC", "VAR(3) - toutv - 3rd SIC")
write("## toutvのVARモデル", file="toutv_sum.csv")
sums <- list(summary(vm_1_aic)[[2]][[1]], summary(vm_2_aic)[[2]][1], summary(vm_3_aic)[[2]][1], summary(vm_1_sic)[[2]][1], summary(vm_2_sic)[[2]][1], summary(vm_3_sic)[[2]][1])
for ( i in 1:6) {
sum_out <- capture.output(sums[i])
write("#####", append=T, file="toutv_sum.csv")
write(names[[i]], append=T, file="toutv_sum.csv")
write("Call:", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Call:", sum_out) + 1]], append=T, file="toutv_sum.csv")
write("Residuals:", append=T, file="toutv_sum.csv")
write.table(as.list(summary(sum$residuals)), append=T, file="toutv_sum.csv", sep=",", row.names=F)
write("Coefficients:", append=T, file="toutv_sum.csv")
write.table(sum$coefficients, append=T, file="toutv_sum.csv", sep=",")
write("---", append=T, file="toutv_sum.csv")
write(sum_out[[grep("^Signif. codes:", sum_out)]], append=T, file="toutv_sum.csv")
write("Multiple R-squared:", append=T, file="toutv_sum.csv")
write(sum$r.squared, append=T, file="toutv_sum.csv")
write("Adjusted R-squared:", append=T, file="toutv_sum.csv")
write(sum$adj.r.squared, append=T, file="toutv_sum.csv")
write(sum_out[grep("^F-statistic:", sum_out)], append=T, file="toutv_sum.csv")
write("#####", append=T, file="toutv_sum.csv")
}
knitr::opts_chunk$set(echo = TRUE)
library(RPostgreSQL)
library(tseries)
library(xts)
library(zoo)
library(knitr)
library(kableExtra)
library(vars)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,dbname="bitcoin",host="localhost",port=5432,user="takumi",password="takumi")
options(digits=5)
options(scipen=20)
w_kable_styling <- function(x) { return(kable_styling(x, bootstrap_options = c("striped", "hover"))) }
bc_mean_1 <- apply(bc[bc$phase==1,2:15], 2, mean, na.rm=TRUE)
bc_mean_2 <- apply(bc[bc$phase==2,2:15], 2, mean, na.rm=TRUE)
bc_mean_3 <- apply(bc[bc$phase==3,2:15], 2, mean, na.rm=TRUE)
bcd_mean_1 <- apply(bcd[bcd$phase==1,2:15], 2, mean, na.rm=TRUE)
bcd_mean_2 <- apply(bcd[bcd$phase==2,2:15], 2, mean, na.rm=TRUE)
bcd_mean_3 <- apply(bcd[bcd$phase==3,2:15], 2, mean, na.rm=TRUE)
mean_table <- data.frame(BC_1=bc_mean_1, BC_2=bc_mean_2, BC_3=bc_mean_3, BCD_1=bcd_mean_1, BCD_2=bcd_mean_2, BCD_3=bcd_mean_3)
write.table(mean_table, "mean_table.csv", sep=",")
w_kable_styling(kable(mean_table, caption="Mean"))
plot(bc$date, bc$ntran, type="l", main="Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
plot(bcd$date, bcd$dntran, type="l", main="DELTA Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
acf(bc[bc$phase==1,]$ntran, lag.max=30)
acf(bc[bc$phase==2,]$ntran, lag.max=30)
acf(bc[bc$phase==3,]$ntran, lag.max=30)
acf(bcd[bcd$phase==1,]$dntran, lag.max=30)
acf(bcd[bcd$phase==2,]$dntran, lag.max=30)
acf(bcd[bcd$phase==3,]$dntran, lag.max=30)
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bc[bc$phase==1,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bc[bc$phase==2,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bc[bc$phase==3,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bc[bc$phase==1,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bc[bc$phase==2,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bc[bc$phase==3,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box <- t(data.frame("Qm_1"=stats_1, "p-value_1"=pv_1, "Qm_2"=stats_2, "p-value_2"=pv_2,"Qm_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(ljung_box, caption="Ljung-Box"))
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box <- t(data.frame("Qm_1"=stats_1, "p-value_1"=pv_1, "Qm_2"=stats_2, "p-value_2"=pv_2,"Qm_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(ljung_box, caption="Ljung-Box"))
stats_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[1]], adf.test(bcd[bcd$phase==1,]$dntran)[[1]])
names(stats_1) <- c("RAW", "DIFF")
stats_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[1]], adf.test(bcd[bcd$phase==2,]$dntran)[[1]])
names(stats_2) <- c("RAW", "DIFF")
stats_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[1]], adf.test(bcd[bcd$phase==3,]$dntran)[[1]])
names(stats_3) <- c("RAW", "DIFF")
pv_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[4]], adf.test(bcd[bcd$phase==1,]$dntran)[[4]])
names(pv_1) <- c("RAW", "DIFF")
pv_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[4]], adf.test(bcd[bcd$phase==2,]$dntran)[[4]])
names(pv_2) <- c("RAW", "DIFF")
pv_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[4]], adf.test(bcd[bcd$phase==3,]$dntran)[[4]])
names(pv_3) <- c("RAW", "DIFF")
a_dicky_fuller <- t(data.frame("DF_1"=stats_1, "p-value_1"=pv_1, "DF_2"=stats_2, "p-value_2"=pv_2, "DF_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(a_dicky_fuller, caption="ADF-test"))
plot(bc$date, bc$ntran, type="l", main="Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
plot(bcd$date, bcd$dntran, type="l", main="DELTA Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
acf(bc[bc$phase==1,]$ntran, lag.max=30)
acf(bc[bc$phase==2,]$ntran, lag.max=30)
acf(bc[bc$phase==3,]$ntran, lag.max=30)
acf(bcd[bcd$phase==1,]$dntran, lag.max=30)
acf(bcd[bcd$phase==2,]$dntran, lag.max=30)
acf(bcd[bcd$phase==3,]$dntran, lag.max=30)
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bc[bc$phase==1,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bc[bc$phase==2,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bc[bc$phase==3,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bc[bc$phase==1,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bc[bc$phase==2,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bc[bc$phase==3,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box <- t(data.frame("Qm_1"=stats_1, "p-value_1"=pv_1, "Qm_2"=stats_2, "p-value_2"=pv_2,"Qm_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(ljung_box, caption="Ljung-Box RAW"))
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box <- t(data.frame("Qm_1"=stats_1, "p-value_1"=pv_1, "Qm_2"=stats_2, "p-value_2"=pv_2,"Qm_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(ljung_box, caption="Ljung-Box DIFF"))
stats_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[1]], adf.test(bcd[bcd$phase==1,]$dntran)[[1]])
names(stats_1) <- c("RAW", "DIFF")
stats_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[1]], adf.test(bcd[bcd$phase==2,]$dntran)[[1]])
names(stats_2) <- c("RAW", "DIFF")
stats_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[1]], adf.test(bcd[bcd$phase==3,]$dntran)[[1]])
names(stats_3) <- c("RAW", "DIFF")
pv_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[4]], adf.test(bcd[bcd$phase==1,]$dntran)[[4]])
names(pv_1) <- c("RAW", "DIFF")
pv_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[4]], adf.test(bcd[bcd$phase==2,]$dntran)[[4]])
names(pv_2) <- c("RAW", "DIFF")
pv_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[4]], adf.test(bcd[bcd$phase==3,]$dntran)[[4]])
names(pv_3) <- c("RAW", "DIFF")
a_dicky_fuller <- t(data.frame("DF_1"=stats_1, "p-value_1"=pv_1, "DF_2"=stats_2, "p-value_2"=pv_2, "DF_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(a_dicky_fuller, caption="ADF-test"))
plot(bc$date, bc$ntran, type="l", main="Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
plot(bcd$date, bcd$dntran, type="l", main="DELTA Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
acf(bc[bc$phase==1,]$ntran, lag.max=30)
acf(bc[bc$phase==2,]$ntran, lag.max=30)
acf(bc[bc$phase==3,]$ntran, lag.max=30)
acf(bcd[bcd$phase==1,]$dntran, lag.max=30)
acf(bcd[bcd$phase==2,]$dntran, lag.max=30)
acf(bcd[bcd$phase==3,]$dntran, lag.max=30)
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bc[bc$phase==1,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bc[bc$phase==2,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bc[bc$phase==3,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bc[bc$phase==1,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bc[bc$phase==2,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bc[bc$phase==3,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box_raw <- t(data.frame("Qm_1"=stats_1, "p-value_1"=pv_1, "Qm_2"=stats_2, "p-value_2"=pv_2,"Qm_3"=stats_3, "p-value_3"=pv_3))
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box_diff <- t(data.frame("Qm_1"=stats_1, "p-value_1"=pv_1, "Qm_2"=stats_2, "p-value_2"=pv_2,"Qm_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(ljung_box, caption="Ljung-Box DIFF"))
stats_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[1]], adf.test(bcd[bcd$phase==1,]$dntran)[[1]])
names(stats_1) <- c("RAW", "DIFF")
stats_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[1]], adf.test(bcd[bcd$phase==2,]$dntran)[[1]])
names(stats_2) <- c("RAW", "DIFF")
stats_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[1]], adf.test(bcd[bcd$phase==3,]$dntran)[[1]])
names(stats_3) <- c("RAW", "DIFF")
pv_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[4]], adf.test(bcd[bcd$phase==1,]$dntran)[[4]])
names(pv_1) <- c("RAW", "DIFF")
pv_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[4]], adf.test(bcd[bcd$phase==2,]$dntran)[[4]])
names(pv_2) <- c("RAW", "DIFF")
pv_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[4]], adf.test(bcd[bcd$phase==3,]$dntran)[[4]])
names(pv_3) <- c("RAW", "DIFF")
a_dicky_fuller <- t(data.frame("DF_1"=stats_1, "p-value_1"=pv_1, "DF_2"=stats_2, "p-value_2"=pv_2, "DF_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(a_dicky_fuller, caption="ADF-test"))
plot(bc$date, bc$ntran, type="l", main="Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
plot(bcd$date, bcd$dntran, type="l", main="DELTA Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
acf(bc[bc$phase==1,]$ntran, lag.max=30)
acf(bc[bc$phase==2,]$ntran, lag.max=30)
acf(bc[bc$phase==3,]$ntran, lag.max=30)
acf(bcd[bcd$phase==1,]$dntran, lag.max=30)
acf(bcd[bcd$phase==2,]$dntran, lag.max=30)
acf(bcd[bcd$phase==3,]$dntran, lag.max=30)
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bc[bc$phase==1,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bc[bc$phase==2,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bc[bc$phase==3,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bc[bc$phase==1,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bc[bc$phase==2,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bc[bc$phase==3,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box_raw <- t(data.frame("RAW_Qm_1"=stats_1, "RAW_p-value_1"=pv_1, "RAW_Qm_2"=stats_2, "RAW_p-value_2"=pv_2,"RAW_Qm_3"=stats_3, "RAW_p-value_3"=pv_3))
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box_diff <- t(data.frame("DIFF_Qm_1"=stats_1, "DIFF_p-value_1"=pv_1, "DIFF_Qm_2"=stats_2, "DIFF_p-value_2"=pv_2, "DIFF_Qm_3"=stats_3, "DIFF_p-value_3"=pv_3))
w_kable_styling(kable(rbind(ljung_box_raw,ljung_box_diff), caption="Ljung-Box"))
stats_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[1]], adf.test(bcd[bcd$phase==1,]$dntran)[[1]])
names(stats_1) <- c("RAW", "DIFF")
stats_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[1]], adf.test(bcd[bcd$phase==2,]$dntran)[[1]])
names(stats_2) <- c("RAW", "DIFF")
stats_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[1]], adf.test(bcd[bcd$phase==3,]$dntran)[[1]])
names(stats_3) <- c("RAW", "DIFF")
pv_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[4]], adf.test(bcd[bcd$phase==1,]$dntran)[[4]])
names(pv_1) <- c("RAW", "DIFF")
pv_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[4]], adf.test(bcd[bcd$phase==2,]$dntran)[[4]])
names(pv_2) <- c("RAW", "DIFF")
pv_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[4]], adf.test(bcd[bcd$phase==3,]$dntran)[[4]])
names(pv_3) <- c("RAW", "DIFF")
a_dicky_fuller <- t(data.frame("DF_1"=stats_1, "p-value_1"=pv_1, "DF_2"=stats_2, "p-value_2"=pv_2, "DF_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(a_dicky_fuller, caption="ADF-test"))
plot(bc$date, bc$ntran, type="l", main="Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
plot(bcd$date, bcd$dntran, type="l", main="DELTA Total Number of Transactions Per Day")
abline(v=c(as.POSIXct("2012-11-28"), as.POSIXct("2016-07-09")), col="red")
acf(bc[bc$phase==1,]$ntran, lag.max=30)
acf(bc[bc$phase==2,]$ntran, lag.max=30)
acf(bc[bc$phase==3,]$ntran, lag.max=30)
acf(bcd[bcd$phase==1,]$dntran, lag.max=30)
acf(bcd[bcd$phase==2,]$dntran, lag.max=30)
acf(bcd[bcd$phase==3,]$dntran, lag.max=30)
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bc[bc$phase==1,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bc[bc$phase==2,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bc[bc$phase==3,]$ntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bc[bc$phase==1,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bc[bc$phase==2,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bc[bc$phase==3,]$ntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box_raw <- t(data.frame("RAW_Qm_1"=stats_1, "RAW_p-value_1"=pv_1, "RAW_Qm_2"=stats_2, "RAW_p-value_2"=pv_2,"RAW_Qm_3"=stats_3, "RAW_p-value_3"=pv_3))
stats_1 <- c(); for (i in 1:10) stats_1 <- append(stats_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_1) <- 1:10
stats_2 <- c(); for (i in 1:10) stats_2 <- append(stats_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_2) <- 1:10
stats_3 <- c(); for (i in 1:10) stats_3 <- append(stats_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=i, type="Ljung-Box")[[1]])
names(stats_3) <- 1:10
pv_1 <- c(); for (i in 1:10) pv_1 <- append(pv_1, Box.test(bcd[bcd$phase==1,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_1) <- 1:10
pv_2 <- c(); for (i in 1:10) pv_2 <- append(pv_2, Box.test(bcd[bcd$phase==2,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_2) <- 1:10
pv_3 <- c(); for (i in 1:10) pv_3 <- append(pv_3, Box.test(bcd[bcd$phase==3,]$dntran, lag=100, type="Ljung-Box")[[3]])
names(pv_3) <- 1:10
ljung_box_diff <- t(data.frame("DIFF_Qm_1"=stats_1, "DIFF_p-value_1"=pv_1, "DIFF_Qm_2"=stats_2, "DIFF_p-value_2"=pv_2, "DIFF_Qm_3"=stats_3, "DIFF_p-value_3"=pv_3))
write.table(rbind(ljung_box_raw,ljung_box_diff), "ntran_ljung_box_test.csv", sep=",")
w_kable_styling(kable(rbind(ljung_box_raw,ljung_box_diff), caption="Ljung-Box"))
stats_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[1]], adf.test(bcd[bcd$phase==1,]$dntran)[[1]])
names(stats_1) <- c("RAW", "DIFF")
stats_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[1]], adf.test(bcd[bcd$phase==2,]$dntran)[[1]])
names(stats_2) <- c("RAW", "DIFF")
stats_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[1]], adf.test(bcd[bcd$phase==3,]$dntran)[[1]])
names(stats_3) <- c("RAW", "DIFF")
pv_1 <- c(adf.test(bc[bc$phase==1,]$ntran)[[4]], adf.test(bcd[bcd$phase==1,]$dntran)[[4]])
names(pv_1) <- c("RAW", "DIFF")
pv_2 <- c(adf.test(bc[bc$phase==2,]$ntran)[[4]], adf.test(bcd[bcd$phase==2,]$dntran)[[4]])
names(pv_2) <- c("RAW", "DIFF")
pv_3 <- c(adf.test(bc[bc$phase==3,]$ntran)[[4]], adf.test(bcd[bcd$phase==3,]$dntran)[[4]])
names(pv_3) <- c("RAW", "DIFF")
a_dicky_fuller <- t(data.frame("DF_1"=stats_1, "p-value_1"=pv_1, "DF_2"=stats_2, "p-value_2"=pv_2, "DF_3"=stats_3, "p-value_3"=pv_3))
w_kable_styling(kable(a_dicky_fuller, caption="ADF-test"))
vm_1_aic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(3,2,7:10,12:14,16)])), p=8, type="const")
vm_1_sic <- VAR(ts(na.omit(bcd[bcd$phase==1,c(3,2,7:10,12:14,16)])), p=1, type="const")
vm_2_aic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(3,2,7:10,12:14,16)])), p=7, type="const")
vm_2_sic <- VAR(ts(na.omit(bcd[bcd$phase==2,c(3,2,7:10,12:14,16)])), p=2, type="const")
vm_3_aic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(3,2,7:10,12:14,16)])), p=8, type="const")
vm_3_sic <- VAR(ts(na.omit(bcd[bcd$phase==3,c(3,2,7:10,12:14,16)])), p=1, type="const")
names <- c("VAR(8) - ntran - 1st AIC", "VAR(1) - ntran - 2nd AIC", "VAR(7) - ntran - 3rd AIC", "VAR(2) - ntran - 1st SIC", "VAR(8) - ntran - 2nd SIC", "VAR(1) - ntran - 3rd SIC")
write("## ntranのVARモデル", file="ntran_sum.csv")
sums <- list(summary(vm_1_aic)[[2]][[1]], summary(vm_2_aic)[[2]][1], summary(vm_3_aic)[[2]][1], summary(vm_1_sic)[[2]][1], summary(vm_2_sic)[[2]][1], summary(vm_3_sic)[[2]][1])
for ( i in 1:6) {
sum_out <- capture.output(sums[i])
write("#####", append=T, file="ntran_sum.csv")
write(names[[i]], append=T, file="ntran_sum.csv")
write("Call:", append=T, file="ntran_sum.csv")
write(sum_out[[grep("^Call:", sum_out) + 1]], append=T, file="ntran_sum.csv")
write("Residuals:", append=T, file="ntran_sum.csv")
write.table(as.list(summary(sum$residuals)), append=T, file="ntran_sum.csv", sep=",", row.names=F)
write("Coefficients:", append=T, file="ntran_sum.csv")
write.table(sum$coefficients, append=T, file="ntran_sum.csv", sep=",")
write("---", append=T, file="ntran_sum.csv")
write(sum_out[[grep("^Signif. codes:", sum_out)]], append=T, file="ntran_sum.csv")
write("Multiple R-squared:", append=T, file="ntran_sum.csv")
write(sum$r.squared, append=T, file="ntran_sum.csv")
write("Adjusted R-squared:", append=T, file="ntran_sum.csv")
write(sum$adj.r.squared, append=T, file="ntran_sum.csv")
write(sum_out[grep("^F-statistic:", sum_out)], append=T, file="ntran_sum.csv")
write("#####", append=T, file="ntran_sum.csv")
}