-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
3726 lines (3696 loc) · 790 KB
/
index.html
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
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.2.335">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Haqiqatkhah, Mohammadhossein Manuel">
<meta name="author" content="Hamaker, Ellen L.">
<meta name="description" content="Reproducible code for Daily dynamics and weekly rhythms: A tutorial on seasonal ARMA models combined with day-of-week effects.">
<title>Daily dynamics and weekly rhythms</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
div.csl-bib-body { }
div.csl-entry {
clear: both;
}
.hanging div.csl-entry {
margin-left:2em;
text-indent:-2em;
}
div.csl-left-margin {
min-width:2em;
float:left;
}
div.csl-right-inline {
margin-left:2em;
padding-left:1em;
}
div.csl-indent {
margin-left: 2em;
}
</style>
<script src="index_files/libs/clipboard/clipboard.min.js"></script>
<script src="index_files/libs/quarto-html/quarto.js"></script>
<script src="index_files/libs/quarto-html/popper.min.js"></script>
<script src="index_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="index_files/libs/quarto-html/anchor.min.js"></script>
<link href="index_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="index_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" class="quarto-color-scheme" id="quarto-text-highlighting-styles">
<link href="index_files/libs/quarto-html/quarto-syntax-highlighting-dark.css" rel="prefetch" class="quarto-color-scheme quarto-color-alternate" id="quarto-text-highlighting-styles">
<script src="index_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="index_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="index_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" class="quarto-color-scheme" id="quarto-bootstrap" data-mode="light">
<link href="index_files/libs/bootstrap/bootstrap-dark.min.css" rel="prefetch" class="quarto-color-scheme quarto-color-alternate" id="quarto-bootstrap" data-mode="dark">
<script async="" src="https://hypothes.is/embed.js"></script>
<script src="index_files/libs/htmlwidgets-1.6.1/htmlwidgets.js"></script>
<link href="index_files/libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet">
<script src="index_files/libs/datatables-binding-0.31/datatables.js"></script>
<script src="index_files/libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<link href="index_files/libs/dt-core-1.13.6/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="index_files/libs/dt-core-1.13.6/css/jquery.dataTables.extra.css" rel="stylesheet">
<script src="index_files/libs/dt-core-1.13.6/js/jquery.dataTables.min.js"></script>
<script src="index_files/libs/jszip-1.13.6/jszip.min.js"></script>
<script src="index_files/libs/pdfmake-1.13.6/pdfmake.js"></script>
<script src="index_files/libs/pdfmake-1.13.6/vfs_fonts.js"></script>
<link href="index_files/libs/dt-ext-buttons-1.13.6/css/buttons.dataTables.min.css" rel="stylesheet">
<script src="index_files/libs/dt-ext-buttons-1.13.6/js/dataTables.buttons.min.js"></script>
<script src="index_files/libs/dt-ext-buttons-1.13.6/js/buttons.html5.min.js"></script>
<script src="index_files/libs/dt-ext-buttons-1.13.6/js/buttons.colVis.min.js"></script>
<script src="index_files/libs/dt-ext-buttons-1.13.6/js/buttons.print.min.js"></script>
<link href="index_files/libs/nouislider-7.0.10/jquery.nouislider.min.css" rel="stylesheet">
<script src="index_files/libs/nouislider-7.0.10/jquery.nouislider.min.js"></script>
<link href="index_files/libs/selectize-0.12.0/selectize.bootstrap3.css" rel="stylesheet">
<script src="index_files/libs/selectize-0.12.0/selectize.min.js"></script>
<link href="index_files/libs/crosstalk-1.2.1/css/crosstalk.min.css" rel="stylesheet">
<script src="index_files/libs/crosstalk-1.2.1/js/crosstalk.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
<meta name="citation_title" content="Daily dynamics and weekly rhythms: A tutorial on seasonal ARMA models combined with day-of-week effects">
<meta name="citation_author" content="Haqiqatkhah, Mohammadhossein Manuel">
<meta name="citation_author" content="Hamaker, Ellen L.">
<meta name="citation_publication_date" content="2024-02-20">
<meta name="citation_cover_date" content="2024-02-20">
<meta name="citation_year" content="2024">
<meta name="citation_fulltext_html_url" content="https://psyarxiv.com/duvqh">
<meta name="citation_doi" content="10.31234/osf.io/duvqh">
<meta name="citation_language" content="en">
<meta name="citation_journal_title" content="PsyArXiv Preprints">
<meta name="citation_reference" content="citation_title=Daily dynamics and weekly rhythms: A tutorial on seasonal ARMA models combined with day-of-week effects;,citation_abstract=Daily diary data of emotional experiences are typically modeled with a first-order autoregressive model to account for possible day-to-day dynamics. However, our emotional experiences are likely to be affected by the weekly rhythm of our activities, which may be reflected by: (a) day-of-week effects (DOWEs), where different days of the week are characterized by different means; and (b) week-to-week dynamics, where weekday-specific activities and experiences have a delayed effect on the emotions that we experience on the same weekday a week later. While DOWEs have been studied occasionally, week-to-week dynamics have been largely ignored in psychological research. To gain more insight in the various regularities that may exist in daily diary data, we begin with presenting a set of complementary visualization techniques that can help to detect and characterize weekly rhythms and day-to-day dynamics in time series data. Subsequently, we introduce the family of seasonal autoregressive–moving average (SARMA) models from the econometrics literature, and extend this with models for the DOWEs. We illustrate how the different model components show up in the various visualizations of the time series data. We then provide a tutorial on fitting these models in R, discussing model fit and model selection, and apply this to a daily diary dataset consisting of 56-101 daily measures from 98 individuals. The results suggests that most individuals in the sample are characterized by patterns and dynamics that the current practices in psychological research cannot capture adequately. We discuss the implications of our findings for current psychological research practices.;,citation_author=MohammadHossein Manuel Haqiqatkhah;,citation_author=Ellen Hamaker;,citation_publication_date=2024-02;,citation_cover_date=2024-02;,citation_year=2024;,citation_doi=10.31234/osf.io/duvqh;,citation_publisher=OSF;">
<meta name="citation_reference" content="citation_title=Daily Interpersonal and Affective Dynamics in Personality Disorder;,citation_abstract=In this naturalistic study, the authors adopt the lens of interpersonal theory to examine between- and within-person differences in dynamic processes of daily affect and interpersonal behaviors among individuals (N = 101) previously diagnosed with personality disorders who completed daily diaries over the course of 100 days. Dispositional ratings of interpersonal problems and measures of daily stress were used as predictors of daily shifts in interpersonal behavior and affect in multilevel models. Results indicate that \sim40%50% of the variance in interpersonal behavior and affect is due to daily fluctuations, which are modestly related to dispositional measures of interpersonal problems but strongly related to daily stress. The findings support conceptions of personality disorders as a dynamic form of psychopathology involving the individuals interacting with and regulating in response to the contextual features of their environment.;,citation_author=Aidan G. C. Wright;,citation_author=Christopher J. Hopwood;,citation_author=Leonard J. Simms;,citation_publication_date=2015-08;,citation_cover_date=2015-08;,citation_year=2015;,citation_issue=4;,citation_doi=10.1521/pedi.2015.29.4.503;,citation_issn=0885-579X;,citation_volume=29;,citation_journal_title=Journal of Personality Disorders;,citation_publisher=Guilford Publications Inc.;">
<meta name="citation_reference" content="citation_title=Circular: Circular Statistics;,citation_abstract=Circular Statistics, from &amp;amp;quot;Topics in circular Statistics&quot; (2001) S. Rao Jammalamadaka and A. SenGupta, World Scientific.;,citation_author=Ulric Lund;,citation_author=Claudio Agostinelli;,citation_author=Hiroyoshi Arai;,citation_author=Alessando Gagliardi;,citation_author=Eduardo García-Portugués;,citation_author=Dimitri Giunchi;,citation_author=Jean-Olivier Irisson;,citation_author=Matthew Pocernich;,citation_author=Federico Rotolo;,citation_publication_date=2023-09;,citation_cover_date=2023-09;,citation_year=2023;">
<meta name="citation_reference" content="citation_title=One Direction? A Tutorial for Circular Data Analysis Using R With Examples in Cognitive Psychology;,citation_abstract=Circular data is data that is measured on a circle in degrees or radians. It is fundamentally different from linear data due to its periodic nature (0^\circ = 360^\circ). Circular data arises in a large variety of research fields. Among others in ecology, the medical sciences, personality measurement, educational science, sociology, and political science circular data is collected. The most direct examples of circular data within the social sciences arise in cognitive and experimental psychology. However, despite numerous examples of circular data being collected in different areas of cognitive and experimental psychology, the knowledge of this type of data is not well-spread and literature in which these types of data are analyzed using methods for circular data is relatively scarce. This paper therefore aims to give a tutorial in working with and analyzing circular data to researchers in cognitive psychology and the social sciences in general. It will do so by focusing on data inspection, model fit, estimation and hypothesis testing for two specific models for circular data using packages from the statistical programming language R.;,citation_author=Jolien Cremers;,citation_author=Irene Klugkist;,citation_publication_date=2018;,citation_cover_date=2018;,citation_year=2018;,citation_issn=1664-1078;,citation_volume=9;,citation_journal_title=Frontiers in Psychology;">
</head>
<body>
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
</div>
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<div class="quarto-title-block"><div><h1 class="title">Daily dynamics and weekly rhythms</h1><button type="button" class="btn code-tools-button dropdown-toggle" id="quarto-code-tools-menu" data-bs-toggle="dropdown" aria-expanded="false"><i class="bi"></i> Code</button><ul class="dropdown-menu dropdown-menu-end" aria-labelelledby="quarto-code-tools-menu"><li><a id="quarto-show-all-code" class="dropdown-item" href="javascript:void(0)" role="button">Show All Code</a></li><li><a id="quarto-hide-all-code" class="dropdown-item" href="javascript:void(0)" role="button">Hide All Code</a></li><li><hr class="dropdown-divider"></li><li><a id="quarto-view-source" class="dropdown-item" href="javascript:void(0)" role="button">View Source</a></li></ul></div></div>
<p class="subtitle lead">Reproducible Code</p>
</div>
<div>
<div class="description">
<p>Reproducible code for <em>Daily dynamics and weekly rhythms: A tutorial on seasonal ARMA models combined with day-of-week effects</em>.</p>
</div>
</div>
<div class="quarto-title-meta-author">
<div class="quarto-title-meta-heading">Authors</div>
<div class="quarto-title-meta-heading">Affiliations</div>
<div class="quarto-title-meta-contents">
Haqiqatkhah, Mohammadhossein Manuel <a href="https://orcid.org/0000-0002-2513-3761" class="quarto-title-author-orcid"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=="></a>
</div>
<div class="quarto-title-meta-contents">
<p class="affiliation">
<a href="https://www.uu.nl/staff/MHHaqiqatkhah">
Utrecht University
</a>
</p>
</div>
<div class="quarto-title-meta-contents">
Hamaker, Ellen L.
</div>
<div class="quarto-title-meta-contents">
<p class="affiliation">
<a href="https://www.uu.nl/staff/ELHamaker">
Utrecht University
</a>
</p>
</div>
</div>
<div class="quarto-title-meta">
</div>
</header>
<nav id="TOC" role="doc-toc">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#sec-intro" id="toc-sec-intro"><span class="toc-section-number">1</span> Introduction</a></li>
<li><a href="#sec-functions" id="toc-sec-functions"><span class="toc-section-number">2</span> R functions</a>
<ul>
<li><a href="#sec-visualization" id="toc-sec-visualization"><span class="toc-section-number">2.1</span> Time series visualizations</a></li>
<li><a href="#sec-simulation" id="toc-sec-simulation"><span class="toc-section-number">2.2</span> Simulating time series</a></li>
<li><a href="#sec-shiny" id="toc-sec-shiny"><span class="toc-section-number">2.3</span> Shiny app</a></li>
<li><a href="#sec-modeling" id="toc-sec-modeling"><span class="toc-section-number">2.4</span> Modeling time series data</a>
<ul>
<li><a href="#sec-fitting" id="toc-sec-fitting"><span class="toc-section-number">2.4.1</span> Fitting time series models</a></li>
<li><a href="#sec-estimates" id="toc-sec-estimates"><span class="toc-section-number">2.4.2</span> Extracting parameter estimates</a>
<ul>
<li><a href="#estimating-harmonic-parameters-by-bootstrapping" id="toc-estimating-harmonic-parameters-by-bootstrapping"><span class="toc-section-number">2.4.2.1</span> Estimating harmonic parameters by bootstrapping</a></li>
</ul></li>
</ul></li>
</ul></li>
<li><a href="#sec-reproducing" id="toc-sec-reproducing"><span class="toc-section-number">3</span> Reproducing figures, analyses, and results</a>
<ul>
<li><a href="#sec-investigate" id="toc-sec-investigate"><span class="toc-section-number">3.1</span> Importing and investigating the empirical data</a></li>
<li><a href="#sec-reproduce-figures" id="toc-sec-reproduce-figures"><span class="toc-section-number">3.2</span> Reproducing figures in the paper</a>
<ul>
<li><a href="#visualizing-empirical-time-series" id="toc-visualizing-empirical-time-series"><span class="toc-section-number">3.2.1</span> Visualizing empirical time series</a></li>
<li><a href="#visualizing-simulated-time-series" id="toc-visualizing-simulated-time-series"><span class="toc-section-number">3.2.2</span> Visualizing simulated time series</a></li>
</ul></li>
<li><a href="#sec-empirical-fitting" id="toc-sec-empirical-fitting"><span class="toc-section-number">3.3</span> Reproducing the analyses of the empirical dataset</a></li>
<li><a href="#sec-empirical-results" id="toc-sec-empirical-results"><span class="toc-section-number">3.4</span> Results</a></li>
</ul></li>
</ul>
</nav>
<section id="sec-intro" class="level1" data-number="1">
<h1 data-number="1"><span class="header-section-number">1</span> Introduction</h1>
<p>This document contains reproducible code of the manuscript by <span class="citation" data-cites="haqiqatkhah_2024_DailyDynamicsWeekly">Haqiqatkhah and Hamaker (<a href="#ref-haqiqatkhah_2024_DailyDynamicsWeekly" role="doc-biblioref">2024</a>)</span> on combining day-of-week effects and week-to-week dynamics with day-to-day dynamics. For attribution, please cite as</p>
<blockquote class="blockquote">
<p>Haqiqatkhah, M. M., & Hamaker, E. L. (2024, February 20). Daily dynamics and weekly rhythms: A tutorial on seasonal ARMA models combined with day-of-week effects. <em>PsyArXiv Preprints</em>. https://doi.org/10.31234/osf.io/duvqh</p>
</blockquote>
<p>This document has two main sections:</p>
<p>In <a href="#sec-functions">Section 2</a>, we present the functions used for making the visualizations (<a href="#sec-visualization">Section 2.1</a>), generating simulated time series (<a href="#sec-simulation">Section 2.2</a>), running the Shiny app accompanying the paper (<a href="#sec-shiny">Section 2.3</a>), and fitting models to empirical data (<a href="#sec-modeling">Section 2.4</a>).</p>
<p>In <a href="#sec-reproducing">Section 3</a>, we provide the empirical dataset and additional plots for empirical time series (<a href="#sec-investigate">Section 3.1</a>), which is followed by the reproducible code for generating figures shown in the paper (<a href="#sec-reproduce-figures">Section 3.2</a>), running all the the analyses on the empirical dataset (<a href="#sec-empirical-fitting">Section 3.3</a>) and making the tables reported in the paper (<a href="#sec-reproducing">Section 3</a>).</p>
<p>To replicate the study from the scratch, you should first either clone the repository (using <code>git clone https://github.com/psyguy/WeCycle.git</code>) or <a href="https://github.com/psyguy/WeCycle/archive/refs/heads/main.zip">download the repository as a zip file</a> and extract it on your machine. Then you can run the <code>.R</code> files you find in the <code>scripts</code> folder with the following order:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-1_94170652671b7093d27bfbceff515489">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1"></a><span class="fu">source</span>(<span class="st">"scripts/initialization.R"</span>)</span>
<span id="cb1-2"><a href="#cb1-2"></a><span class="fu">source</span>(<span class="st">"scripts/functions_simulation.R"</span>)</span>
<span id="cb1-3"><a href="#cb1-3"></a><span class="fu">source</span>(<span class="st">"scripts/functions_visualization.R"</span>)</span>
<span id="cb1-4"><a href="#cb1-4"></a><span class="fu">source</span>(<span class="st">"scripts/functions_modeling.R"</span>)</span>
<span id="cb1-5"><a href="#cb1-5"></a><span class="fu">source</span>(<span class="st">"scripts/run_figures.R"</span>)</span>
<span id="cb1-6"><a href="#cb1-6"></a><span class="fu">source</span>(<span class="st">"scripts/run_analyses.R"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Alternatively, if you have <a href="https://quarto.org/docs/get-started/">Quarto installed</a> installed on your machine, you can compile <code>index.qmd</code> located in the root directory using Quarto after setting the following variables to <code>TRUE</code>:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_a27a40301049d9deef2349c0541b1946">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1"></a>load_functions <span class="ot"><-</span> <span class="cn">FALSE</span></span>
<span id="cb2-2"><a href="#cb2-2"></a>run_figures <span class="ot"><-</span> <span class="cn">FALSE</span></span>
<span id="cb2-3"><a href="#cb2-3"></a>run_analyses <span class="ot"><-</span> <span class="cn">FALSE</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="sec-functions" class="level1" data-number="2">
<h1 data-number="2"><span class="header-section-number">2</span> R functions</h1>
<p>The code used for plotting the time series and fitting the models requires the time series <span class="math inline">\(y_t\)</span> to be stored in a data.frame (which, let us call <code>df</code>) with at least three columns:</p>
<ul>
<li><p><code>t</code>: Indicating the time of the measurement</p></li>
<li><p><code>y</code>: The value <span class="math inline">\(y_t\)</span> on time <span class="math inline">\(t\)</span></p></li>
<li><p><code>weekday</code> (or <code>weekday_num</code>): The name (or number) of the weekday corresponding to <code>t</code>. In the case of the former, it should be in the form of capitalized three letter codes (<code>"Mon"</code>, <code>"Tue"</code>, …, <code>"Sun"</code>). Note that we consider Monday to be the first day of the week, and Sunday be the 0th/7th day of the week.</p></li>
</ul>
<p>The column <code>weekday</code> (and <code>weekday_num</code>) can be generated if the date (e.g., as <code>date</code>) is included in <code>df</code>, using <code>lubridate::wday</code> and setting:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_9e688d5df7677938184009ef0c990ff9">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1"></a>df <span class="ot"><-</span> df <span class="sc">%>%</span> </span>
<span id="cb3-2"><a href="#cb3-2"></a> <span class="fu">mutate</span>(<span class="at">weekday =</span> lubridate<span class="sc">::</span><span class="fu">wday</span>(date,</span>
<span id="cb3-3"><a href="#cb3-3"></a> <span class="at">week_start =</span> <span class="dv">1</span>,</span>
<span id="cb3-4"><a href="#cb3-4"></a> <span class="at">label =</span> <span class="cn">TRUE</span>),</span>
<span id="cb3-5"><a href="#cb3-5"></a> <span class="at">weekday_num =</span> lubridate<span class="sc">::</span><span class="fu">wday</span>(date,</span>
<span id="cb3-6"><a href="#cb3-6"></a> <span class="at">week_start =</span> <span class="dv">1</span>,</span>
<span id="cb3-7"><a href="#cb3-7"></a> <span class="at">label =</span> <span class="cn">FALSE</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>The missing values in the time series should be explicitly indicated with <code>NA</code> in the dataframe—that is, we should have a row for each time point—which can be achieved by:</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-6_edf7d3c37e21b9d5403d112c883c5fa8">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1"></a>df <span class="ot"><-</span> df <span class="sc">%>%</span></span>
<span id="cb4-2"><a href="#cb4-2"></a> <span class="fu">right_join</span>(<span class="fu">data.frame</span>(<span class="at">t =</span> <span class="fu">min</span>(df<span class="sc">$</span>t)<span class="sc">:</span><span class="fu">max</span>(df<span class="sc">$</span>t)),</span>
<span id="cb4-3"><a href="#cb4-3"></a> <span class="at">by =</span> <span class="st">"t"</span>) <span class="sc">%>%</span> </span>
<span id="cb4-4"><a href="#cb4-4"></a> <span class="fu">arrange</span>(t)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<section id="sec-visualization" class="level2" data-number="2.1">
<h2 data-number="2.1" class="anchored" data-anchor-id="sec-visualization"><span class="header-section-number">2.1</span> Time series visualizations</h2>
<p>The visualizations shown in discussed in the paper were plotted using separate functions for each plot, that are named accordingly <code>plot_hist()</code> , <code>plot_seq()</code>, <code>plot_dowe()</code>, <code>plot_psd()</code>, <code>plot_acf()</code>, and <code>plot_pacf()</code>. The main argument of these functions is <code>d</code>, which can be a numerical vector (for which the weekdays are added, starting by Monday), or it can be a dataframe with the columns specifiedexplained earlier.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_edc670809335b37dbd65db8b6373333b">
<details>
<summary>Click to reveal <code>plot_hist()</code></summary>
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1"></a>plot_hist <span class="ot"><-</span> <span class="cf">function</span>(<span class="at">d =</span> <span class="cn">NULL</span>,</span>
<span id="cb5-2"><a href="#cb5-2"></a> <span class="at">title =</span> <span class="st">" "</span>,</span>
<span id="cb5-3"><a href="#cb5-3"></a> <span class="at">subtitle =</span> <span class="cn">NULL</span>,</span>
<span id="cb5-4"><a href="#cb5-4"></a> <span class="at">remove_titles =</span> <span class="cn">TRUE</span>,</span>
<span id="cb5-5"><a href="#cb5-5"></a> <span class="at">remove_xlab =</span> <span class="cn">TRUE</span>,</span>
<span id="cb5-6"><a href="#cb5-6"></a> <span class="at">scale_rel =</span> <span class="fl">0.9</span>,</span>
<span id="cb5-7"><a href="#cb5-7"></a> <span class="at">max_acf.lag =</span> <span class="dv">35</span>,</span>
<span id="cb5-8"><a href="#cb5-8"></a> <span class="at">max_period =</span> <span class="dv">15</span>,</span>
<span id="cb5-9"><a href="#cb5-9"></a> <span class="at">ymin =</span> <span class="dv">0</span><span class="fl">-0.1</span>,</span>
<span id="cb5-10"><a href="#cb5-10"></a> <span class="at">ymax =</span> <span class="dv">4</span><span class="fl">+0.1</span>,</span>
<span id="cb5-11"><a href="#cb5-11"></a> <span class="at">max_t =</span> <span class="dv">140</span>,</span>
<span id="cb5-12"><a href="#cb5-12"></a> <span class="at">max_weeks =</span> <span class="dv">25</span>,</span>
<span id="cb5-13"><a href="#cb5-13"></a> <span class="at">col_weekly =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb5-14"><a href="#cb5-14"></a> <span class="at">col_dowe.line =</span> <span class="st">"mediumorchid4"</span>,</span>
<span id="cb5-15"><a href="#cb5-15"></a> <span class="at">col_dowe.point =</span> <span class="st">"deeppink1"</span>,</span>
<span id="cb5-16"><a href="#cb5-16"></a> <span class="at">col_ts =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb5-17"><a href="#cb5-17"></a> <span class="at">col_ts.point =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb5-18"><a href="#cb5-18"></a> <span class="at">col_hist =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb5-19"><a href="#cb5-19"></a> <span class="at">col_acf =</span> <span class="st">"darkolivegreen3"</span>,</span>
<span id="cb5-20"><a href="#cb5-20"></a> <span class="at">col_pacf =</span> <span class="st">"darkorange3"</span>,</span>
<span id="cb5-21"><a href="#cb5-21"></a> <span class="at">col_spec =</span> <span class="st">"darkorchid4"</span>,</span>
<span id="cb5-22"><a href="#cb5-22"></a> <span class="at">col_hlines =</span> <span class="st">"dimgray"</span>) {</span>
<span id="cb5-23"><a href="#cb5-23"></a></span>
<span id="cb5-24"><a href="#cb5-24"></a> <span class="co"># Transforming the input to an appropriate dataframe</span></span>
<span id="cb5-25"><a href="#cb5-25"></a> d <span class="ot"><-</span> d <span class="sc">%>%</span> <span class="fu">data_shaper</span>()</span>
<span id="cb5-26"><a href="#cb5-26"></a></span>
<span id="cb5-27"><a href="#cb5-27"></a> <span class="co"># Making sure the optimal theme is in place</span></span>
<span id="cb5-28"><a href="#cb5-28"></a> <span class="fu">theme_set</span>(ggthemes<span class="sc">::</span><span class="fu">theme_few</span>())</span>
<span id="cb5-29"><a href="#cb5-29"></a></span>
<span id="cb5-30"><a href="#cb5-30"></a> breaks_y <span class="ot"><-</span> <span class="fu">seq</span>(<span class="fu">floor</span>(ymin),</span>
<span id="cb5-31"><a href="#cb5-31"></a> <span class="fu">ceiling</span>(ymax))</span>
<span id="cb5-32"><a href="#cb5-32"></a> <span class="co"># Making sure the limits are not off</span></span>
<span id="cb5-33"><a href="#cb5-33"></a> ymin <span class="ot"><-</span> <span class="fu">min</span>(<span class="fu">min</span>(d<span class="sc">$</span>y), ymin)</span>
<span id="cb5-34"><a href="#cb5-34"></a> ymax <span class="ot"><-</span> <span class="fu">max</span>(<span class="fu">max</span>(d<span class="sc">$</span>y), ymax)</span>
<span id="cb5-35"><a href="#cb5-35"></a></span>
<span id="cb5-36"><a href="#cb5-36"></a> p_out <span class="ot"><-</span> d <span class="sc">%>%</span></span>
<span id="cb5-37"><a href="#cb5-37"></a> <span class="fu">mutate</span>(<span class="at">group_mean =</span> <span class="fu">mean</span>(y,</span>
<span id="cb5-38"><a href="#cb5-38"></a> <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%>%</span></span>
<span id="cb5-39"><a href="#cb5-39"></a> <span class="fu">group_by</span>(weekday,</span>
<span id="cb5-40"><a href="#cb5-40"></a> <span class="at">.add =</span> <span class="cn">TRUE</span>) <span class="sc">%>%</span></span>
<span id="cb5-41"><a href="#cb5-41"></a> <span class="fu">mutate</span>(<span class="at">weekday_mean =</span> <span class="fu">mean</span>(y,</span>
<span id="cb5-42"><a href="#cb5-42"></a> <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%>%</span></span>
<span id="cb5-43"><a href="#cb5-43"></a> <span class="fu">ungroup</span>() <span class="sc">%>%</span></span>
<span id="cb5-44"><a href="#cb5-44"></a> <span class="fu">ggplot</span>() <span class="sc">+</span></span>
<span id="cb5-45"><a href="#cb5-45"></a> <span class="fu">aes</span>(<span class="at">x =</span> y) <span class="sc">+</span></span>
<span id="cb5-46"><a href="#cb5-46"></a> <span class="fu">geom_histogram</span>(</span>
<span id="cb5-47"><a href="#cb5-47"></a> <span class="fu">aes</span>(<span class="at">y =</span> <span class="fu">after_stat</span>(ndensity)),</span>
<span id="cb5-48"><a href="#cb5-48"></a> <span class="at">center =</span> <span class="dv">0</span>,</span>
<span id="cb5-49"><a href="#cb5-49"></a> <span class="at">bins =</span> <span class="dv">40</span>,</span>
<span id="cb5-50"><a href="#cb5-50"></a> <span class="at">fill =</span> col_hist</span>
<span id="cb5-51"><a href="#cb5-51"></a> ) <span class="sc">+</span></span>
<span id="cb5-52"><a href="#cb5-52"></a> <span class="fu">geom_vline</span>(</span>
<span id="cb5-53"><a href="#cb5-53"></a> <span class="fu">aes</span>(<span class="at">xintercept =</span> group_mean),</span>
<span id="cb5-54"><a href="#cb5-54"></a> <span class="at">linetype =</span> <span class="st">"dashed"</span>,</span>
<span id="cb5-55"><a href="#cb5-55"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.2</span>)</span>
<span id="cb5-56"><a href="#cb5-56"></a> ) <span class="sc">+</span></span>
<span id="cb5-57"><a href="#cb5-57"></a> <span class="fu">labs</span>(<span class="at">subtitle =</span> <span class="st">"Distribution"</span>,</span>
<span id="cb5-58"><a href="#cb5-58"></a> <span class="at">x =</span> <span class="st">"y"</span>,</span>
<span id="cb5-59"><a href="#cb5-59"></a> <span class="at">y =</span> title) <span class="sc">+</span></span>
<span id="cb5-60"><a href="#cb5-60"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> breaks_y) <span class="sc">+</span></span>
<span id="cb5-61"><a href="#cb5-61"></a> <span class="fu">xlim</span>(ymin, ymax) <span class="sc">+</span></span>
<span id="cb5-62"><a href="#cb5-62"></a> <span class="fu">theme</span>(</span>
<span id="cb5-63"><a href="#cb5-63"></a> <span class="at">panel.grid.major =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb5-64"><a href="#cb5-64"></a> <span class="co"># axis.title.y = element_blank(),</span></span>
<span id="cb5-65"><a href="#cb5-65"></a> <span class="at">axis.ticks.y =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb5-66"><a href="#cb5-66"></a> <span class="at">axis.line.y =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb5-67"><a href="#cb5-67"></a> <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="fu">rel</span>(<span class="fl">1.4</span><span class="sc">*</span>scale_rel)),</span>
<span id="cb5-68"><a href="#cb5-68"></a> <span class="at">axis.text.y =</span> <span class="fu">element_blank</span>()</span>
<span id="cb5-69"><a href="#cb5-69"></a> )</span>
<span id="cb5-70"><a href="#cb5-70"></a></span>
<span id="cb5-71"><a href="#cb5-71"></a> <span class="cf">if</span> (remove_titles)</span>
<span id="cb5-72"><a href="#cb5-72"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">theme</span>(<span class="at">plot.subtitle =</span> <span class="fu">element_blank</span>())</span>
<span id="cb5-73"><a href="#cb5-73"></a> <span class="cf">if</span> (remove_xlab)</span>
<span id="cb5-74"><a href="#cb5-74"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">xlab</span>(<span class="cn">NULL</span>)</span>
<span id="cb5-75"><a href="#cb5-75"></a></span>
<span id="cb5-76"><a href="#cb5-76"></a> p_out</span>
<span id="cb5-77"><a href="#cb5-77"></a></span>
<span id="cb5-78"><a href="#cb5-78"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-8_baf0d0268a9fb6ae506b7857af63c464">
<details>
<summary>Click to reveal <code>plot_seq()</code></summary>
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1"></a>plot_seq <span class="ot"><-</span> <span class="cf">function</span>(<span class="at">d =</span> <span class="cn">NULL</span>,</span>
<span id="cb6-2"><a href="#cb6-2"></a> <span class="at">title =</span> <span class="cn">NULL</span>,</span>
<span id="cb6-3"><a href="#cb6-3"></a> <span class="at">subtitle =</span> <span class="cn">NULL</span>,</span>
<span id="cb6-4"><a href="#cb6-4"></a> <span class="at">remove_titles =</span> <span class="cn">TRUE</span>,</span>
<span id="cb6-5"><a href="#cb6-5"></a> <span class="at">remove_xlab =</span> <span class="cn">TRUE</span>,</span>
<span id="cb6-6"><a href="#cb6-6"></a> <span class="at">scale_rel =</span> <span class="fl">0.9</span>,</span>
<span id="cb6-7"><a href="#cb6-7"></a> <span class="at">max_acf.lag =</span> <span class="dv">35</span>,</span>
<span id="cb6-8"><a href="#cb6-8"></a> <span class="at">max_period =</span> <span class="dv">15</span>,</span>
<span id="cb6-9"><a href="#cb6-9"></a> <span class="at">ymin =</span> <span class="dv">0</span><span class="fl">-0.1</span>,</span>
<span id="cb6-10"><a href="#cb6-10"></a> <span class="at">ymax =</span> <span class="dv">4</span><span class="fl">+0.1</span>,</span>
<span id="cb6-11"><a href="#cb6-11"></a> <span class="at">max_t =</span> <span class="dv">140</span>,</span>
<span id="cb6-12"><a href="#cb6-12"></a> <span class="at">max_weeks =</span> <span class="dv">25</span>,</span>
<span id="cb6-13"><a href="#cb6-13"></a> <span class="at">col_weekly =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb6-14"><a href="#cb6-14"></a> <span class="at">col_dowe.line =</span> <span class="st">"mediumorchid4"</span>,</span>
<span id="cb6-15"><a href="#cb6-15"></a> <span class="at">col_dowe.point =</span> <span class="st">"deeppink1"</span>,</span>
<span id="cb6-16"><a href="#cb6-16"></a> <span class="at">col_ts =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb6-17"><a href="#cb6-17"></a> <span class="at">col_ts.point =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb6-18"><a href="#cb6-18"></a> <span class="at">col_hist =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb6-19"><a href="#cb6-19"></a> <span class="at">col_acf =</span> <span class="st">"darkolivegreen3"</span>,</span>
<span id="cb6-20"><a href="#cb6-20"></a> <span class="at">col_pacf =</span> <span class="st">"darkorange3"</span>,</span>
<span id="cb6-21"><a href="#cb6-21"></a> <span class="at">col_spec =</span> <span class="st">"darkorchid4"</span>,</span>
<span id="cb6-22"><a href="#cb6-22"></a> <span class="at">col_hlines =</span> <span class="st">"dimgray"</span>) {</span>
<span id="cb6-23"><a href="#cb6-23"></a></span>
<span id="cb6-24"><a href="#cb6-24"></a></span>
<span id="cb6-25"><a href="#cb6-25"></a> <span class="co"># Transforming the input to an appropriate dataframe</span></span>
<span id="cb6-26"><a href="#cb6-26"></a> d <span class="ot"><-</span> d <span class="sc">%>%</span> <span class="fu">data_shaper</span>()</span>
<span id="cb6-27"><a href="#cb6-27"></a></span>
<span id="cb6-28"><a href="#cb6-28"></a> <span class="co"># Making sure the optimal theme is in place</span></span>
<span id="cb6-29"><a href="#cb6-29"></a> <span class="fu">theme_set</span>(ggthemes<span class="sc">::</span><span class="fu">theme_few</span>())</span>
<span id="cb6-30"><a href="#cb6-30"></a></span>
<span id="cb6-31"><a href="#cb6-31"></a> <span class="co"># Making sure the limits are not off</span></span>
<span id="cb6-32"><a href="#cb6-32"></a> ymin <span class="ot"><-</span> <span class="fu">min</span>(<span class="fu">min</span>(d<span class="sc">$</span>y), ymin)</span>
<span id="cb6-33"><a href="#cb6-33"></a> ymax <span class="ot"><-</span> <span class="fu">max</span>(<span class="fu">max</span>(d<span class="sc">$</span>y), ymax)</span>
<span id="cb6-34"><a href="#cb6-34"></a></span>
<span id="cb6-35"><a href="#cb6-35"></a> p_out <span class="ot"><-</span> d <span class="sc">%>%</span></span>
<span id="cb6-36"><a href="#cb6-36"></a> <span class="fu">data_shaper</span>() <span class="sc">%>%</span></span>
<span id="cb6-37"><a href="#cb6-37"></a> <span class="fu">mutate</span>(<span class="at">group_mean =</span> <span class="fu">mean</span>(y,</span>
<span id="cb6-38"><a href="#cb6-38"></a> <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%>%</span></span>
<span id="cb6-39"><a href="#cb6-39"></a> <span class="fu">group_by</span>(weekday,</span>
<span id="cb6-40"><a href="#cb6-40"></a> <span class="at">.add =</span> <span class="cn">TRUE</span>) <span class="sc">%>%</span></span>
<span id="cb6-41"><a href="#cb6-41"></a> <span class="fu">mutate</span>(<span class="at">weekday_mean =</span> <span class="fu">mean</span>(y,</span>
<span id="cb6-42"><a href="#cb6-42"></a> <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%>%</span></span>
<span id="cb6-43"><a href="#cb6-43"></a> <span class="fu">ungroup</span>() <span class="sc">%>%</span></span>
<span id="cb6-44"><a href="#cb6-44"></a> <span class="fu">ggplot</span>() <span class="sc">+</span></span>
<span id="cb6-45"><a href="#cb6-45"></a> <span class="fu">aes</span>(<span class="at">x =</span> t,</span>
<span id="cb6-46"><a href="#cb6-46"></a> <span class="at">y =</span> y) <span class="sc">+</span></span>
<span id="cb6-47"><a href="#cb6-47"></a> <span class="fu">geom_hline</span>(</span>
<span id="cb6-48"><a href="#cb6-48"></a> <span class="fu">aes</span>(<span class="at">yintercept =</span> group_mean),</span>
<span id="cb6-49"><a href="#cb6-49"></a> <span class="at">linetype =</span> <span class="st">"dashed"</span>,</span>
<span id="cb6-50"><a href="#cb6-50"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.2</span>)</span>
<span id="cb6-51"><a href="#cb6-51"></a> ) <span class="sc">+</span></span>
<span id="cb6-52"><a href="#cb6-52"></a> <span class="fu">geom_line</span>(</span>
<span id="cb6-53"><a href="#cb6-53"></a> <span class="at">color =</span> col_ts,</span>
<span id="cb6-54"><a href="#cb6-54"></a> <span class="at">alpha =</span> <span class="dv">1</span>,</span>
<span id="cb6-55"><a href="#cb6-55"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.2</span>)</span>
<span id="cb6-56"><a href="#cb6-56"></a> ) <span class="sc">+</span></span>
<span id="cb6-57"><a href="#cb6-57"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">y =</span> y),</span>
<span id="cb6-58"><a href="#cb6-58"></a> <span class="at">color =</span> col_ts.point,</span>
<span id="cb6-59"><a href="#cb6-59"></a> <span class="at">size =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.12</span>)) <span class="sc">+</span></span>
<span id="cb6-60"><a href="#cb6-60"></a> <span class="fu">scale_y_continuous</span>(<span class="co"># breaks = breaks_y,</span></span>
<span id="cb6-61"><a href="#cb6-61"></a> <span class="at">limits =</span> <span class="fu">c</span>(ymin, ymax)) <span class="sc">+</span></span>
<span id="cb6-62"><a href="#cb6-62"></a> <span class="fu">xlim</span>(<span class="dv">0</span>, max_t) <span class="sc">+</span></span>
<span id="cb6-63"><a href="#cb6-63"></a> <span class="fu">labs</span>(<span class="at">subtitle =</span> <span class="st">"Sequence plot"</span>,</span>
<span id="cb6-64"><a href="#cb6-64"></a> <span class="at">x =</span> <span class="st">"t"</span>,</span>
<span id="cb6-65"><a href="#cb6-65"></a> <span class="at">y =</span> <span class="st">"y"</span>)</span>
<span id="cb6-66"><a href="#cb6-66"></a></span>
<span id="cb6-67"><a href="#cb6-67"></a> <span class="cf">if</span> (remove_titles)</span>
<span id="cb6-68"><a href="#cb6-68"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">theme</span>(<span class="at">plot.subtitle =</span> <span class="fu">element_blank</span>())</span>
<span id="cb6-69"><a href="#cb6-69"></a> <span class="cf">if</span> (remove_xlab)</span>
<span id="cb6-70"><a href="#cb6-70"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">xlab</span>(<span class="cn">NULL</span>)</span>
<span id="cb6-71"><a href="#cb6-71"></a> p_out</span>
<span id="cb6-72"><a href="#cb6-72"></a></span>
<span id="cb6-73"><a href="#cb6-73"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-9_0eca9110cb3884664524b05eb46051c4">
<details>
<summary>Click to reveal <code>plot_dowe()</code></summary>
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1"></a>plot_dowe <span class="ot"><-</span> <span class="cf">function</span>(<span class="at">d =</span> <span class="cn">NULL</span>,</span>
<span id="cb7-2"><a href="#cb7-2"></a> <span class="at">title =</span> <span class="cn">NULL</span>,</span>
<span id="cb7-3"><a href="#cb7-3"></a> <span class="at">subtitle =</span> <span class="cn">NULL</span>,</span>
<span id="cb7-4"><a href="#cb7-4"></a> <span class="at">remove_titles =</span> <span class="cn">TRUE</span>,</span>
<span id="cb7-5"><a href="#cb7-5"></a> <span class="at">remove_xlab =</span> <span class="cn">TRUE</span>,</span>
<span id="cb7-6"><a href="#cb7-6"></a> <span class="at">scale_rel =</span> <span class="fl">0.9</span>,</span>
<span id="cb7-7"><a href="#cb7-7"></a> <span class="at">max_acf.lag =</span> <span class="dv">35</span>,</span>
<span id="cb7-8"><a href="#cb7-8"></a> <span class="at">max_period =</span> <span class="dv">15</span>,</span>
<span id="cb7-9"><a href="#cb7-9"></a> <span class="at">ymin =</span> <span class="dv">0</span><span class="fl">-0.1</span>,</span>
<span id="cb7-10"><a href="#cb7-10"></a> <span class="at">ymax =</span> <span class="dv">4</span><span class="fl">+0.1</span>,</span>
<span id="cb7-11"><a href="#cb7-11"></a> <span class="at">max_t =</span> <span class="dv">140</span>,</span>
<span id="cb7-12"><a href="#cb7-12"></a> <span class="at">max_weeks =</span> <span class="dv">25</span>,</span>
<span id="cb7-13"><a href="#cb7-13"></a> <span class="at">col_weekly =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb7-14"><a href="#cb7-14"></a> <span class="at">col_dowe.line =</span> <span class="st">"mediumorchid4"</span>,</span>
<span id="cb7-15"><a href="#cb7-15"></a> <span class="at">col_dowe.point =</span> <span class="st">"deeppink1"</span>,</span>
<span id="cb7-16"><a href="#cb7-16"></a> <span class="at">col_ts =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb7-17"><a href="#cb7-17"></a> <span class="at">col_ts.point =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb7-18"><a href="#cb7-18"></a> <span class="at">col_hist =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb7-19"><a href="#cb7-19"></a> <span class="at">col_acf =</span> <span class="st">"darkolivegreen3"</span>,</span>
<span id="cb7-20"><a href="#cb7-20"></a> <span class="at">col_pacf =</span> <span class="st">"darkorange3"</span>,</span>
<span id="cb7-21"><a href="#cb7-21"></a> <span class="at">col_spec =</span> <span class="st">"darkorchid4"</span>,</span>
<span id="cb7-22"><a href="#cb7-22"></a> <span class="at">col_hlines =</span> <span class="st">"dimgray"</span>) {</span>
<span id="cb7-23"><a href="#cb7-23"></a></span>
<span id="cb7-24"><a href="#cb7-24"></a> <span class="co"># Transforming the input to an appropriate dataframe</span></span>
<span id="cb7-25"><a href="#cb7-25"></a> d <span class="ot"><-</span> d <span class="sc">%>%</span> <span class="fu">data_shaper</span>()</span>
<span id="cb7-26"><a href="#cb7-26"></a></span>
<span id="cb7-27"><a href="#cb7-27"></a> <span class="co"># Making sure the optimal theme is in place</span></span>
<span id="cb7-28"><a href="#cb7-28"></a> <span class="fu">theme_set</span>(ggthemes<span class="sc">::</span><span class="fu">theme_few</span>())</span>
<span id="cb7-29"><a href="#cb7-29"></a></span>
<span id="cb7-30"><a href="#cb7-30"></a> <span class="co"># Making sure the limits are not off</span></span>
<span id="cb7-31"><a href="#cb7-31"></a> ymin <span class="ot"><-</span> <span class="fu">min</span>(<span class="fu">min</span>(d<span class="sc">$</span>y), ymin)</span>
<span id="cb7-32"><a href="#cb7-32"></a> ymax <span class="ot"><-</span> <span class="fu">max</span>(<span class="fu">max</span>(d<span class="sc">$</span>y), ymax)</span>
<span id="cb7-33"><a href="#cb7-33"></a></span>
<span id="cb7-34"><a href="#cb7-34"></a> p_out <span class="ot"><-</span> d <span class="sc">%>%</span></span>
<span id="cb7-35"><a href="#cb7-35"></a> <span class="fu">data_shaper</span>() <span class="sc">%>%</span></span>
<span id="cb7-36"><a href="#cb7-36"></a> <span class="fu">mutate</span>(<span class="at">group_mean =</span> <span class="fu">mean</span>(y,</span>
<span id="cb7-37"><a href="#cb7-37"></a> <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%>%</span></span>
<span id="cb7-38"><a href="#cb7-38"></a> <span class="fu">group_by</span>(weekday,</span>
<span id="cb7-39"><a href="#cb7-39"></a> <span class="at">.add =</span> <span class="cn">TRUE</span>) <span class="sc">%>%</span></span>
<span id="cb7-40"><a href="#cb7-40"></a> <span class="fu">mutate</span>(<span class="at">weekday_mean =</span> <span class="fu">mean</span>(y,</span>
<span id="cb7-41"><a href="#cb7-41"></a> <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%>%</span></span>
<span id="cb7-42"><a href="#cb7-42"></a> <span class="fu">ungroup</span>() <span class="sc">%>%</span></span>
<span id="cb7-43"><a href="#cb7-43"></a> <span class="fu">group_by</span>(week_num,</span>
<span id="cb7-44"><a href="#cb7-44"></a> <span class="at">.add =</span> <span class="cn">FALSE</span>) <span class="sc">%>%</span></span>
<span id="cb7-45"><a href="#cb7-45"></a> <span class="fu">filter</span>(week_num <span class="sc"><=</span> max_weeks) <span class="sc">%>%</span></span>
<span id="cb7-46"><a href="#cb7-46"></a> <span class="fu">ggplot</span>() <span class="sc">+</span></span>
<span id="cb7-47"><a href="#cb7-47"></a> <span class="fu">aes</span>(<span class="at">x =</span> weekday,</span>
<span id="cb7-48"><a href="#cb7-48"></a> <span class="at">y =</span> y,</span>
<span id="cb7-49"><a href="#cb7-49"></a> <span class="at">group =</span> week_num) <span class="sc">+</span></span>
<span id="cb7-50"><a href="#cb7-50"></a> <span class="fu">geom_hline</span>(</span>
<span id="cb7-51"><a href="#cb7-51"></a> <span class="fu">aes</span>(<span class="at">yintercept =</span> group_mean),</span>
<span id="cb7-52"><a href="#cb7-52"></a> <span class="at">linetype =</span> <span class="st">"dashed"</span>,</span>
<span id="cb7-53"><a href="#cb7-53"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.2</span>),</span>
<span id="cb7-54"><a href="#cb7-54"></a> <span class="at">alpha =</span> <span class="dv">1</span></span>
<span id="cb7-55"><a href="#cb7-55"></a> ) <span class="sc">+</span></span>
<span id="cb7-56"><a href="#cb7-56"></a> <span class="fu">geom_line</span>(</span>
<span id="cb7-57"><a href="#cb7-57"></a> <span class="at">alpha =</span> <span class="fl">0.5</span>,</span>
<span id="cb7-58"><a href="#cb7-58"></a> <span class="at">color =</span> col_weekly,</span>
<span id="cb7-59"><a href="#cb7-59"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.4</span>)</span>
<span id="cb7-60"><a href="#cb7-60"></a> ) <span class="sc">+</span></span>
<span id="cb7-61"><a href="#cb7-61"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">y =</span> y),</span>
<span id="cb7-62"><a href="#cb7-62"></a> <span class="at">alpha =</span> <span class="fl">0.6</span>,</span>
<span id="cb7-63"><a href="#cb7-63"></a> <span class="at">color =</span> col_ts.point,</span>
<span id="cb7-64"><a href="#cb7-64"></a> <span class="at">size =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.12</span>)) <span class="sc">+</span></span>
<span id="cb7-65"><a href="#cb7-65"></a> <span class="fu">geom_line</span>(</span>
<span id="cb7-66"><a href="#cb7-66"></a> <span class="fu">aes</span>(<span class="at">y =</span> weekday_mean),</span>
<span id="cb7-67"><a href="#cb7-67"></a> <span class="at">color =</span> col_dowe.line,</span>
<span id="cb7-68"><a href="#cb7-68"></a> <span class="at">alpha =</span> <span class="dv">1</span>,</span>
<span id="cb7-69"><a href="#cb7-69"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="dv">1</span>)</span>
<span id="cb7-70"><a href="#cb7-70"></a> ) <span class="sc">+</span></span>
<span id="cb7-71"><a href="#cb7-71"></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">y =</span> weekday_mean),</span>
<span id="cb7-72"><a href="#cb7-72"></a> <span class="at">color =</span> col_dowe.point,</span>
<span id="cb7-73"><a href="#cb7-73"></a> <span class="at">size =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.8</span>)) <span class="sc">+</span></span>
<span id="cb7-74"><a href="#cb7-74"></a> <span class="fu">labs</span>(<span class="at">subtitle =</span> <span class="st">"Weekly plot"</span>,</span>
<span id="cb7-75"><a href="#cb7-75"></a> <span class="at">x =</span> <span class="st">"Weekdays"</span>,</span>
<span id="cb7-76"><a href="#cb7-76"></a> <span class="at">y =</span> <span class="st">"y"</span>) <span class="sc">+</span></span>
<span id="cb7-77"><a href="#cb7-77"></a> <span class="fu">scale_y_continuous</span>(<span class="co">#breaks = breaks_y,</span></span>
<span id="cb7-78"><a href="#cb7-78"></a> <span class="at">limits =</span> <span class="fu">c</span>(ymin, ymax)) <span class="sc">+</span></span>
<span id="cb7-79"><a href="#cb7-79"></a> <span class="fu">theme</span>(<span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb7-80"><a href="#cb7-80"></a> <span class="at">axis.title.y =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb7-81"><a href="#cb7-81"></a> <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">angle =</span> <span class="dv">90</span>,</span>
<span id="cb7-82"><a href="#cb7-82"></a> <span class="at">size =</span> <span class="fu">rel</span>(<span class="dv">1</span> <span class="sc">*</span> scale_rel)))</span>
<span id="cb7-83"><a href="#cb7-83"></a></span>
<span id="cb7-84"><a href="#cb7-84"></a> <span class="cf">if</span> (remove_titles)</span>
<span id="cb7-85"><a href="#cb7-85"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">theme</span>(<span class="at">plot.subtitle =</span> <span class="fu">element_blank</span>())</span>
<span id="cb7-86"><a href="#cb7-86"></a> <span class="cf">if</span> (remove_xlab)</span>
<span id="cb7-87"><a href="#cb7-87"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">xlab</span>(<span class="cn">NULL</span>)</span>
<span id="cb7-88"><a href="#cb7-88"></a> p_out</span>
<span id="cb7-89"><a href="#cb7-89"></a></span>
<span id="cb7-90"><a href="#cb7-90"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-10_e31cf287a054841231430870c8747683">
<details>
<summary>Click to reveal <code>plot_psd()</code></summary>
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1"></a>plot_psd <span class="ot"><-</span> <span class="cf">function</span>(<span class="at">d =</span> <span class="cn">NULL</span>,</span>
<span id="cb8-2"><a href="#cb8-2"></a> <span class="at">title =</span> <span class="cn">NULL</span>,</span>
<span id="cb8-3"><a href="#cb8-3"></a> <span class="at">subtitle =</span> <span class="cn">NULL</span>,</span>
<span id="cb8-4"><a href="#cb8-4"></a> <span class="at">remove_titles =</span> <span class="cn">TRUE</span>,</span>
<span id="cb8-5"><a href="#cb8-5"></a> <span class="at">remove_xlab =</span> <span class="cn">TRUE</span>,</span>
<span id="cb8-6"><a href="#cb8-6"></a> <span class="at">scale_rel =</span> <span class="fl">0.9</span>,</span>
<span id="cb8-7"><a href="#cb8-7"></a> <span class="at">max_acf.lag =</span> <span class="dv">35</span>,</span>
<span id="cb8-8"><a href="#cb8-8"></a> <span class="at">max_period =</span> <span class="dv">15</span>,</span>
<span id="cb8-9"><a href="#cb8-9"></a> <span class="at">ymin =</span> <span class="dv">0</span><span class="fl">-0.1</span>,</span>
<span id="cb8-10"><a href="#cb8-10"></a> <span class="at">ymax =</span> <span class="dv">4</span><span class="fl">+0.1</span>,</span>
<span id="cb8-11"><a href="#cb8-11"></a> <span class="at">max_t =</span> <span class="dv">140</span>,</span>
<span id="cb8-12"><a href="#cb8-12"></a> <span class="at">max_weeks =</span> <span class="dv">25</span>,</span>
<span id="cb8-13"><a href="#cb8-13"></a> <span class="at">col_weekly =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb8-14"><a href="#cb8-14"></a> <span class="at">col_dowe.line =</span> <span class="st">"mediumorchid4"</span>,</span>
<span id="cb8-15"><a href="#cb8-15"></a> <span class="at">col_dowe.point =</span> <span class="st">"deeppink1"</span>,</span>
<span id="cb8-16"><a href="#cb8-16"></a> <span class="at">col_ts =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb8-17"><a href="#cb8-17"></a> <span class="at">col_ts.point =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb8-18"><a href="#cb8-18"></a> <span class="at">col_hist =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb8-19"><a href="#cb8-19"></a> <span class="at">col_acf =</span> <span class="st">"darkolivegreen3"</span>,</span>
<span id="cb8-20"><a href="#cb8-20"></a> <span class="at">col_pacf =</span> <span class="st">"darkorange3"</span>,</span>
<span id="cb8-21"><a href="#cb8-21"></a> <span class="at">col_spec =</span> <span class="st">"darkorchid4"</span>,</span>
<span id="cb8-22"><a href="#cb8-22"></a> <span class="at">col_hlines =</span> <span class="st">"dimgray"</span>) {</span>
<span id="cb8-23"><a href="#cb8-23"></a></span>
<span id="cb8-24"><a href="#cb8-24"></a> <span class="co"># Transforming the input to an appropriate dataframe</span></span>
<span id="cb8-25"><a href="#cb8-25"></a> d <span class="ot"><-</span> d <span class="sc">%>%</span> <span class="fu">data_shaper</span>()</span>
<span id="cb8-26"><a href="#cb8-26"></a></span>
<span id="cb8-27"><a href="#cb8-27"></a> <span class="co"># Making sure the optimal theme is in place</span></span>
<span id="cb8-28"><a href="#cb8-28"></a> <span class="fu">theme_set</span>(ggthemes<span class="sc">::</span><span class="fu">theme_few</span>())</span>
<span id="cb8-29"><a href="#cb8-29"></a></span>
<span id="cb8-30"><a href="#cb8-30"></a> <span class="co"># Imputing the missing values using seasonal Kalman smoothing</span></span>
<span id="cb8-31"><a href="#cb8-31"></a> y_imp <span class="ot"><-</span> d<span class="sc">$</span>y <span class="sc">%>%</span></span>
<span id="cb8-32"><a href="#cb8-32"></a> <span class="fu">ts</span>(<span class="at">frequency =</span> <span class="dv">7</span>) <span class="sc">%>%</span></span>
<span id="cb8-33"><a href="#cb8-33"></a> imputeTS<span class="sc">::</span><span class="fu">na_kalman</span>()</span>
<span id="cb8-34"><a href="#cb8-34"></a></span>
<span id="cb8-35"><a href="#cb8-35"></a> <span class="do">## Calculate Fourier components</span></span>
<span id="cb8-36"><a href="#cb8-36"></a> y_imp <span class="ot"><-</span> y_imp <span class="sc">%>%</span> as.numeric</span>
<span id="cb8-37"><a href="#cb8-37"></a> n <span class="ot"><-</span> <span class="fu">length</span>(y_imp)</span>
<span id="cb8-38"><a href="#cb8-38"></a> Freq <span class="ot">=</span> (<span class="dv">1</span><span class="sc">:</span>n <span class="sc">-</span> <span class="dv">1</span>) <span class="sc">/</span> n</span>
<span id="cb8-39"><a href="#cb8-39"></a> var_component <span class="ot"><-</span> <span class="fu">Mod</span>(<span class="fu">fft</span>(<span class="fu">scale</span>(y_imp, <span class="at">scale =</span> <span class="cn">FALSE</span>))) <span class="sc">^</span> <span class="dv">2</span> <span class="sc">/</span> n<span class="sc">^</span><span class="dv">2</span></span>
<span id="cb8-40"><a href="#cb8-40"></a> df_fourier <span class="ot"><-</span> <span class="fu">data.frame</span>(<span class="at">Freq =</span> Freq,</span>
<span id="cb8-41"><a href="#cb8-41"></a> <span class="at">rel_power =</span> <span class="dv">100</span><span class="sc">*</span>var_component<span class="sc">/</span><span class="fu">var</span>(y_imp))<span class="sc">%>%</span></span>
<span id="cb8-42"><a href="#cb8-42"></a> <span class="fu">mutate</span>(<span class="at">Period =</span> <span class="fu">round</span>(<span class="dv">1</span> <span class="sc">/</span> Freq, <span class="dv">1</span>)) <span class="sc">%>%</span></span>
<span id="cb8-43"><a href="#cb8-43"></a> <span class="fu">filter</span>(Freq <span class="sc">!=</span> <span class="dv">0</span>,</span>
<span id="cb8-44"><a href="#cb8-44"></a> Freq <span class="sc"><=</span> <span class="fl">0.5</span>,</span>
<span id="cb8-45"><a href="#cb8-45"></a> Period <span class="sc"><=</span> max_period) <span class="sc">%>%</span></span>
<span id="cb8-46"><a href="#cb8-46"></a> <span class="fu">summarise</span>(<span class="at">rel_power =</span> <span class="fu">sum</span>(rel_power),</span>
<span id="cb8-47"><a href="#cb8-47"></a> <span class="at">.by =</span> Period) <span class="sc">%>%</span></span>
<span id="cb8-48"><a href="#cb8-48"></a> <span class="fu">mutate</span>(<span class="at">Freq =</span> <span class="dv">1</span> <span class="sc">/</span> Period,</span>
<span id="cb8-49"><a href="#cb8-49"></a> <span class="at">.before =</span> <span class="dv">1</span>)</span>
<span id="cb8-50"><a href="#cb8-50"></a></span>
<span id="cb8-51"><a href="#cb8-51"></a> max_var_component <span class="ot"><-</span> <span class="fu">max</span>(df_fourier<span class="sc">$</span>rel_power)</span>
<span id="cb8-52"><a href="#cb8-52"></a></span>
<span id="cb8-53"><a href="#cb8-53"></a> p_out <span class="ot"><-</span> df_fourier <span class="sc">%>%</span></span>
<span id="cb8-54"><a href="#cb8-54"></a> <span class="fu">ggplot</span>() <span class="sc">+</span></span>
<span id="cb8-55"><a href="#cb8-55"></a> <span class="fu">aes</span>(</span>
<span id="cb8-56"><a href="#cb8-56"></a> <span class="at">x =</span> Period,</span>
<span id="cb8-57"><a href="#cb8-57"></a> <span class="at">xend =</span> Period,</span>
<span id="cb8-58"><a href="#cb8-58"></a> <span class="at">y =</span> rel_power,</span>
<span id="cb8-59"><a href="#cb8-59"></a> <span class="at">yend =</span> <span class="dv">0</span></span>
<span id="cb8-60"><a href="#cb8-60"></a> ) <span class="sc">+</span></span>
<span id="cb8-61"><a href="#cb8-61"></a> <span class="fu">geom_rect</span>(</span>
<span id="cb8-62"><a href="#cb8-62"></a> <span class="fu">aes</span>(</span>
<span id="cb8-63"><a href="#cb8-63"></a> <span class="at">xmin =</span> <span class="fl">6.5</span>,</span>
<span id="cb8-64"><a href="#cb8-64"></a> <span class="at">xmax =</span> <span class="fl">7.5</span>,</span>
<span id="cb8-65"><a href="#cb8-65"></a> <span class="at">ymin =</span> <span class="dv">0</span>,</span>
<span id="cb8-66"><a href="#cb8-66"></a> <span class="at">ymax =</span> <span class="cn">Inf</span></span>
<span id="cb8-67"><a href="#cb8-67"></a> ),</span>
<span id="cb8-68"><a href="#cb8-68"></a> <span class="at">alpha =</span> <span class="fl">0.7</span>,</span>
<span id="cb8-69"><a href="#cb8-69"></a> <span class="at">fill =</span> <span class="st">"azure2"</span></span>
<span id="cb8-70"><a href="#cb8-70"></a> ) <span class="sc">+</span></span>
<span id="cb8-71"><a href="#cb8-71"></a> <span class="fu">geom_segment</span>(<span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.5</span>),</span>
<span id="cb8-72"><a href="#cb8-72"></a> <span class="at">color =</span> col_spec) <span class="sc">+</span></span>
<span id="cb8-73"><a href="#cb8-73"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span></span>
<span id="cb8-74"><a href="#cb8-74"></a> <span class="fu">seq</span>(<span class="dv">0</span>,</span>
<span id="cb8-75"><a href="#cb8-75"></a> max_period <span class="sc">-</span> <span class="fl">0.5</span>,</span>
<span id="cb8-76"><a href="#cb8-76"></a> <span class="dv">7</span>)) <span class="sc">+</span></span>
<span id="cb8-77"><a href="#cb8-77"></a> <span class="fu">scale_y_continuous</span>(<span class="co"># labels = scaleFUN,</span></span>
<span id="cb8-78"><a href="#cb8-78"></a> <span class="at">breaks =</span> scales<span class="sc">::</span><span class="fu">breaks_pretty</span>(<span class="dv">4</span>),</span>
<span id="cb8-79"><a href="#cb8-79"></a> <span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="fu">max</span>(<span class="dv">1</span>, max_var_component))) <span class="sc">+</span></span>
<span id="cb8-80"><a href="#cb8-80"></a> <span class="fu">theme</span>(</span>
<span id="cb8-81"><a href="#cb8-81"></a> <span class="co"># axis.title.y = element_blank(),</span></span>
<span id="cb8-82"><a href="#cb8-82"></a> <span class="co"># axis.ticks.y = element_blank(),</span></span>
<span id="cb8-83"><a href="#cb8-83"></a> <span class="co"># axis.line.y = element_blank(),</span></span>
<span id="cb8-84"><a href="#cb8-84"></a> <span class="co"># axis.text.y = element_blank(),</span></span>
<span id="cb8-85"><a href="#cb8-85"></a> <span class="at">panel.grid.major =</span> <span class="fu">element_blank</span>()</span>
<span id="cb8-86"><a href="#cb8-86"></a> ) <span class="sc">+</span></span>
<span id="cb8-87"><a href="#cb8-87"></a> <span class="fu">labs</span>(<span class="at">subtitle =</span> <span class="st">"Power spectral density"</span>,</span>
<span id="cb8-88"><a href="#cb8-88"></a> <span class="at">x =</span> <span class="st">"Period (in days)"</span>,</span>
<span id="cb8-89"><a href="#cb8-89"></a> <span class="at">y =</span> <span class="st">"% total power"</span>)</span>
<span id="cb8-90"><a href="#cb8-90"></a></span>
<span id="cb8-91"><a href="#cb8-91"></a> <span class="cf">if</span>(max_var_component <span class="sc"><</span> <span class="dv">1</span>)</span>
<span id="cb8-92"><a href="#cb8-92"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span></span>
<span id="cb8-93"><a href="#cb8-93"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">1</span>),</span>
<span id="cb8-94"><a href="#cb8-94"></a> <span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">1</span>))</span>
<span id="cb8-95"><a href="#cb8-95"></a></span>
<span id="cb8-96"><a href="#cb8-96"></a> <span class="cf">if</span> (remove_titles)</span>
<span id="cb8-97"><a href="#cb8-97"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">theme</span>(<span class="at">plot.subtitle =</span> <span class="fu">element_blank</span>())</span>
<span id="cb8-98"><a href="#cb8-98"></a> <span class="cf">if</span> (remove_xlab)</span>
<span id="cb8-99"><a href="#cb8-99"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">xlab</span>(<span class="cn">NULL</span>)</span>
<span id="cb8-100"><a href="#cb8-100"></a> p_out</span>
<span id="cb8-101"><a href="#cb8-101"></a></span>
<span id="cb8-102"><a href="#cb8-102"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-11_550ab826d7b0231be376443aa838f430">
<details>
<summary>Click to reveal <code>plot_acf()</code></summary>
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1"></a>plot_acf <span class="ot"><-</span> <span class="cf">function</span>(<span class="at">d =</span> <span class="cn">NULL</span>,</span>
<span id="cb9-2"><a href="#cb9-2"></a> <span class="at">title =</span> <span class="cn">NULL</span>,</span>
<span id="cb9-3"><a href="#cb9-3"></a> <span class="at">subtitle =</span> <span class="cn">NULL</span>,</span>
<span id="cb9-4"><a href="#cb9-4"></a> <span class="at">remove_titles =</span> <span class="cn">TRUE</span>,</span>
<span id="cb9-5"><a href="#cb9-5"></a> <span class="at">remove_xlab =</span> <span class="cn">TRUE</span>,</span>
<span id="cb9-6"><a href="#cb9-6"></a> <span class="at">scale_rel =</span> <span class="fl">0.9</span>,</span>
<span id="cb9-7"><a href="#cb9-7"></a> <span class="at">max_acf.lag =</span> <span class="dv">35</span>,</span>
<span id="cb9-8"><a href="#cb9-8"></a> <span class="at">max_period =</span> <span class="dv">15</span>,</span>
<span id="cb9-9"><a href="#cb9-9"></a> <span class="at">ymin =</span> <span class="dv">0</span><span class="fl">-0.1</span>,</span>
<span id="cb9-10"><a href="#cb9-10"></a> <span class="at">ymax =</span> <span class="dv">4</span><span class="fl">+0.1</span>,</span>
<span id="cb9-11"><a href="#cb9-11"></a> <span class="at">max_t =</span> <span class="dv">140</span>,</span>
<span id="cb9-12"><a href="#cb9-12"></a> <span class="at">max_weeks =</span> <span class="dv">25</span>,</span>
<span id="cb9-13"><a href="#cb9-13"></a> <span class="at">col_weekly =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb9-14"><a href="#cb9-14"></a> <span class="at">col_dowe.line =</span> <span class="st">"mediumorchid4"</span>,</span>
<span id="cb9-15"><a href="#cb9-15"></a> <span class="at">col_dowe.point =</span> <span class="st">"deeppink1"</span>,</span>
<span id="cb9-16"><a href="#cb9-16"></a> <span class="at">col_ts =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb9-17"><a href="#cb9-17"></a> <span class="at">col_ts.point =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb9-18"><a href="#cb9-18"></a> <span class="at">col_hist =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb9-19"><a href="#cb9-19"></a> <span class="at">col_acf =</span> <span class="st">"darkolivegreen3"</span>,</span>
<span id="cb9-20"><a href="#cb9-20"></a> <span class="at">col_pacf =</span> <span class="st">"darkorange3"</span>,</span>
<span id="cb9-21"><a href="#cb9-21"></a> <span class="at">col_spec =</span> <span class="st">"darkorchid4"</span>,</span>
<span id="cb9-22"><a href="#cb9-22"></a> <span class="at">col_hlines =</span> <span class="st">"dimgray"</span>) {</span>
<span id="cb9-23"><a href="#cb9-23"></a></span>
<span id="cb9-24"><a href="#cb9-24"></a> <span class="co"># Transforming the input to an appropriate dataframe</span></span>
<span id="cb9-25"><a href="#cb9-25"></a> d <span class="ot"><-</span> d <span class="sc">%>%</span> <span class="fu">data_shaper</span>()</span>
<span id="cb9-26"><a href="#cb9-26"></a></span>
<span id="cb9-27"><a href="#cb9-27"></a> <span class="co"># Making sure the optimal theme is in place</span></span>
<span id="cb9-28"><a href="#cb9-28"></a> <span class="fu">theme_set</span>(ggthemes<span class="sc">::</span><span class="fu">theme_few</span>())</span>
<span id="cb9-29"><a href="#cb9-29"></a></span>
<span id="cb9-30"><a href="#cb9-30"></a> <span class="co"># Imputing the missing values using seasonal Kalman smoothing</span></span>
<span id="cb9-31"><a href="#cb9-31"></a> y_imp <span class="ot"><-</span> d<span class="sc">$</span>y <span class="sc">%>%</span></span>
<span id="cb9-32"><a href="#cb9-32"></a> <span class="fu">ts</span>(<span class="at">frequency =</span> <span class="dv">7</span>) <span class="sc">%>%</span></span>
<span id="cb9-33"><a href="#cb9-33"></a> imputeTS<span class="sc">::</span><span class="fu">na_kalman</span>()</span>
<span id="cb9-34"><a href="#cb9-34"></a></span>
<span id="cb9-35"><a href="#cb9-35"></a> breaks_acf <span class="ot"><-</span> <span class="fu">seq</span>(<span class="dv">0</span>,</span>
<span id="cb9-36"><a href="#cb9-36"></a> max_acf.lag,</span>
<span id="cb9-37"><a href="#cb9-37"></a> <span class="at">by =</span> <span class="dv">14</span> <span class="sc">*</span> <span class="fu">floor</span>(max_acf.lag <span class="sc">/</span> <span class="dv">7</span> <span class="sc">/</span> <span class="dv">3</span>))</span>
<span id="cb9-38"><a href="#cb9-38"></a></span>
<span id="cb9-39"><a href="#cb9-39"></a> df_acf <span class="ot"><-</span> <span class="fu">data.frame</span>(</span>
<span id="cb9-40"><a href="#cb9-40"></a> <span class="at">lag =</span> <span class="fu">c</span>(<span class="dv">0</span><span class="sc">:</span>max_acf.lag),</span>
<span id="cb9-41"><a href="#cb9-41"></a> <span class="at">acf =</span> stats<span class="sc">::</span><span class="fu">acf</span>(y_imp,</span>
<span id="cb9-42"><a href="#cb9-42"></a> <span class="at">lag.max =</span> max_acf.lag,</span>
<span id="cb9-43"><a href="#cb9-43"></a> <span class="at">plot =</span> <span class="cn">FALSE</span>)<span class="sc">$</span>acf <span class="sc">%>%</span></span>
<span id="cb9-44"><a href="#cb9-44"></a> <span class="fu">as.numeric</span>()</span>
<span id="cb9-45"><a href="#cb9-45"></a> )</span>
<span id="cb9-46"><a href="#cb9-46"></a></span>
<span id="cb9-47"><a href="#cb9-47"></a> p_out <span class="ot"><-</span> df_acf <span class="sc">%>%</span></span>
<span id="cb9-48"><a href="#cb9-48"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> lag,</span>
<span id="cb9-49"><a href="#cb9-49"></a> <span class="at">y =</span> acf)) <span class="sc">+</span></span>
<span id="cb9-50"><a href="#cb9-50"></a> <span class="fu">geom_segment</span>(</span>
<span id="cb9-51"><a href="#cb9-51"></a> <span class="fu">aes</span>(</span>
<span id="cb9-52"><a href="#cb9-52"></a> <span class="at">x =</span> lag,</span>
<span id="cb9-53"><a href="#cb9-53"></a> <span class="at">xend =</span> lag,</span>
<span id="cb9-54"><a href="#cb9-54"></a> <span class="at">y =</span> <span class="dv">0</span>,</span>
<span id="cb9-55"><a href="#cb9-55"></a> <span class="at">yend =</span> acf</span>
<span id="cb9-56"><a href="#cb9-56"></a> ),</span>
<span id="cb9-57"><a href="#cb9-57"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="dv">35</span> <span class="sc">/</span> max_acf.lag <span class="sc">/</span> <span class="dv">2</span>),</span>
<span id="cb9-58"><a href="#cb9-58"></a> <span class="at">color =</span> col_acf,</span>
<span id="cb9-59"><a href="#cb9-59"></a> <span class="at">lineend =</span> <span class="st">"butt"</span></span>
<span id="cb9-60"><a href="#cb9-60"></a> ) <span class="sc">+</span></span>
<span id="cb9-61"><a href="#cb9-61"></a> <span class="fu">geom_hline</span>(</span>
<span id="cb9-62"><a href="#cb9-62"></a> <span class="at">yintercept =</span> <span class="dv">0</span>,</span>
<span id="cb9-63"><a href="#cb9-63"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.3</span>),</span>
<span id="cb9-64"><a href="#cb9-64"></a> <span class="at">linetype =</span> <span class="st">"solid"</span>,</span>
<span id="cb9-65"><a href="#cb9-65"></a> <span class="at">color =</span> col_hlines</span>
<span id="cb9-66"><a href="#cb9-66"></a> ) <span class="sc">+</span></span>
<span id="cb9-67"><a href="#cb9-67"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> breaks_acf) <span class="sc">+</span></span>
<span id="cb9-68"><a href="#cb9-68"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">c</span>(<span class="sc">-</span>.<span class="dv">5</span>, <span class="dv">0</span>, <span class="fl">0.5</span>, <span class="dv">1</span>),</span>
<span id="cb9-69"><a href="#cb9-69"></a> <span class="at">limits =</span> <span class="fu">c</span>(<span class="sc">-</span>.<span class="dv">25</span>, <span class="fl">1.1</span>)) <span class="sc">+</span></span>
<span id="cb9-70"><a href="#cb9-70"></a> <span class="fu">labs</span>(<span class="at">subtitle =</span> <span class="st">"ACF"</span>,</span>
<span id="cb9-71"><a href="#cb9-71"></a> <span class="at">x =</span> <span class="st">"Lag"</span>,</span>
<span id="cb9-72"><a href="#cb9-72"></a> <span class="at">y =</span> <span class="st">""</span>) <span class="sc">+</span></span>
<span id="cb9-73"><a href="#cb9-73"></a> <span class="fu">theme</span>(</span>
<span id="cb9-74"><a href="#cb9-74"></a> <span class="at">panel.grid.major =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb9-75"><a href="#cb9-75"></a> <span class="at">axis.title.y =</span> <span class="fu">element_blank</span>()</span>
<span id="cb9-76"><a href="#cb9-76"></a> )</span>
<span id="cb9-77"><a href="#cb9-77"></a></span>
<span id="cb9-78"><a href="#cb9-78"></a> <span class="cf">if</span> (remove_titles)</span>
<span id="cb9-79"><a href="#cb9-79"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">theme</span>(<span class="at">plot.subtitle =</span> <span class="fu">element_blank</span>())</span>
<span id="cb9-80"><a href="#cb9-80"></a> <span class="cf">if</span> (remove_xlab)</span>
<span id="cb9-81"><a href="#cb9-81"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">xlab</span>(<span class="cn">NULL</span>)</span>
<span id="cb9-82"><a href="#cb9-82"></a> p_out</span>
<span id="cb9-83"><a href="#cb9-83"></a></span>
<span id="cb9-84"><a href="#cb9-84"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-12_53f4dabe6a8385bb6da68ea7be409853">
<details>
<summary>Click to reveal <code>plot_pacf()</code></summary>
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1"></a>plot_pacf <span class="ot"><-</span> <span class="cf">function</span>(<span class="at">d =</span> <span class="cn">NULL</span>,</span>
<span id="cb10-2"><a href="#cb10-2"></a> <span class="at">title =</span> <span class="cn">NULL</span>,</span>
<span id="cb10-3"><a href="#cb10-3"></a> <span class="at">subtitle =</span> <span class="cn">NULL</span>,</span>
<span id="cb10-4"><a href="#cb10-4"></a> <span class="at">remove_titles =</span> <span class="cn">TRUE</span>,</span>
<span id="cb10-5"><a href="#cb10-5"></a> <span class="at">remove_xlab =</span> <span class="cn">TRUE</span>,</span>
<span id="cb10-6"><a href="#cb10-6"></a> <span class="at">scale_rel =</span> <span class="fl">0.9</span>,</span>
<span id="cb10-7"><a href="#cb10-7"></a> <span class="at">max_pacf.lag =</span> <span class="dv">35</span>,</span>
<span id="cb10-8"><a href="#cb10-8"></a> <span class="at">max_period =</span> <span class="dv">15</span>,</span>
<span id="cb10-9"><a href="#cb10-9"></a> <span class="at">ymin =</span> <span class="dv">0</span><span class="fl">-0.1</span>,</span>
<span id="cb10-10"><a href="#cb10-10"></a> <span class="at">ymax =</span> <span class="dv">4</span><span class="fl">+0.1</span>,</span>
<span id="cb10-11"><a href="#cb10-11"></a> <span class="at">max_t =</span> <span class="dv">140</span>,</span>
<span id="cb10-12"><a href="#cb10-12"></a> <span class="at">max_weeks =</span> <span class="dv">25</span>,</span>
<span id="cb10-13"><a href="#cb10-13"></a> <span class="at">col_weekly =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb10-14"><a href="#cb10-14"></a> <span class="at">col_dowe.line =</span> <span class="st">"mediumorchid4"</span>,</span>
<span id="cb10-15"><a href="#cb10-15"></a> <span class="at">col_dowe.point =</span> <span class="st">"deeppink1"</span>,</span>
<span id="cb10-16"><a href="#cb10-16"></a> <span class="at">col_ts =</span> <span class="st">"lightsteelblue4"</span>,</span>
<span id="cb10-17"><a href="#cb10-17"></a> <span class="at">col_ts.point =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb10-18"><a href="#cb10-18"></a> <span class="at">col_hist =</span> <span class="st">"cornflowerblue"</span>,</span>
<span id="cb10-19"><a href="#cb10-19"></a> <span class="at">col_acf =</span> <span class="st">"darkolivegreen3"</span>,</span>
<span id="cb10-20"><a href="#cb10-20"></a> <span class="at">col_pacf =</span> <span class="st">"darkorange3"</span>,</span>
<span id="cb10-21"><a href="#cb10-21"></a> <span class="at">col_spec =</span> <span class="st">"darkorchid4"</span>,</span>
<span id="cb10-22"><a href="#cb10-22"></a> <span class="at">col_hlines =</span> <span class="st">"dimgray"</span>) {</span>
<span id="cb10-23"><a href="#cb10-23"></a></span>
<span id="cb10-24"><a href="#cb10-24"></a> <span class="co"># Transforming the input to an appropriate dataframe</span></span>
<span id="cb10-25"><a href="#cb10-25"></a> d <span class="ot"><-</span> d <span class="sc">%>%</span> <span class="fu">data_shaper</span>()</span>
<span id="cb10-26"><a href="#cb10-26"></a></span>
<span id="cb10-27"><a href="#cb10-27"></a> <span class="co"># Making sure the optimal theme is in place</span></span>
<span id="cb10-28"><a href="#cb10-28"></a> <span class="fu">theme_set</span>(ggthemes<span class="sc">::</span><span class="fu">theme_few</span>())</span>
<span id="cb10-29"><a href="#cb10-29"></a></span>
<span id="cb10-30"><a href="#cb10-30"></a> <span class="co"># Imputing the missing values using seasonal Kalman smoothing</span></span>
<span id="cb10-31"><a href="#cb10-31"></a> y_imp <span class="ot"><-</span> d<span class="sc">$</span>y <span class="sc">%>%</span></span>
<span id="cb10-32"><a href="#cb10-32"></a> <span class="fu">ts</span>(<span class="at">frequency =</span> <span class="dv">7</span>) <span class="sc">%>%</span></span>
<span id="cb10-33"><a href="#cb10-33"></a> imputeTS<span class="sc">::</span><span class="fu">na_kalman</span>()</span>
<span id="cb10-34"><a href="#cb10-34"></a></span>
<span id="cb10-35"><a href="#cb10-35"></a> breaks_acf <span class="ot"><-</span> <span class="fu">seq</span>(<span class="dv">0</span>,</span>
<span id="cb10-36"><a href="#cb10-36"></a> max_pacf.lag,</span>
<span id="cb10-37"><a href="#cb10-37"></a> <span class="at">by =</span> <span class="dv">14</span> <span class="sc">*</span> <span class="fu">floor</span>(max_pacf.lag <span class="sc">/</span> <span class="dv">7</span> <span class="sc">/</span> <span class="dv">3</span>))</span>
<span id="cb10-38"><a href="#cb10-38"></a></span>
<span id="cb10-39"><a href="#cb10-39"></a> df_pacf <span class="ot"><-</span> <span class="fu">data.frame</span>(</span>
<span id="cb10-40"><a href="#cb10-40"></a> <span class="at">lag =</span> <span class="fu">c</span>(<span class="dv">0</span><span class="sc">:</span>max_pacf.lag),</span>
<span id="cb10-41"><a href="#cb10-41"></a> <span class="at">pacf =</span> stats<span class="sc">::</span><span class="fu">pacf</span>(y_imp,</span>
<span id="cb10-42"><a href="#cb10-42"></a> <span class="fu">max</span>(<span class="dv">1</span>, max_pacf.lag),</span>
<span id="cb10-43"><a href="#cb10-43"></a> <span class="at">na.action =</span> na.exclude,</span>
<span id="cb10-44"><a href="#cb10-44"></a> <span class="at">plot =</span> <span class="cn">FALSE</span>)<span class="sc">$</span>acf <span class="sc">%>%</span></span>
<span id="cb10-45"><a href="#cb10-45"></a> <span class="fu">as.numeric</span>() <span class="sc">%>%</span></span>
<span id="cb10-46"><a href="#cb10-46"></a> <span class="fu">c</span>(<span class="dv">0</span>, .)</span>
<span id="cb10-47"><a href="#cb10-47"></a> )</span>
<span id="cb10-48"><a href="#cb10-48"></a></span>
<span id="cb10-49"><a href="#cb10-49"></a> p_out <span class="ot"><-</span> df_pacf <span class="sc">%>%</span></span>
<span id="cb10-50"><a href="#cb10-50"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> lag,</span>
<span id="cb10-51"><a href="#cb10-51"></a> <span class="at">y =</span> pacf)) <span class="sc">+</span></span>
<span id="cb10-52"><a href="#cb10-52"></a> <span class="fu">geom_segment</span>(</span>
<span id="cb10-53"><a href="#cb10-53"></a> <span class="fu">aes</span>(</span>
<span id="cb10-54"><a href="#cb10-54"></a> <span class="at">x =</span> lag,</span>
<span id="cb10-55"><a href="#cb10-55"></a> <span class="at">xend =</span> lag,</span>
<span id="cb10-56"><a href="#cb10-56"></a> <span class="at">y =</span> <span class="dv">0</span>,</span>
<span id="cb10-57"><a href="#cb10-57"></a> <span class="at">yend =</span> pacf</span>
<span id="cb10-58"><a href="#cb10-58"></a> ),</span>
<span id="cb10-59"><a href="#cb10-59"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="dv">35</span> <span class="sc">/</span> max_pacf.lag <span class="sc">/</span> <span class="dv">2</span>),</span>
<span id="cb10-60"><a href="#cb10-60"></a> <span class="at">color =</span> col_pacf,</span>
<span id="cb10-61"><a href="#cb10-61"></a> <span class="at">lineend =</span> <span class="st">"butt"</span></span>
<span id="cb10-62"><a href="#cb10-62"></a> ) <span class="sc">+</span></span>
<span id="cb10-63"><a href="#cb10-63"></a> <span class="fu">geom_hline</span>(</span>
<span id="cb10-64"><a href="#cb10-64"></a> <span class="at">yintercept =</span> <span class="dv">0</span>,</span>
<span id="cb10-65"><a href="#cb10-65"></a> <span class="at">linewidth =</span> <span class="fu">rel</span>(scale_rel <span class="sc">*</span> <span class="fl">0.3</span>),</span>
<span id="cb10-66"><a href="#cb10-66"></a> <span class="at">linetype =</span> <span class="st">"solid"</span>,</span>
<span id="cb10-67"><a href="#cb10-67"></a> <span class="at">color =</span> col_hlines</span>
<span id="cb10-68"><a href="#cb10-68"></a> ) <span class="sc">+</span></span>
<span id="cb10-69"><a href="#cb10-69"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> breaks_acf) <span class="sc">+</span></span>
<span id="cb10-70"><a href="#cb10-70"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">c</span>(<span class="sc">-</span>.<span class="dv">5</span>, <span class="dv">0</span>, <span class="fl">0.5</span>, <span class="dv">1</span>),</span>
<span id="cb10-71"><a href="#cb10-71"></a> <span class="at">limits =</span> <span class="fu">c</span>(<span class="sc">-</span>.<span class="dv">25</span>, <span class="fl">1.1</span>)) <span class="sc">+</span></span>
<span id="cb10-72"><a href="#cb10-72"></a> <span class="fu">labs</span>(<span class="at">subtitle =</span> <span class="st">"PACF"</span>,</span>
<span id="cb10-73"><a href="#cb10-73"></a> <span class="at">x =</span> <span class="st">"Lag"</span>,</span>
<span id="cb10-74"><a href="#cb10-74"></a> <span class="at">y =</span> <span class="st">""</span>) <span class="sc">+</span></span>
<span id="cb10-75"><a href="#cb10-75"></a> <span class="fu">theme</span>(</span>
<span id="cb10-76"><a href="#cb10-76"></a> <span class="at">panel.grid.major =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb10-77"><a href="#cb10-77"></a> <span class="at">axis.title.y =</span> <span class="fu">element_blank</span>()</span>
<span id="cb10-78"><a href="#cb10-78"></a> )</span>
<span id="cb10-79"><a href="#cb10-79"></a></span>
<span id="cb10-80"><a href="#cb10-80"></a> <span class="cf">if</span> (remove_titles)</span>
<span id="cb10-81"><a href="#cb10-81"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">theme</span>(<span class="at">plot.subtitle =</span> <span class="fu">element_blank</span>())</span>
<span id="cb10-82"><a href="#cb10-82"></a> <span class="cf">if</span> (remove_xlab)</span>
<span id="cb10-83"><a href="#cb10-83"></a> p_out <span class="ot"><-</span> p_out <span class="sc">+</span> <span class="fu">xlab</span>(<span class="cn">NULL</span>)</span>
<span id="cb10-84"><a href="#cb10-84"></a> p_out</span>
<span id="cb10-85"><a href="#cb10-85"></a></span>
<span id="cb10-86"><a href="#cb10-86"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>To make sure that the data provided to these functions are in the correct format (with the above-mentioned columns), the function <code>data_shaper()</code> is called within these plotting functions to do the job. This function also amends a new column (<code>week_num</code>) to the dataframe that counts the week number since the start of the time series, which is needed for plotting the DOWEs in <code>plot_dowe()</code>.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-13_80349d74156f4f8c8f4533b23d303f8b">
<details>
<summary>Click to reveal <code>data_shaper()</code></summary>
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1"></a>data_shaper <span class="ot"><-</span> <span class="cf">function</span>(d,</span>
<span id="cb11-2"><a href="#cb11-2"></a> <span class="at">minimal_output =</span> <span class="cn">FALSE</span>) {</span>
<span id="cb11-3"><a href="#cb11-3"></a></span>
<span id="cb11-4"><a href="#cb11-4"></a> weekdays <span class="ot"><-</span> <span class="fu">c</span>(<span class="st">"Mon"</span>,</span>
<span id="cb11-5"><a href="#cb11-5"></a> <span class="st">"Tue"</span>,</span>
<span id="cb11-6"><a href="#cb11-6"></a> <span class="st">"Wed"</span>,</span>
<span id="cb11-7"><a href="#cb11-7"></a> <span class="st">"Thu"</span>,</span>
<span id="cb11-8"><a href="#cb11-8"></a> <span class="st">"Fri"</span>,</span>
<span id="cb11-9"><a href="#cb11-9"></a> <span class="st">"Sat"</span>,</span>
<span id="cb11-10"><a href="#cb11-10"></a> <span class="st">"Sun"</span>)</span>
<span id="cb11-11"><a href="#cb11-11"></a></span>
<span id="cb11-12"><a href="#cb11-12"></a> <span class="cf">if</span> (<span class="sc">!</span><span class="fu">is.data.frame</span>(d)){</span>
<span id="cb11-13"><a href="#cb11-13"></a> d <span class="ot"><-</span> <span class="fu">data.frame</span>(</span>
<span id="cb11-14"><a href="#cb11-14"></a> <span class="at">t =</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(d),</span>
<span id="cb11-15"><a href="#cb11-15"></a> <span class="at">y =</span> d,</span>
<span id="cb11-16"><a href="#cb11-16"></a> <span class="at">weekday =</span> <span class="fu">rep</span>(weekdays, <span class="at">length.out =</span> <span class="fu">length</span>(d)),</span>
<span id="cb11-17"><a href="#cb11-17"></a> <span class="at">week_num =</span> <span class="fu">rep</span>(<span class="dv">1</span><span class="sc">:</span><span class="fu">ceiling</span>(<span class="fu">length</span>(d) <span class="sc">/</span> <span class="dv">7</span>), <span class="at">each =</span> <span class="dv">7</span>)[<span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(d)]</span>
<span id="cb11-18"><a href="#cb11-18"></a> )</span>
<span id="cb11-19"><a href="#cb11-19"></a> <span class="co"># if(minimal_output == TRUE) return(d)</span></span>
<span id="cb11-20"><a href="#cb11-20"></a> }</span>
<span id="cb11-21"><a href="#cb11-21"></a></span>
<span id="cb11-22"><a href="#cb11-22"></a> <span class="cf">if</span> (<span class="st">"date"</span> <span class="sc">%in%</span> <span class="fu">colnames</span>(d))</span>
<span id="cb11-23"><a href="#cb11-23"></a> d <span class="ot"><-</span> d <span class="sc">%>%</span></span>
<span id="cb11-24"><a href="#cb11-24"></a> <span class="fu">mutate</span>(</span>
<span id="cb11-25"><a href="#cb11-25"></a> <span class="at">weekday =</span> lubridate<span class="sc">::</span><span class="fu">wday</span>(date,</span>
<span id="cb11-26"><a href="#cb11-26"></a> <span class="at">week_start =</span> <span class="dv">1</span>,</span>
<span id="cb11-27"><a href="#cb11-27"></a> <span class="at">label =</span> <span class="cn">TRUE</span>),</span>
<span id="cb11-28"><a href="#cb11-28"></a> <span class="at">weekday_num =</span> lubridate<span class="sc">::</span><span class="fu">wday</span>(date,</span>
<span id="cb11-29"><a href="#cb11-29"></a> <span class="at">week_start =</span> <span class="dv">1</span>,</span>
<span id="cb11-30"><a href="#cb11-30"></a> <span class="at">label =</span> <span class="cn">FALSE</span>)</span>
<span id="cb11-31"><a href="#cb11-31"></a> )</span>
<span id="cb11-32"><a href="#cb11-32"></a></span>
<span id="cb11-33"><a href="#cb11-33"></a> <span class="cf">if</span> (<span class="sc">!</span>(<span class="st">"weekday_num"</span> <span class="sc">%in%</span> <span class="fu">colnames</span>(d)))</span>
<span id="cb11-34"><a href="#cb11-34"></a> d<span class="sc">$</span>weekday_num <span class="ot"><-</span> <span class="fu">match</span>(d<span class="sc">$</span>weekday, weekdays)</span>
<span id="cb11-35"><a href="#cb11-35"></a></span>
<span id="cb11-36"><a href="#cb11-36"></a> <span class="cf">if</span> (<span class="sc">!</span>(<span class="st">"week_num"</span> <span class="sc">%in%</span> <span class="fu">colnames</span>(d))) {</span>
<span id="cb11-37"><a href="#cb11-37"></a> <span class="co"># Initialize week number and an empty vector to store week numbers</span></span>
<span id="cb11-38"><a href="#cb11-38"></a> week_number <span class="ot"><-</span> <span class="dv">1</span></span>
<span id="cb11-39"><a href="#cb11-39"></a> week_numbers <span class="ot"><-</span> <span class="fu">numeric</span>(<span class="fu">length</span>(d<span class="sc">$</span>weekday_num))</span>
<span id="cb11-40"><a href="#cb11-40"></a> <span class="co"># Check if the sequence starts with a day other than Monday and adjust week_number accordingly</span></span>
<span id="cb11-41"><a href="#cb11-41"></a> <span class="cf">if</span> (d<span class="sc">$</span>weekday_num[<span class="dv">1</span>] <span class="sc">!=</span> <span class="dv">1</span>) {</span>
<span id="cb11-42"><a href="#cb11-42"></a> week_number <span class="ot"><-</span> <span class="dv">1</span></span>
<span id="cb11-43"><a href="#cb11-43"></a> } <span class="cf">else</span> {</span>
<span id="cb11-44"><a href="#cb11-44"></a> week_number <span class="ot"><-</span></span>
<span id="cb11-45"><a href="#cb11-45"></a> <span class="dv">2</span> <span class="co"># Start from week 2 if the first day is Monday, to handle edge cases</span></span>
<span id="cb11-46"><a href="#cb11-46"></a> }</span>
<span id="cb11-47"><a href="#cb11-47"></a> <span class="co"># Iterate through the days, increasing week number after encountering a Sunday</span></span>
<span id="cb11-48"><a href="#cb11-48"></a> <span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(d<span class="sc">$</span>weekday_num)) {</span>
<span id="cb11-49"><a href="#cb11-49"></a> week_numbers[i] <span class="ot"><-</span> week_number</span>
<span id="cb11-50"><a href="#cb11-50"></a> <span class="cf">if</span> (d<span class="sc">$</span>weekday_num[i] <span class="sc">==</span> <span class="dv">7</span> <span class="sc">&&</span></span>
<span id="cb11-51"><a href="#cb11-51"></a> i <span class="sc">!=</span> <span class="fu">length</span>(d<span class="sc">$</span>weekday_num)) {</span>
<span id="cb11-52"><a href="#cb11-52"></a> <span class="co"># Check for Sunday and not the last element</span></span>
<span id="cb11-53"><a href="#cb11-53"></a> week_number <span class="ot"><-</span> week_number <span class="sc">+</span> <span class="dv">1</span></span>
<span id="cb11-54"><a href="#cb11-54"></a> }</span>
<span id="cb11-55"><a href="#cb11-55"></a> }</span>
<span id="cb11-56"><a href="#cb11-56"></a> d<span class="sc">$</span>week_num <span class="ot"><-</span> week_numbers</span>
<span id="cb11-57"><a href="#cb11-57"></a> }</span>
<span id="cb11-58"><a href="#cb11-58"></a></span>
<span id="cb11-59"><a href="#cb11-59"></a> <span class="co"># Substituting NA's for implicit missing values</span></span>
<span id="cb11-60"><a href="#cb11-60"></a> d_out <span class="ot"><-</span> d <span class="sc">%>%</span></span>
<span id="cb11-61"><a href="#cb11-61"></a> <span class="fu">right_join</span>(<span class="fu">data.frame</span>(<span class="at">t =</span> <span class="fu">min</span>(d<span class="sc">$</span>t)<span class="sc">:</span><span class="fu">max</span>(d<span class="sc">$</span>t)),</span>
<span id="cb11-62"><a href="#cb11-62"></a> <span class="at">by =</span> <span class="st">"t"</span>) <span class="sc">%>%</span></span>
<span id="cb11-63"><a href="#cb11-63"></a> <span class="fu">mutate</span>(<span class="at">weekday =</span> weekday <span class="sc">%>%</span> <span class="fu">factor</span>(weekdays)) <span class="sc">%>%</span></span>
<span id="cb11-64"><a href="#cb11-64"></a> <span class="fu">arrange</span>(t)</span>
<span id="cb11-65"><a href="#cb11-65"></a></span>
<span id="cb11-66"><a href="#cb11-66"></a> <span class="fu">return</span>(d_out)</span>
<span id="cb11-67"><a href="#cb11-67"></a></span>
<span id="cb11-68"><a href="#cb11-68"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>Then, the function <code>plot_row_assembly()</code> uses the above functions to put them together in a row and returns either the plot, or saves it in a file in the <code>figures</code> folder with dimensions and sizes that render in nice proportions when the plot is saved with a <code>.svg</code> (good for putting in Word or online) or <code>.pdf</code> (good for <span class="math inline">\(\LaTeX\)</span> manuscripts) file formats.</p>
<p>This function takes a list of time series (either as vectors or dataframes) in its <code>list_data</code> argument, and adds vertical labels to each row of the plots with the values passed to <code>list_labels</code>.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-14_884303f5a0e9dbdac7d4641afc4988cb">
<details>
<summary>Click to reveal <code>plot_row_assembly()</code></summary>
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1"></a>plot_row_assembly <span class="ot"><-</span> <span class="cf">function</span>(list_data,</span>
<span id="cb12-2"><a href="#cb12-2"></a> <span class="at">list_labels =</span> <span class="cn">NULL</span>,</span>
<span id="cb12-3"><a href="#cb12-3"></a> <span class="at">save_name =</span> <span class="st">"plot-rows.pdf"</span>,</span>
<span id="cb12-4"><a href="#cb12-4"></a> <span class="at">save_dir =</span> <span class="st">"figures"</span>,</span>
<span id="cb12-5"><a href="#cb12-5"></a> ...) {</span>
<span id="cb12-6"><a href="#cb12-6"></a> n_rows <span class="ot"><-</span> <span class="fu">length</span>(list_data)</span>
<span id="cb12-7"><a href="#cb12-7"></a></span>
<span id="cb12-8"><a href="#cb12-8"></a> l_hist <span class="ot"><-</span> <span class="fu">list</span>()</span>
<span id="cb12-9"><a href="#cb12-9"></a> l_seq <span class="ot"><-</span> <span class="fu">list</span>()</span>
<span id="cb12-10"><a href="#cb12-10"></a> l_dowe <span class="ot"><-</span> <span class="fu">list</span>()</span>
<span id="cb12-11"><a href="#cb12-11"></a> l_psd <span class="ot"><-</span> <span class="fu">list</span>()</span>
<span id="cb12-12"><a href="#cb12-12"></a> l_acf <span class="ot"><-</span> <span class="fu">list</span>()</span>
<span id="cb12-13"><a href="#cb12-13"></a> l_pacf <span class="ot"><-</span> <span class="fu">list</span>()</span>
<span id="cb12-14"><a href="#cb12-14"></a></span>
<span id="cb12-15"><a href="#cb12-15"></a> title_r <span class="ot"><-</span> <span class="cn">NULL</span></span>
<span id="cb12-16"><a href="#cb12-16"></a></span>
<span id="cb12-17"><a href="#cb12-17"></a> <span class="cf">for</span> (r <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span>n_rows) {</span>
<span id="cb12-18"><a href="#cb12-18"></a> d <span class="ot"><-</span> list_data[[r]]</span>
<span id="cb12-19"><a href="#cb12-19"></a></span>
<span id="cb12-20"><a href="#cb12-20"></a> <span class="cf">if</span> (<span class="fu">length</span>(list_labels) <span class="sc">==</span> n_rows)</span>
<span id="cb12-21"><a href="#cb12-21"></a> title_r <span class="ot"><-</span> list_labels[[r]]</span>
<span id="cb12-22"><a href="#cb12-22"></a></span>
<span id="cb12-23"><a href="#cb12-23"></a> rm_titles <span class="ot"><-</span> <span class="cn">TRUE</span></span>
<span id="cb12-24"><a href="#cb12-24"></a> rm_xlab <span class="ot"><-</span> <span class="cn">TRUE</span></span>
<span id="cb12-25"><a href="#cb12-25"></a></span>
<span id="cb12-26"><a href="#cb12-26"></a> <span class="cf">if</span> (r <span class="sc">==</span> <span class="dv">1</span>) {</span>
<span id="cb12-27"><a href="#cb12-27"></a> rm_titles <span class="ot"><-</span> <span class="cn">FALSE</span></span>
<span id="cb12-28"><a href="#cb12-28"></a> rm_xlab <span class="ot"><-</span> <span class="cn">TRUE</span></span>
<span id="cb12-29"><a href="#cb12-29"></a> }</span>
<span id="cb12-30"><a href="#cb12-30"></a></span>
<span id="cb12-31"><a href="#cb12-31"></a> <span class="cf">if</span> (r <span class="sc">==</span> n_rows) {</span>
<span id="cb12-32"><a href="#cb12-32"></a> rm_titles <span class="ot"><-</span> <span class="cn">TRUE</span></span>
<span id="cb12-33"><a href="#cb12-33"></a> rm_xlab <span class="ot"><-</span> <span class="cn">FALSE</span></span>
<span id="cb12-34"><a href="#cb12-34"></a> }</span>
<span id="cb12-35"><a href="#cb12-35"></a></span>
<span id="cb12-36"><a href="#cb12-36"></a> <span class="cf">if</span> (n_rows <span class="sc">==</span> <span class="dv">1</span>) {</span>
<span id="cb12-37"><a href="#cb12-37"></a> rm_titles <span class="ot"><-</span> <span class="cn">FALSE</span></span>
<span id="cb12-38"><a href="#cb12-38"></a> rm_xlab <span class="ot"><-</span> <span class="cn">FALSE</span></span>
<span id="cb12-39"><a href="#cb12-39"></a> }</span>
<span id="cb12-40"><a href="#cb12-40"></a></span>
<span id="cb12-41"><a href="#cb12-41"></a> l_hist[[r]] <span class="ot"><-</span> <span class="co">#label_plot(r) +</span></span>
<span id="cb12-42"><a href="#cb12-42"></a> <span class="fu">plot_hist</span>(</span>
<span id="cb12-43"><a href="#cb12-43"></a> d,</span>
<span id="cb12-44"><a href="#cb12-44"></a> <span class="at">title =</span> title_r,</span>
<span id="cb12-45"><a href="#cb12-45"></a> <span class="at">remove_titles =</span> rm_titles,</span>
<span id="cb12-46"><a href="#cb12-46"></a> <span class="at">remove_xlab =</span> rm_xlab,</span>
<span id="cb12-47"><a href="#cb12-47"></a> ...</span>
<span id="cb12-48"><a href="#cb12-48"></a> )</span>
<span id="cb12-49"><a href="#cb12-49"></a> l_seq[[r]] <span class="ot"><-</span> <span class="fu">plot_seq</span>(d,</span>
<span id="cb12-50"><a href="#cb12-50"></a> <span class="at">remove_titles =</span> rm_titles,</span>
<span id="cb12-51"><a href="#cb12-51"></a> <span class="at">remove_xlab =</span> rm_xlab,</span>
<span id="cb12-52"><a href="#cb12-52"></a> ...)</span>
<span id="cb12-53"><a href="#cb12-53"></a> l_dowe[[r]] <span class="ot"><-</span> <span class="fu">plot_dowe</span>(d,</span>
<span id="cb12-54"><a href="#cb12-54"></a> <span class="at">remove_titles =</span> rm_titles,</span>
<span id="cb12-55"><a href="#cb12-55"></a> <span class="at">remove_xlab =</span> rm_xlab,</span>
<span id="cb12-56"><a href="#cb12-56"></a> ...)</span>
<span id="cb12-57"><a href="#cb12-57"></a> l_psd[[r]] <span class="ot"><-</span> <span class="fu">plot_psd</span>(d,</span>
<span id="cb12-58"><a href="#cb12-58"></a> <span class="at">remove_titles =</span> rm_titles,</span>
<span id="cb12-59"><a href="#cb12-59"></a> <span class="at">remove_xlab =</span> rm_xlab,</span>
<span id="cb12-60"><a href="#cb12-60"></a> ...)</span>
<span id="cb12-61"><a href="#cb12-61"></a> l_acf[[r]] <span class="ot"><-</span> <span class="fu">plot_acf</span>(d,</span>
<span id="cb12-62"><a href="#cb12-62"></a> <span class="at">remove_titles =</span> rm_titles,</span>
<span id="cb12-63"><a href="#cb12-63"></a> <span class="at">remove_xlab =</span> rm_xlab,</span>
<span id="cb12-64"><a href="#cb12-64"></a> ...)</span>
<span id="cb12-65"><a href="#cb12-65"></a> l_pacf[[r]] <span class="ot"><-</span> <span class="fu">plot_pacf</span>(d,</span>
<span id="cb12-66"><a href="#cb12-66"></a> <span class="at">remove_titles =</span> rm_titles,</span>
<span id="cb12-67"><a href="#cb12-67"></a> <span class="at">remove_xlab =</span> rm_xlab,</span>
<span id="cb12-68"><a href="#cb12-68"></a> ...)</span>
<span id="cb12-69"><a href="#cb12-69"></a></span>
<span id="cb12-70"><a href="#cb12-70"></a> }</span>
<span id="cb12-71"><a href="#cb12-71"></a></span>
<span id="cb12-72"><a href="#cb12-72"></a></span>
<span id="cb12-73"><a href="#cb12-73"></a> p_tot <span class="ot"><-</span> cowplot<span class="sc">::</span><span class="fu">plot_grid</span>(</span>
<span id="cb12-74"><a href="#cb12-74"></a> l_hist <span class="sc">%>%</span> <span class="fu">wrap_plots</span>(<span class="at">ncol =</span> <span class="dv">1</span>),</span>
<span id="cb12-75"><a href="#cb12-75"></a> l_seq <span class="sc">%>%</span> <span class="fu">wrap_plots</span>(<span class="at">ncol =</span> <span class="dv">1</span>),</span>