-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplorations.Rmd
More file actions
630 lines (442 loc) · 13.6 KB
/
explorations.Rmd
File metadata and controls
630 lines (442 loc) · 13.6 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
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
---
title: "Assignment 1 - a22mohmo"
output:
html_document:
toc: yes
toc_depth: '5'
df_print: paged
word_document: default
pdf_document:
toc: yes
toc_depth: 5
---
### Loading packages into R
```{r}
library(forecast)
library(tsutils)
```
### Loading data into R
```{r}
Y <- read.csv("./workshop1R.csv")
```
## Exercises
I have furnished my observational summaries at the conclusion of each time series analysis, culminating in comprehensive responses to the exercise questions collectively.
### Level_A - Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- Y[,1]
print(y)
```
```{r}
y <- ts(y,frequency=12,end=c(2018,11))
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,12)
y.trn <- head(y,48)
```
#### Verifying Data {style="color: grey"}
```{r}
yy <- y[1:48]
print(yy)
```
```{r}
class(y) # Our time series object
```
```{r}
class(yy) # A simple vector of numeric values
```
```{r}
yy == y.trn
```
```{r}
all(yy==y.trn)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1)
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
```{r}
seasplot(y.trn,outplot=3)
```
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
- **Trend Analysis:** A thorough examination of the data reveals the absence of any discernible trend. This observation is further substantiated by the visualization graphs, which clearly indicate the absence of both upward and downward trends in the dataset.
- **Seasonality Assessment:** A meticulous statistical analysis also confirms the absence of seasonality within the dataset. The accompanying visualization graphs corroborate this finding by demonstrating the absence of any repetitive patterns that would typically be indicative of seasonality.
- **Conclusion:** In summary, analysis unequivocally concludes that neither trend nor seasonality is evident in this time series data.
### Level_B -Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- Y[,2]
print(y)
```
```{r}
y <- ts(y,frequency=12,end=c(2018,11))
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,12)
y.trn <- head(y,48)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1) # The argument outplot produces a plot
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
```{r}
seasplot(y.trn,outplot=3)
```
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
- **Trend Analysis:** Statistically, there appears to be evidence of a trend within the data. However, it is important to note that the visualization graphs do not unequivocally confirm the presence of this trend, warranting further investigation.
- **Seasonality Assessment:** Conversely, Statistical analysis fails to detect any significant seasonality within the dataset. This finding is corroborated by the visualization graph, which illustrates the absence of repetitive patterns typically indicative of seasonality.
- **Conclusion:** In summary, while there is some statistical indication of a trend, it is not definitively supported by the visualization graphs. Additionally, there is a clear absence of seasonality within this time series data.
### LevelShift - Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- Y[,3]
print(y)
```
```{r}
y <- ts(y,frequency=12,end=c(2018,11))
# The syntax of end is c(Year,Month), or more generally
# c(season,seasonal period).
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,12)
y.trn <- head(y,48)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1)
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
```{r}
seasplot(y.trn,outplot=3)
```
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
**Trend Analysis:** Statistical assessment unequivocally identifies the presence of a discernible trend within the dataset. This finding is further validated by the visualization graph, which unmistakably portrays the existence of a trend.
**Seasonality Evaluation:** In stark contrast, rigorous statistical analysis fails to detect any significant seasonality within the dataset. This outcome is in alignment with the visualization graph, which provides compelling evidence of the absence of repetitive patterns indicative of seasonality.
**Conclusion:** In summary, analysis conclusively asserts the existence of a trend while simultaneously discounting the presence of seasonality within this time series data.
### Trend_A - Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- Y[,4]
print(y)
```
```{r}
y <- ts(y,frequency=12,end=c(2018,11))
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,12)
y.trn <- head(y,48)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1)
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
```{r}
seasplot(y.trn,outplot=3)
```
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
- **Trend Analysis:** The statistical analysis conducted indicates the presence of a discernible trend within the dataset, a conclusion further supported by the visualization graphs.
- **Seasonality Assessment:** Conversely, the statistical examination unequivocally affirms the absence of significant seasonality within the dataset. This observation aligns with the visualization graphs, which lack repetitive patterns indicative of seasonality.
- **Conclusion:** In summary, the analysis confirms the existence of a trend while conclusively ruling out the presence of seasonality within this time series data.
### Trend_B - Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- Y[,5]
print(y)
```
```{r}
y <- ts(y,frequency=12,end=c(2018,11))
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,12)
y.trn <- head(y,48)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1)
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
```{r}
seasplot(y.trn,outplot=3)
```
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
- **Trend Analysis:** Through a meticulous examination of the data, it is evident that a discernible trend exists, a conclusion supported by the visualization graphs.
- **Seasonality Assessment:** Conversely, the analysis conducted demonstrates the absence of significant seasonality within the dataset. This determination aligns with the visual evidence presented in the graphs, which notably lack any recurring patterns indicative of seasonality.
- **Conclusion:** In summary, the analysis affirms the presence of a trend while simultaneously discounting the presence of seasonality within this time series data.
### Season_A - Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- Y[,6]
print(y)
```
```{r}
y <- ts(y,frequency=12,end=c(2018,11))
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,12)
y.trn <- head(y,48)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1)
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
`{seasplot(y.trn,outplot=3)}`
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
- **Trend Analysis:** The static analysis suggests the presence of a trend in the data, but this observation is not corroborated by the visual examination, as the graphs do not display any clear trend.
- **Seasonality Assessment:** Both the static analysis and visual inspection indicate the presence of seasonality in the dataset, confirming the recurring patterns associated with seasonality.
- **Conclusion:** In summary, the dataset exhibits seasonality, while a discernible trend is not apparent within the time series data.
### Season_B - Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- Y[,7]
print(y)
```
```{r}
y <- ts(y,frequency=12,end=c(2018,11))
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,12)
y.trn <- head(y,48)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1)
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
```{r}
seasplot(y.trn,outplot=3)
```
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
- **Trend Analysis:** Both the static analysis and visual examination do not show any evidence of a trend in the data. There is no discernible trend statically or visually.
- **Seasonality Assessment:** Conversely, both the static analysis and visual inspection confirm the presence of seasonality within the dataset, with clear recurring patterns evident both statistically and visually.
- **Conclusion:** In summary, the dataset reveals the presence of seasonality while lacking a discernible trend within the time series data.
### TrendSeason - Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- Y[,8]
print(y)
```
```{r}
y <- ts(y,frequency=12,end=c(2018,11))
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,12)
y.trn <- head(y,48)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1)
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
```{r}
seasplot(y.trn,outplot=3)
```
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
**Trend Analysis:** Both the static analysis and visual examination reveal the presence of a discernible trend in the data, with clear evidence of a trend both statistically and visually.
**Seasonality Assessment:** Similarly, both the static analysis and visual inspection confirm the presence of seasonality within the dataset, with recurring patterns evident both statistically and visually.
**Conclusion:** In conclusion, the dataset unmistakably demonstrates the presence of both a discernible trend and seasonality, indicating significant temporal patterns within the time series data.
### Does your understanding of the plots agree with the underlying model? {style="color: green"}
::: {style="color: black"}
Upon careful examination of the provided time series analyses, it is evident that there may be occasional disparities in the interpretation of trends and seasonality between the statistical results derived from the model and the visual examination.
While the model provides a statistical perspective, the visual examination offers an additional layer of insight. These differences in interpretation are duly recognized, and the conclusions drawn in each analysis take into consideration both the statistical results and the visual evidence presented in the plots.
In response to the question, it can be stated that there is a degree of agreement between the understanding derived from the plots and the underlying model's analysis. However, it is also important to acknowledge that the agreement is not absolute, and the conclusions consider the insights from both sources to provide a comprehensive assessment of the data's trends and seasonality.
:::
### Does decomp() know when to remove the trend or the seasonality? {style="color: green"}
::: {style="color: black"}
The decomp()function, as with similar decomposition methods, doesn't make automatic decisions about removing trend or seasonality. Users need to specify the decomposition method and choose whether to keep or eliminate these components based on their specific analysis goals and the nature of the data they are working with.
:::
### AirPassengers - Time Series {style="color: blue"}
#### Load Data {style="color: grey"}
```{r}
y <- AirPassengers
print(y)
```
```{r}
plot(y)
```
#### Constructing estimation and hold-out sets {style="color: grey"}
```{r}
y.tst <- tail(y,29)
y.trn <- head(y,115)
```
#### Exploration {style="color: grey"}
```{r}
cma <- cmav(y.trn,outplot=1)
```
```{r}
print(cma)
```
```{r}
seasplot(y.trn)
```
```{r}
seasplot(y.trn,outplot=2)
```
```{r}
seasplot(y.trn,outplot=3)
```
```{r}
seasplot(y.trn,outplot=4)
```
```{r}
dc <- decomp(y.trn,outplot=1)
```
#### Observation {style="color: black"}
- **Trend Analysis:** Both the static analysis and visual examination distinctly indicate the presence of an additive trend in the data, with clear evidence of a trend both statistically and visually.
- **Seasonality Assessment:** Similarly, both the static analysis and visual inspection consistently confirm the presence of seasonality within the dataset, with recurring patterns evident both statistically and visually.
- **Conclusion:** In summary, the data unequivocally exhibits both a discernible additive trend and seasonality, as supported by both static analysis and visual examination of this time series data.