-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefineVeg.html
2732 lines (2623 loc) · 171 KB
/
DefineVeg.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>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="author" content="Mike Francis" />
<title>Define Vegetarians</title>
<script src="site_libs/header-attrs-2.16.2/header-attrs.js"></script>
<script src="site_libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/lumen.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<script src="site_libs/kePrint-0.0.1/kePrint.js"></script>
<link href="site_libs/lightable-0.0.1/lightable.css" rel="stylesheet" />
<link href="site_libs/font-awesome-5.1.0/css/all.css" rel="stylesheet" />
<link href="site_libs/font-awesome-5.1.0/css/v4-shims.css" rel="stylesheet" />
<link rel="shortcut icon" href="favicon_package_v0.16/favicon-32x32.png">
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">
code {
white-space: pre;
}
.sourceCode {
overflow: visible;
}
</style>
<style type="text/css" data-origin="pandoc">
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; } /* Alert */
code span.an { color: #008000; } /* Annotation */
code span.at { } /* Attribute */
code span.bu { } /* BuiltIn */
code span.cf { color: #0000ff; } /* ControlFlow */
code span.ch { color: #008080; } /* Char */
code span.cn { } /* Constant */
code span.co { color: #008000; } /* Comment */
code span.cv { color: #008000; } /* CommentVar */
code span.do { color: #008000; } /* Documentation */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.im { } /* Import */
code span.in { color: #008000; } /* Information */
code span.kw { color: #0000ff; } /* Keyword */
code span.op { } /* Operator */
code span.ot { color: #ff4000; } /* Other */
code span.pp { color: #ff4000; } /* Preprocessor */
code span.sc { color: #008080; } /* SpecialChar */
code span.ss { color: #008080; } /* SpecialString */
code span.st { color: #008080; } /* String */
code span.va { } /* Variable */
code span.vs { color: #008080; } /* VerbatimString */
code span.wa { color: #008000; font-weight: bold; } /* Warning */
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
var j = 0;
while (j < rules.length) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
j++;
continue;
}
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') {
j++;
continue;
}
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
}
}
})();
</script>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #adb5bd;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script type="text/javascript">
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark the anchor link active (and if it's in a dropdown, also mark that active)
var dropdown = menuAnchor.closest('li.dropdown');
if (window.bootstrap) { // Bootstrap 4+
menuAnchor.addClass('active');
dropdown.find('> .dropdown-toggle').addClass('active');
} else { // Bootstrap 3
menuAnchor.parent().addClass('active');
dropdown.addClass('active');
}
// Navbar adjustments
var navHeight = $(".navbar").first().height() + 15;
var style = document.createElement('style');
var pt = "padding-top: " + navHeight + "px; ";
var mt = "margin-top: -" + navHeight + "px; ";
var css = "";
// offset scroll position for anchor links (for fixed navbar)
for (var i = 1; i <= 6; i++) {
css += ".section h" + i + "{ " + pt + mt + "}\n";
}
style.innerHTML = "body {" + pt + "padding-bottom: 40px; }\n" + css;
document.head.appendChild(style);
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-bs-toggle="collapse" data-target="#navbar" data-bs-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Gene-vegetarianism interactions</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">
<span class="fa fa-home"></span>
Home
</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-solid fa-seedling"></span>
Full analysis code
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="DefineVeg.html">
<span class="fa fa-solid fa-seedling"></span>
1a. Define Vegetarians
</a>
</li>
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-solid fa-clipboard-check"></span>
1b. Phenotype prep
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="UKB_participantQC.html">
<span class="fa fa-solid fa-user"></span>
Participant QC
</a>
</li>
<li>
<a href="pheno.html">
<span class="fa fa-solid fa-syringe"></span>
Prepare phenotype table
</a>
</li>
<li>
<a href="skim-phenotype.html">
<span class="fa fa-solid fa-list"></span>
Pheno skim
</a>
</li>
</ul>
</li>
<li>
<a href="genoQC.html">
<span class="fa fa-solid fa-filter"></span>
1c. Genotype prep
</a>
</li>
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-solid fa-users"></span>
2. Matching + Veg. Effect
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="MatchEffect.html">
<span class="fa fa-solid fa-users"></span>
2. Matching + Veg. Effect
</a>
</li>
<li>
<a href="CompareRaw.html">
<span class="fa fa-regular fa-square"></span>
Compare raw phenotype values
</a>
</li>
</ul>
</li>
<li>
<a href="GWAS.html">
<span class="fa fa-solid fa-dna"></span>
3. Vegetarianism GWAS
</a>
</li>
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-solid fa-bolt"></span>
4. Gene x Vegetarianism GWIS
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="GWIS.html">GWIS in GEM</a>
</li>
<li>
<a href="hudson.html">Make interactive Manhattan plots</a>
</li>
</ul>
</li>
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-regular fa-folder"></span>
Extra scripts
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="medcodesextra.html">Medication code lists and extra formulas</a>
</li>
<li>
<a href="maxunrelated.html">Max unrelated script</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-solid fa-dna"></span>
Interactive Manhattan Plots
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="GxEplots.html">
<span class="fa fa-solid fa-dna"></span>
GWIS (variant level)
</a>
</li>
<li>
<a href="GxEplots.gene.html">
<span class="fa fa-solid fa-dna"></span>
GWIS (gene level)
</a>
</li>
<li>
<a href="GWASplot.html">
<span class="fa fa-solid fa-dna"></span>
GWAS
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div id="header">
<h1 class="title toc-ignore">Define Vegetarians</h1>
<h4 class="author">Mike Francis</h4>
<h4 class="date">2022-10-09 21:03:25</h4>
</div>
<div id="defining-high-quality-vegetarians-for-use-in-this-analysis"
class="section level1">
<h1>Defining “high quality” vegetarians for use in this analysis</h1>
<div id="purpose-of-this-script" class="section level3">
<h3>Purpose of this script:</h3>
<ul>
<li><p>Find the self-identified vegetarians in the UK Biobank dietary
recall survey instances</p></li>
<li><p>Assess their consistency with other parts of the dietary
survey.</p></li>
<li><p>Obtain a list of high quality vegetarians to use for subsequent
analyses.</p></li>
</ul>
<hr />
<p><strong>Veg5yr1 is the vegetarian variable used in the main analysis.
Being categorized as a vegetarian means participants adhered to all four
of these criteria:</strong></p>
<ul>
<li><p><strong>Self-identified as a vegetarian or vegan the first time
they were asked on a 24HR survey</strong></p></li>
<li><p><strong>Didn’t indicate eating any meat or fish on that same
first 24HR survey</strong></p></li>
<li><p><strong>Indicated no major dietary changes over past 5
years</strong></p></li>
<li><p><strong>No meat or fish eating indicated on initial
assessment</strong></p></li>
</ul>
<hr />
<p>The biomarker data that we use in this analysis was taken at the IA.
Therefore this is a combination of several columns that describe the
quality of vegetarianism at that same time point.</p>
<p>There are also some plots here showing general qualities of the 24HR
recall survey that were done in my data exploration that don’t factor
into the main analysis (i.e., <a
href="#plot-how-many-repeat-participants-were-in-each-instance-of-the-24hr">Plot:
How many repeat participants were in each instance of the 24HR?</a> , <a
href="#plot-percent-consistent-vegetarians-vs-number-of-recall-surveys-taken-across-3-years">Plot:
Percent consistent vegetarians vs number of recall survey’s taken across
3 years</a>, [Identify those who were vegetarian at two consecutive 24HR
instances])</p>
</div>
<div id="load-data" class="section level3">
<h3>Load data</h3>
<div id="load-packages-special-functions" class="section level4">
<h4>Load packages + special functions</h4>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">suppressMessages</span>(silent <span class="ot"><-</span> <span class="fu">lapply</span>(</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">c</span>(<span class="st">"plyr"</span>, <span class="st">"dplyr"</span>, <span class="st">"tidyverse"</span>, <span class="st">"data.table"</span>, <span class="st">"vroom"</span>, <span class="st">"knitr"</span>,<span class="st">"kableExtra"</span>,<span class="st">"cowplot"</span>), </span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> library, <span class="at">character.only=</span>T))</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>table <span class="ot">=</span> <span class="cf">function</span> (..., <span class="at">useNA =</span> <span class="st">'always'</span>) base<span class="sc">::</span><span class="fu">table</span>(..., <span class="at">useNA =</span> useNA)</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>mutate_when <span class="ot"><-</span> <span class="cf">function</span>(data, ...) {</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> dots <span class="ot"><-</span> <span class="fu">eval</span>(<span class="fu">substitute</span>(<span class="fu">alist</span>(...)))</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> (i <span class="cf">in</span> <span class="fu">seq</span>(<span class="dv">1</span>, <span class="fu">length</span>(dots), <span class="at">by =</span> <span class="dv">2</span>)) {</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> condition <span class="ot"><-</span> <span class="fu">eval</span>(dots[[i]], <span class="at">envir =</span> data)</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> mutations <span class="ot"><-</span> <span class="fu">eval</span>(dots[[i <span class="sc">+</span> <span class="dv">1</span>]], </span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> <span class="at">envir =</span> data[condition, , <span class="at">drop =</span> <span class="cn">FALSE</span>])</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> data[condition, <span class="fu">names</span>(mutations)] <span class="ot"><-</span> mutations</span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a> data</span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
</div>
<div id="load-uk-biobank-dataset" class="section level4">
<h4>Load UK Biobank dataset</h4>
<pre><code>## [1] 502527 5172</code></pre>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>bd<span class="ot">=</span><span class="fu">vroom</span>(<span class="st">"/Users/mike/Documents/R_files/UKBpheno/pheno/ukbXXXXX.tab"</span>, <span class="at">delim=</span><span class="st">"</span><span class="sc">\t</span><span class="st">"</span>, <span class="at">show_col_types =</span> <span class="cn">FALSE</span>)</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>bd<span class="ot">=</span><span class="fu">as_tibble</span>(bd)</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="fu">source</span>(<span class="st">"src/components/ukbXXXXX_factordata.R"</span>) <span class="co">#file provided by UKB "ukbXXXXX_loaddata.R" without the loading part, to label the responses in survey questions</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="fu">dim</span>(bd)</span></code></pre></div>
</div>
</div>
<div
id="identify-instances-where-24-hour-dietary-recall-24hr-was-taken-by-participants.-possible-instances-are-0-through-4."
class="section level3">
<h3>Identify instances where 24 hour dietary recall (24HR) was taken by
participants. Possible instances are 0 through 4.</h3>
<p>“daycols” are days of the week that the 24HR was taken, i.e. a proxy
for whether the survey was completed. In these columns, NA=survey wasn’t
taken that instance.</p>
<p>We change the days of the week to 1 because we’re not interested in
which day it actually was.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co">#First, remove withdrawn participants</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>withdrawn<span class="ot">=</span><span class="fu">read.csv</span>(<span class="st">"src/components/w48818_20220222.csv"</span>, <span class="at">header =</span> <span class="cn">FALSE</span>)</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="fu">nrow</span>(withdrawn)</span></code></pre></div>
<pre><code>## [1] 114</code></pre>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>bd<span class="ot">=</span>bd[<span class="sc">!</span>(bd<span class="sc">$</span>f.eid <span class="sc">%in%</span> withdrawn<span class="sc">$</span>V1), ]</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="fu">nrow</span>(bd)</span></code></pre></div>
<pre><code>## [1] 502413</code></pre>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Identify columns with days of the week</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>daycols<span class="ot"><-</span><span class="fu">c</span>(<span class="st">"f.20080.0.0"</span>, <span class="st">"f.20080.1.0"</span>, <span class="st">"f.20080.2.0"</span>,</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"f.20080.3.0"</span>, <span class="st">"f.20080.4.0"</span>)</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>bd1<span class="ot"><-</span>bd[,<span class="fu">c</span>(<span class="st">"f.eid"</span>, daycols)]</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a><span class="co">#Change all the factors to characters</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a>bd1[,daycols]<span class="ot"><-</span><span class="fu">sapply</span>(bd1[,daycols], as.character)</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a><span class="co">#Change NA's to zeros and days to 1's</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a>bd1[,daycols][(<span class="fu">is.na</span>(bd1[,daycols]))]<span class="ot"><-</span><span class="st">"0"</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a>bd1[,daycols][bd1[,daycols]<span class="sc">!=</span><span class="st">"0"</span>] <span class="ot"><-</span><span class="st">"1"</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a><span class="co">#Change these back to numeric</span></span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a>bd1[,daycols]<span class="ot"><-</span><span class="fu">sapply</span>(bd1[,daycols], as.integer)</span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true" tabindex="-1"></a><span class="co">#Now make a new column, everyone with rowSums zero never took recall</span></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true" tabindex="-1"></a><span class="co">#and those with >0 took it at least once</span></span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true" tabindex="-1"></a>bd1<span class="sc">$</span>times_taken_24HR<span class="ot"><-</span><span class="fu">rowSums</span>(bd1[,daycols])</span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true" tabindex="-1"></a>bd1<span class="sc">$</span>ever_took_24HR<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true" tabindex="-1"></a>bd1<span class="sc">$</span>ever_took_24HR[bd1<span class="sc">$</span>times_taken_24HR<span class="sc">></span><span class="dv">0</span>]<span class="ot"><-</span><span class="dv">1</span></span>
<span id="cb8-21"><a href="#cb8-21" aria-hidden="true" tabindex="-1"></a>bd1<span class="sc">$</span>times_taken_24HR[bd1<span class="sc">$</span>times_taken_24HR<span class="sc">==</span><span class="dv">0</span>]<span class="ot"><-</span><span class="cn">NA</span></span>
<span id="cb8-22"><a href="#cb8-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-23"><a href="#cb8-23" aria-hidden="true" tabindex="-1"></a><span class="fu">sum</span>(bd1<span class="sc">$</span>ever_took_24HR)</span></code></pre></div>
<pre><code>## [1] 210967</code></pre>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="co">#TP = time point</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(bd1)<span class="ot"><-</span><span class="fu">c</span>(<span class="st">"IID"</span>, <span class="st">"RecallTP0"</span>, <span class="st">"RecallTP1"</span>,</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"RecallTP2"</span>,<span class="st">"RecallTP3"</span>,<span class="st">"RecallTP4"</span>,</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="st">"times_taken_24HR"</span>, <span class="st">"ever_took_24HR"</span>)</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a><span class="co">#Optional save here</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a><span class="co">#write.csv(bd1, "UKB_24hourRecall-ParticipantInstancesTaken.csv", quote=F, row.names=F)</span></span></code></pre></div>
<p>During what time periods did the questionnaire cycles occur?</p>
<p><img src="images/paste-31AC8130.png" /></p>
</div>
<div id="plot-how-many-times-did-participants-take-24hr-surveys"
class="section level3">
<h3>Plot: How many times did participants take 24HR surveys</h3>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>perinstance<span class="ot">=</span>bd1<span class="sc">%>%</span><span class="fu">select</span>(RecallTP0<span class="sc">:</span>RecallTP4)</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>timestaken<span class="ot"><-</span>bd1<span class="sc">%>%</span><span class="fu">select</span>(times_taken_24HR)<span class="sc">%>%</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(times_taken_24HR)<span class="sc">%>%</span><span class="fu">summarise</span>(<span class="at">N=</span><span class="fu">n</span>())</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a>timestaken<span class="sc">%>%</span><span class="fu">kbl</span>()</span></code></pre></div>
<table>
<thead>
<tr>
<th style="text-align:right;">
times_taken_24HR
</th>
<th style="text-align:right;">
N
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
84145
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
48108
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
<td style="text-align:right;">
42482
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:right;">
30467
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
<td style="text-align:right;">
5765
</td>
</tr>
<tr>
<td style="text-align:right;">
NA
</td>
<td style="text-align:right;">
291446
</td>
</tr>
</tbody>
</table>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>p1<span class="ot">=</span><span class="fu">ggplot</span>(<span class="at">data=</span>timestaken, <span class="fu">aes</span>(<span class="at">x=</span>times_taken_24HR, <span class="at">y=</span>N)) <span class="sc">+</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_bar</span>(<span class="at">stat=</span><span class="st">"identity"</span>, <span class="at">width=</span><span class="fl">0.5</span>, <span class="at">fill =</span><span class="st">"#8C8C8C"</span>)<span class="sc">+</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">ylab</span>(<span class="st">"Number of participants"</span>)<span class="sc">+</span></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">"Number of 24 hour recall surveys taken"</span>)<span class="sc">+</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggtitle</span>(<span class="fu">paste</span>(<span class="st">"N = "</span>, <span class="fu">sum</span>(timestaken<span class="sc">$</span>N[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>]), <span class="at">sep=</span><span class="st">""</span>))<span class="sc">+</span></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>()</span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a>p1</span></code></pre></div>
<pre><code>## Warning: Removed 1 rows containing missing values (position_stack).</code></pre>
<p><img src="DefineVeg_files/figure-html/plot-1.png" width="672" /></p>
</div>
<div
id="plot-how-many-repeat-participants-were-in-each-instance-of-the-24hr"
class="section level3">
<h3>Plot: How many repeat participants were in each instance of the
24HR?</h3>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>take<span class="ot">=</span>bd1[<span class="fu">paste</span>(<span class="st">"RecallTP"</span>, <span class="dv">0</span><span class="sc">:</span><span class="dv">4</span>, <span class="at">sep=</span><span class="st">""</span>)]</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>take<span class="ot">=</span>take[<span class="sc">!</span><span class="fu">rowSums</span>(take)<span class="sc">==</span><span class="dv">0</span>,]</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a>take.plot<span class="ot">=</span>take<span class="sc">%>%</span> </span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">gather</span>(<span class="at">key =</span> v, <span class="at">value =</span> total, RecallTP0<span class="sc">:</span>RecallTP4, <span class="at">na.rm =</span> T)<span class="sc">%>%</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(v)<span class="sc">%>%</span><span class="fu">count</span>(total)<span class="sc">%>%</span><span class="fu">filter</span>(total<span class="sc">==</span><span class="dv">1</span>)</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(take.plot)<span class="ot">=</span><span class="fu">c</span>(<span class="st">"RecallTP"</span>, <span class="st">"Group"</span>, <span class="st">"n"</span>)</span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a>take.plot<span class="sc">$</span>RecallTP<span class="ot">=</span><span class="dv">0</span><span class="sc">:</span><span class="dv">4</span></span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a><span class="fu">as_tibble</span>(take.plot)<span class="sc">%>%</span><span class="fu">kbl</span>()</span></code></pre></div>
<table>
<thead>
<tr>
<th style="text-align:right;">
RecallTP
</th>
<th style="text-align:right;">
Group
</th>
<th style="text-align:right;">
n
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;">
0
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
70692
</td>
</tr>
<tr>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
100577
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
83243
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
103765
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:right;">
100223
</td>
</tr>
</tbody>
</table>
<p>This next script chunk is incredibly repetitive and I’m sure there is
a more efficient way to write it but it was faster for me to just write
it “manually”.</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>rep<span class="ot">=</span><span class="fu">paste</span>(<span class="st">"repeat"</span>, <span class="dv">0</span><span class="sc">:</span><span class="dv">4</span>, <span class="at">sep=</span><span class="st">""</span>)</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>take[rep]<span class="ot">=</span><span class="dv">0</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>take[rep[<span class="dv">1</span>]]<span class="ot">=</span><span class="dv">0</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a><span class="fu">nrow</span>(take[<span class="sc">!</span><span class="fu">rowSums</span>(take)<span class="sc">==</span><span class="dv">0</span>,])</span></code></pre></div>
<pre><code>## [1] 210967</code></pre>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="co">#TP1, previously took once</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat1[take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">1</span></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a><span class="co">#TP2, previously took at least once</span></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat2[(take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> </span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span>) <span class="sc">&</span></span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">1</span></span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true" tabindex="-1"></a><span class="co">#TP2, previously took twice</span></span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat2[(take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> </span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span>) <span class="sc">&</span></span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">2</span></span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true" tabindex="-1"></a><span class="co">#TP3, previously took at least once</span></span>
<span id="cb17-16"><a href="#cb17-16" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat3[(take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> </span>
<span id="cb17-17"><a href="#cb17-17" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span> </span>
<span id="cb17-18"><a href="#cb17-18" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span>) <span class="sc">&</span></span>
<span id="cb17-19"><a href="#cb17-19" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">1</span></span>
<span id="cb17-20"><a href="#cb17-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-21"><a href="#cb17-21" aria-hidden="true" tabindex="-1"></a><span class="co">#TP3, previously took at least twice</span></span>
<span id="cb17-22"><a href="#cb17-22" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat3[(</span>
<span id="cb17-23"><a href="#cb17-23" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span> </span>
<span id="cb17-24"><a href="#cb17-24" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span></span>
<span id="cb17-25"><a href="#cb17-25" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span>)</span>
<span id="cb17-26"><a href="#cb17-26" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">&</span> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">2</span></span>
<span id="cb17-27"><a href="#cb17-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-28"><a href="#cb17-28" aria-hidden="true" tabindex="-1"></a><span class="co">#TP3, previously took three times</span></span>
<span id="cb17-29"><a href="#cb17-29" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat3[(</span>
<span id="cb17-30"><a href="#cb17-30" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> </span>
<span id="cb17-31"><a href="#cb17-31" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> </span>
<span id="cb17-32"><a href="#cb17-32" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span></span>
<span id="cb17-33"><a href="#cb17-33" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>) ] <span class="ot">=</span> <span class="dv">3</span></span>
<span id="cb17-34"><a href="#cb17-34" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-35"><a href="#cb17-35" aria-hidden="true" tabindex="-1"></a><span class="co">#TP4, previously took at least once</span></span>
<span id="cb17-36"><a href="#cb17-36" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat4[(take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> </span>
<span id="cb17-37"><a href="#cb17-37" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span> </span>
<span id="cb17-38"><a href="#cb17-38" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span> </span>
<span id="cb17-39"><a href="#cb17-39" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>) <span class="sc">&</span></span>
<span id="cb17-40"><a href="#cb17-40" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP4<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">1</span></span>
<span id="cb17-41"><a href="#cb17-41" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-42"><a href="#cb17-42" aria-hidden="true" tabindex="-1"></a><span class="co">#TP4, previously took at least twice</span></span>
<span id="cb17-43"><a href="#cb17-43" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat4[(</span>
<span id="cb17-44"><a href="#cb17-44" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span> </span>
<span id="cb17-45"><a href="#cb17-45" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span></span>
<span id="cb17-46"><a href="#cb17-46" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span></span>
<span id="cb17-47"><a href="#cb17-47" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span> </span>
<span id="cb17-48"><a href="#cb17-48" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span></span>
<span id="cb17-49"><a href="#cb17-49" aria-hidden="true" tabindex="-1"></a> (take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>) </span>
<span id="cb17-50"><a href="#cb17-50" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">&</span> take<span class="sc">$</span>RecallTP4<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">2</span></span>
<span id="cb17-51"><a href="#cb17-51" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-52"><a href="#cb17-52" aria-hidden="true" tabindex="-1"></a><span class="co">#TP4, previously took at least three times</span></span>
<span id="cb17-53"><a href="#cb17-53" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat4[(</span>
<span id="cb17-54"><a href="#cb17-54" aria-hidden="true" tabindex="-1"></a>(take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span></span>
<span id="cb17-55"><a href="#cb17-55" aria-hidden="true" tabindex="-1"></a>(take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>) <span class="sc">|</span></span>
<span id="cb17-56"><a href="#cb17-56" aria-hidden="true" tabindex="-1"></a>(take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span>) </span>
<span id="cb17-57"><a href="#cb17-57" aria-hidden="true" tabindex="-1"></a>) <span class="sc">&</span> take<span class="sc">$</span>RecallTP4<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">3</span></span>
<span id="cb17-58"><a href="#cb17-58" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-59"><a href="#cb17-59" aria-hidden="true" tabindex="-1"></a><span class="co">#TP4, previously took four times</span></span>
<span id="cb17-60"><a href="#cb17-60" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat4[</span>
<span id="cb17-61"><a href="#cb17-61" aria-hidden="true" tabindex="-1"></a> take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb17-62"><a href="#cb17-62" aria-hidden="true" tabindex="-1"></a> <span class="sc">&</span> take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">1</span> <span class="sc">&</span> take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">1</span> </span>
<span id="cb17-63"><a href="#cb17-63" aria-hidden="true" tabindex="-1"></a> <span class="sc">&</span> take<span class="sc">$</span>RecallTP4<span class="sc">==</span><span class="dv">1</span>] <span class="ot">=</span> <span class="dv">4</span></span>
<span id="cb17-64"><a href="#cb17-64" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-65"><a href="#cb17-65" aria-hidden="true" tabindex="-1"></a><span class="co">#NA for those who didn't take the recall in that instance</span></span>
<span id="cb17-66"><a href="#cb17-66" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat0[take<span class="sc">$</span>RecallTP0<span class="sc">==</span><span class="dv">0</span>]<span class="ot">=</span><span class="cn">NA</span></span>
<span id="cb17-67"><a href="#cb17-67" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat1[take<span class="sc">$</span>RecallTP1<span class="sc">==</span><span class="dv">0</span>]<span class="ot">=</span><span class="cn">NA</span></span>
<span id="cb17-68"><a href="#cb17-68" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat2[take<span class="sc">$</span>RecallTP2<span class="sc">==</span><span class="dv">0</span>]<span class="ot">=</span><span class="cn">NA</span></span>
<span id="cb17-69"><a href="#cb17-69" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat3[take<span class="sc">$</span>RecallTP3<span class="sc">==</span><span class="dv">0</span>]<span class="ot">=</span><span class="cn">NA</span></span>
<span id="cb17-70"><a href="#cb17-70" aria-hidden="true" tabindex="-1"></a>take<span class="sc">$</span>repeat4[take<span class="sc">$</span>RecallTP4<span class="sc">==</span><span class="dv">0</span>]<span class="ot">=</span><span class="cn">NA</span></span>
<span id="cb17-71"><a href="#cb17-71" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-72"><a href="#cb17-72" aria-hidden="true" tabindex="-1"></a><span class="fu">sapply</span>(take, table)[<span class="dv">6</span><span class="sc">:</span><span class="dv">10</span>] <span class="co">#Count repeats at each instance</span></span></code></pre></div>
<pre><code>## $repeat0
##
## 0 <NA>
## 70692 140275
##
## $repeat1
##
## 0 1 <NA>
## 79599 20978 110390
##
## $repeat2
##
## 0 1 2 <NA>
## 27105 46006 10132 127724
##
## $repeat3
##
## 0 1 2 3 <NA>
## 19639 38856 37764 7506 107202
##
## $repeat4
##
## 0 1 2 3 4 <NA>
## 13932 20982 34122 25422 5765 110744</code></pre>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>take.plot<span class="ot">=</span><span class="fu">data.frame</span>(<span class="dv">0</span><span class="sc">:</span><span class="dv">4</span>, <span class="fu">sapply</span>(take, sum)[<span class="dv">1</span><span class="sc">:</span><span class="dv">5</span>], <span class="at">row.names =</span> <span class="cn">NULL</span>)</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(take.plot)<span class="ot">=</span><span class="fu">c</span>(<span class="st">"RecallTP"</span>, <span class="st">"N"</span>)</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a>y<span class="ot">=</span><span class="fu">data.frame</span>()</span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">0</span><span class="sc">:</span><span class="dv">4</span>){</span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a> x<span class="ot">=</span>take<span class="sc">%>%</span><span class="fu">group_by_</span>(<span class="fu">paste</span>(<span class="st">"RecallTP"</span>, i,<span class="at">sep=</span><span class="st">""</span>), <span class="fu">paste</span>(<span class="st">"repeat"</span>,i,<span class="at">sep=</span><span class="st">""</span>))<span class="sc">%>%</span></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarise</span>(<span class="at">count=</span><span class="fu">n</span>())<span class="sc">%>%</span></span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_</span>(<span class="st">"RecallTP"</span> <span class="ot">=</span> <span class="fu">paste</span>(<span class="st">"RecallTP"</span>, i,<span class="at">sep=</span><span class="st">""</span>))<span class="sc">%>%</span></span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">rename_</span>(<span class="st">"group"</span> <span class="ot">=</span> <span class="fu">paste</span>(<span class="st">"repeat"</span>, i,<span class="at">sep=</span><span class="st">""</span>))</span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a> x<span class="ot">=</span>x[x<span class="sc">$</span>RecallTP<span class="sc">==</span><span class="dv">1</span>,]</span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true" tabindex="-1"></a> x<span class="sc">$</span>RecallTP<span class="ot">=</span>i</span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true" tabindex="-1"></a> y<span class="ot">=</span><span class="fu">rbind</span>(y,x)</span>
<span id="cb19-13"><a href="#cb19-13" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<pre><code>## `summarise()` has grouped output by 'RecallTP0'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'RecallTP1'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'RecallTP2'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'RecallTP3'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'RecallTP4'. You can override using the `.groups` argument.</code></pre>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>y<span class="sc">$</span>group<span class="ot">=</span><span class="fu">mapvalues</span>(y<span class="sc">$</span>group, <span class="at">from=</span><span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>), </span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="at">to=</span><span class="fu">c</span>(<span class="st">"First time taking"</span>,</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"Second time taking"</span>,</span>