-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2hrs_ph3_report_generator.R
811 lines (692 loc) · 26.4 KB
/
2hrs_ph3_report_generator.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
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
source('funcs.R')
# benchmark models ----
report.full(model = 'snaive()',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1)
report.full(model = 'meanf()',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1)
report.full(model = 'naive()',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1)
# 2hrs ph3 Simple Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0)) ----
# arima(1,0,0)(1,0,0)
# One positive lag in ACF & PACF - AR signature
report(model = 'Arima(order=c(1, 0, 0))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
# Previous model had residual significant at lag = 12 (24hrs seasonality)
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
# Some outlier present, try to ignore it by tsclean
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0))',
series = '2hrs ph3',
transformation = 'tsclean()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
# Try with a transformation, avoid -Inf values
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0))',
series = '2hrs ph3',
transformation = 'log() %>% (function(d) {d[d==-Inf]<-0; d})',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
# Try also with a MA term since neither the ACF nor the PACF
# decays slowly or sinusoidally in order to be sure AR or MA is definitely usable
report(model = 'Arima(order=c(0, 0, 1))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
# Same as above, but with seasonal terms, again there were significant residuals
# at lag 12
report(model = 'Arima(order=c(0, 0, 1), seasonal=c(0, 0, 1))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
#Fourier terms for the model AR(1) and SAR(1)
#K was randomly chosen by me
report(model = 'Arima(order=c(0, 0, 1), seasonal=c(0, 0, 1), xreg=fourier(., K=5))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3,
xreg='fourier(., K=5, h=h)')
#Fourier terms for the model MA(1) and SMA(1)
#K was randomly chosen by me
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), xreg=fourier(., K=5))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3,
xreg='fourier(., K=5, h=h)')
#Try with differences, although no indication of trend or seasonal-trend
report(model = 'Arima(order=c(0, 1, 1), seasonal=c(0, 1, 1))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
#Variation on the above
report(model = 'Arima(order=c(1, 1, 0), seasonal=c(1, 1, 0))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
report(model = 'auto.arima()',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 3)
# 2hrs ph3 -1 day forecast - Simple Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0)) ----
# fourier arima(1,0,0)(1,0,0)
report(model = 'Arima(order=c(1, 0, 0))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1)
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1)
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0))',
series = '2hrs ph3',
transformation = 'log() %>% (function(d) {d[d==-Inf]<-0; d})',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1)
report(model = 'Arima(order=c(0, 0, 1))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1)
report(model = 'Arima(order=c(0, 0, 1), seasonal=c(0, 0, 1))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1)
report(model = 'Arima(order=c(0, 0, 1), seasonal=c(0, 0, 1), xreg=fourier(., K=5))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1,
xreg='fourier(., K=5, h=h)')
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), xreg=fourier(., K=5))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1,
xreg='fourier(., K=5, h=h)')
report(model = 'Arima(order=c(0, 1, 1), seasonal=c(0, 1, 1))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1)
report(model = 'Arima(order=c(1, 1, 0), seasonal=c(1, 1, 0))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1)
report(model = 'auto.arima()',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = -10,
traindays = 7,
testdays = 1)
# 2hrs ph3 from the front ----
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = 0,
traindays = 7,
testdays = 1)
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), xreg=fourier(., K=5))',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = 0,
traindays = 7,
testdays = 1,
xreg='fourier(., K=5, h=h)')
report(model = 'auto.arima()',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = 0,
traindays = 7,
testdays = 1)
# 2hrs ph3 full - apply the best models so far on the full data ----
report.full(model = 'auto.arima()',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1)
#https://stackoverflow.com/questions/7233288/non-stationary-seasonal-ar-part-from-css-error-in-r
# This model predicts the new value as a multiple of the previous (seasonal) value plus a constant
# This model assumes mean reverting behaviour (no trend - no diffs) which for house-hold is true (energy consumption is the same, on average)
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML")',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1)
# Fit the seasonality using fourier terms nad the errors using the logic above
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=5))',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1,
xreg='fourier(., K=5, h=h)')
report.full(model = 'auto.arima(xreg=fourier(., K=5))',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1,
xreg='fourier(., K=5, h=h)')
# Find the best train:test days ratio for ARIMA(1,0,0)(1,0,0) ----
best.fcast.2hrsPh3 <- NULL
best.traindays <- 0
best.testdays <- 0
for(traindays in 3:7)
{
for(testdays in 1:3)
{
print(paste("Trying", traindays, "train days and", testdays, "test days"))
current <- fullforecast(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML")',
dataset = datasets[['2hrs ph3']]$series,
transformation = 'identity()',
traindays = traindays,
testdays = testdays,
xreg=NULL)
if(is.null(best.fcast.2hrsPh3) || current$accuracy[[2]] < best.fcast.2hrsPh3$accuracy[[2]])
{
best.fcast.2hrsPh3 <- current
best.traindays <- traindays
best.testdays <- testdays
}
}
}
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML")',
series = '2hrs ph3',
transformation = 'identity()',
traindays = best.traindays, # 4
testdays = best.testdays) # 1
# Find the best train:test days ratio for ARIMA(1,0,0)(1,0,0) K=5----
best.fcast.fourier.2hrsPh3 <- NULL
best.fourier.traindays <- 0
best.fourier.testdays <- 0
for(traindays in 3:7)
{
for(testdays in 1:3)
{
print(paste("Trying", traindays, "train days and", testdays, "test days"))
current <- fullforecast(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=5))',
dataset = datasets[['2hrs ph3']]$series,
transformation = 'identity()',
traindays = traindays,
testdays = testdays,
xreg='fourier(., K=5, h=h)')
if(is.null(best.fcast.fourier.2hrsPh3) || current$accuracy[[2]] < best.fcast.fourier.2hrsPh3$accuracy[[2]])
{
best.fcast.fourier.2hrsPh3 <- current
best.fourier.traindays <- traindays
best.fourier.testdays <- testdays
}
}
}
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=5))',
series = '2hrs ph3',
transformation = 'identity()',
traindays = best.fourier.traindays, # 7
testdays = best.fourier.testdays, # 3
xreg='fourier(., K=5, h=h)')
# Find best K for the above model ARIMA(1,0,0)(1,0,0) ----
best.fcast.k.2hrsPh3 <- NULL
best.k <- 0
#K must be not be greater than period/2
for(k in 1:(frequency(datasets[['2hrs ph3']]$series)/2))
{
print(paste("Trying k =", k))
m <- paste('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=', k, '))', sep='')
xreg <- paste('fourier(., h=h, K=', k, ')')
current <- fullforecast(model = m,
dataset = datasets[['2hrs ph3']]$series,
transformation = 'identity()',
traindays = best.fourier.traindays, # 7
testdays = best.fourier.testdays, # 3
xreg=xreg)
if(is.null(best.fcast.k.2hrsPh3) || current$accuracy[[2]] < best.fcast.k.2hrsPh3$accuracy[[2]])
{
best.fcast.k.2hrsPh3 <- current
best.k <- k
}
}
report.full(model = paste('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=', best.k, '))', sep=''),
series = '2hrs ph3',
transformation = 'identity()',
traindays = best.fourier.traindays, # 7
testdays = best.fourier.testdays, # 3
xreg = paste('fourier(., h=h, K=', best.k, ')')) #2
# Best model: ARIMA(1, 0, 0)(1, 0, 0) (K=2), 7:3, RMSE 318, MAE 182 || with tsclean RMSE 330, MAE 169 ----
# For tsclean() RMSE has gone up since it applies bigger penalty to the bigger errors (there are bigger errors since tsclean "smoothes" the data hence the outliers will give even bigger errors)
# For 5th obs: RMSE=318 ; MAE=179
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=2))',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = 'fourier(., h=h, K=2)')
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=2))',
series = '2hrs ph3',
transformation = 'tsclean()',
traindays = 7,
testdays = 3,
xreg = 'fourier(., h=h, K=2)')
fifthOD.fcast <- quote(
{cbind(
dummies=getNthObsDummies(5, 1, h, frequency(.)),
fourier(., h=h, K=2)
)}
)
fifthOD.fit <- quote(
{cbind(
dummies=getNthObsDummies(5, 1, length(.), frequency(.)),
fourier(., K=2)
)}
)
report.full(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=', paste0(deparse(fifthOD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(fifthOD.fcast), collapse=''))
# same
report.full(model = paste0('Arima(order=c(1, 0, 0), method="ML", xreg=', paste0(deparse(fifthOD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(fifthOD.fcast), collapse=''))
# rmse320 mae=183 - worse
report.full(model = 'Arima(order=c(1, 0, 0), method="ML", xreg=fourier(., K=2))',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = 'fourier(., h=h, K=2)')
# observation based modelling ----
report(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML")',
series = '2hrs ph3',
transformation = 'identity()',
diffs = 'identity()',
sdiffs = 'identity()',
startday = 0,
traindays = 24,
testdays = 12,
obs = TRUE)
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS")',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 48,
testdays = 1,
obs=TRUE)
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=fourier(., K=2))',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 48,
testdays = 2,
xreg = 'fourier(., h=h, K=2)',
obs = TRUE)
best.fcast.obs.2hrsPh3 <- NULL
best.testobs <- 0
trainobs <- 4*frequency(datasets[['2hrs ph3']]$series) #48
for(testobs in 1:(frequency(datasets[['2hrs ph3']]$series) - 1)) # 1:11
{
print(paste("Trying", trainobs, "train observations and", testobs, "test observations"))
current <- fullforecast.obs(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML")',
dataset = datasets[['2hrs ph3']]$series,
transformation = 'identity()',
trainobs = trainobs,
testobs = testobs,
xreg=NULL)
if(is.null(best.fcast.obs.2hrsPh3) || current$accuracy[[2]] < best.fcast.obs.2hrsPh3$accuracy[[2]])
{
best.fcast.obs.2hrsPh3 <- current
best.testobs <- testobs
}
}
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML")',
series = '2hrs ph3',
transformation = 'identity()',
traindays = trainobs,
testdays = best.testobs, # 9
obs = TRUE)
best.fcast.obs.fourier.2hrsPh3 <- NULL
best.fourier.testobs <- 0
for(testobs in 2:(frequency(datasets[['2hrs ph3']]$series) - 1)) # 2:11
{
print(paste("Trying", trainobs, "train observations and", testobs, "test observations"))
current <- fullforecast.obs(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), xreg=fourier(., K=2), method="CSS")',
dataset = datasets[['2hrs ph3']]$series,
transformation = 'identity()',
trainobs = trainobs,
testobs = testobs,
xreg = 'fourier(., h=h, K=2)')
if(is.null(best.fcast.obs.fourier.2hrsPh3) || current$accuracy[[2]] < best.fcast.obs.fourier.2hrsPh3$accuracy[[2]])
{
best.fcast.obs.fourier.2hrsPh3 <- current
best.fourier.testobs <- testobs
}
}
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), xreg=fourier(., K=2), method="ML")',
series = '2hrs ph3',
transformation = 'identity()',
traindays = trainobs,
testdays = best.fourier.testobs, # 11
xreg = 'fourier(., h=h, K=2)',
obs = TRUE)
# no better model was found this way (by using only several observations ----
# tsclean on the best model ----
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=2))',
series = '2hrs ph3',
transformation = 'tsclean()',
traindays = 7,
testdays = 3,
xreg = 'fourier(., h=h, K=2)')
# dummies on 6th day - 6th day has an "outlier" ----
sixthDD.fcast <- quote(
{cbind(
dummies=get6thDayDummies(h, frequency(.), start(.)[[1]]),
fourier(., h=h, K=2)
)}
)
sixthDD.fit <- quote(
{cbind(
dummies=get6thDayDummies(length(.), frequency(.), start(.)[[1]]),
fourier(., K=2)
)}
)
report(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=', paste0(deparse(sixthDD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(sixthDD.fcast), collapse=''))
#7:3 rmse=330 mae=193
report.full(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(sixthDD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(sixthDD.fcast), collapse=''))
(datasets[['2hrs ph3']]$series %>%
{eval(x)} ->
external.regressors)
plot(external.regressors)
# dummies on every weekday ----
dailyD.fcast <- quote(
{cbind(
dummies=getDailyDummies(h, frequency(.), start(.)[[1]]),
fourier(., h=h, K=2)
)}
)
dailyD.fit <- quote(
{cbind(
dummies=getDailyDummies(length(.), frequency(.), start(.)[[1]]),
fourier(., K=2)
)}
)
report(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(dailyD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(dailyD.fcast), collapse=''))
# 7:3 rmse=333, mae=202
report.full(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=', paste0(deparse(dailyD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(dailyD.fcast), collapse=''))
# dummies on the 5th obs (the "outlier") ----
fifthOD.fcast <- quote(
{cbind(
dummies=getNthObsDummies(5, 1, h, frequency(.)),
fourier(., h=h, K=2)
)}
)
fifthOD.fit <- quote(
{cbind(
dummies=getNthObsDummies(5, 1, length(.), frequency(.)),
fourier(., K=2)
)}
)
report(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(fifthOD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(fifthOD.fcast), collapse=''))
# dummies on the 5th obs (the "outlier") without seasonal terms, with Fourier ----
fifthOD.fcast <- quote(
{cbind(
dummies=getNthObsDummies(5, 1, h, frequency(.)),
fourier(., h=h, K=2)
)}
)
fifthOD.fit <- quote(
{cbind(
dummies=getNthObsDummies(5, 1, length(.), frequency(.)),
fourier(., K=2)
)}
)
report(model = paste0('Arima(order=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(fifthOD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(fifthOD.fcast), collapse=''))
# dummies on the 5-9th obs (the "outlier") with seasonal terms, without Fourier ----
fifthOD.fcast <- quote(
{cbind(
dummies=getNthObsDummies(5, 4, h, frequency(.))
)}
)
fifthOD.fit <- quote(
{cbind(
dummies=getNthObsDummies(5, 4, length(.), frequency(.))
)}
)
report(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(fifthOD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(fifthOD.fcast), collapse=''))
# 7:3 rmse=318, mae=179
report.full(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=', paste0(deparse(fifthOD.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(fifthOD.fcast), collapse=''))
# dummies on the 5th to the 7th obs (the "outliers") ----
best.fcast.dummy.2hrsPh3 <- NULL
best.startDummy <- 0
best.lenDummy <- 0
for(startDummy in 4:8)
{
for(lenDummy in 1:5)
{
print(paste("Trying startDummy =", startDummy, ", length =", lenDummy))
obsDummies.fcast <- substitute(
{cbind(
dummies=getNthObsDummies(startDummy, lenDummy, h, frequency(.)),
fourier(., h=h, K=2)
)},
list(startDummy=startDummy, lenDummy=lenDummy)
)
obsDummies.fit <- substitute(
{cbind(
dummies=getNthObsDummies(startDummy, lenDummy, length(.), frequency(.)),
fourier(., K=2)
)},
list(startDummy=startDummy, lenDummy=lenDummy)
)
current <- fullforecast(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=', paste0(deparse(obsDummies.fit), collapse='') ,')'),
dataset = datasets[['2hrs ph3']]$series,
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(obsDummies.fcast), collapse=''))
if(is.null(best.fcast.dummy.2hrsPh3) || current$accuracy[[2]] < best.fcast.dummy.2hrsPh3$accuracy[[2]])
{
best.fcast.dummy.2hrsPh3 <- current
best.startDummy <- startDummy
best.lenDummy <- lenDummy
}
}
}
bestObsDummies.fcast <- substitute(
{cbind(
dummies=getNthObsDummies(best.startDummy, best.lenDummy, h, frequency(.)),
fourier(., h=h, K=2)
)},
list(best.startDummy = best.startDummy, best.lenDummy = best.lenDummy)
)
bestObsDummies.fit <- substitute(
{cbind(
dummies=getNthObsDummies(best.startDummy, best.lenDummy, length(.), frequency(.)),
fourier(., K=2)
)},
list(best.startDummy = best.startDummy, best.lenDummy = best.lenDummy)
)
# 7:3, dummies 4:4, rmse=318, mae=184
report.full(model = paste0('Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=', paste0(deparse(bestObsDummies.fit), collapse='') ,')'),
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 3,
xreg = paste0(deparse(bestObsDummies.fcast), collapse=''))
# other tries ----
report.full(model = 'Arima(order=c(2, 1, 1), seasonal=c(2, 0, 0))',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1)
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="ML", xreg=fourier(., K=1), include.mean=FALSE)',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 7,
testdays = 1,
xreg = 'fourier(., h=h, K=1)')
#series = msts(read.csv(file = '../energyarima/benchmarks/2hrs-ph3.txt'), seasonal.periods=c((24*60)/120, (24*60*7)/120), start=0),
# report.full(
# model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=fourier(., K=c(1, 1)))',
# series = '2hrs ph3',
# transformation = 'identity()',
# traindays = 7,
# testdays = 1,
# xreg = 'fourier(., h=h, K=c(1, 1))')
# if predicting one single point ahead it works, otherwise I produce too many fcast points
fullforecast.obs(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=fourier(., K=1))',
dataset = datasets[['2hrs ph3']]$series,
transformation = 'identity()',
trainobs = 48,
testobs = 12,
xreg = 'fourier(., h=h, K=1)')
fullforecast.serial.obs(model = 'Arima(order=c(1, 0, 0), method="CSS")',
dataset = head(datasets[['2hrs ph3']]$series, 100),
transformation = 'identity()',
trainobs = 48,
testobs = 12,
xreg = NULL)
fullforecast(model = 'Arima(order=c(1, 0, 0), method="CSS")',
dataset = head(datasets[['2hrs ph3']]$series, 1000),
transformation = 'identity()',
traindays = 7,
testdays = 2,
xreg = NULL)
report.full(model = 'Arima(order=c(1, 0, 0), seasonal=c(1, 0, 0), method="CSS", xreg=fourier(., K=1))',
series = '2hrs ph3',
transformation = 'identity()',
traindays = 48,
testdays = 12,
xreg = 'fourier(., h=h, K=1)',
obs=TRUE)