-
Notifications
You must be signed in to change notification settings - Fork 0
/
community_contribution.html
1343 lines (1288 loc) · 104 KB
/
community_contribution.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.5.57">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Sophie Wagner (sw3767)">
<title>Survival Analysis in R Demo with Competing Risk</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 -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { 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 { display: inline-block; 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;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="community_contribution_files/libs/clipboard/clipboard.min.js"></script>
<script src="community_contribution_files/libs/quarto-html/quarto.js"></script>
<script src="community_contribution_files/libs/quarto-html/popper.min.js"></script>
<script src="community_contribution_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="community_contribution_files/libs/quarto-html/anchor.min.js"></script>
<link href="community_contribution_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="community_contribution_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="community_contribution_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="community_contribution_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="community_contribution_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Survival Analysis in R Demo with Competing Risk</h1>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p>Sophie Wagner (sw3767) </p>
</div>
</div>
</div>
</header>
<section id="survival-analysis-in-r-demo" class="level1">
<h1>Survival Analysis in R Demo</h1>
<section id="setup" class="level2">
<h2 class="anchored" data-anchor-id="setup">Setup</h2>
<section id="load-packages" class="level3">
<h3 class="anchored" data-anchor-id="load-packages">Load packages</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(<span class="at">list =</span> <span class="fu">ls</span>()) <span class="co"># Clearing Environment and Plots</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr) <span class="co"># For data manipulation</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(forcats) <span class="co"># For easy factor conversion</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(rstpm2) <span class="co"># For hazard modelling</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(cmprsk) <span class="co"># For competing risk analysis</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidycmprsk) <span class="co"># For competing risk analysis</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(survminer) <span class="co"># For plotting</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2) <span class="co"># For plotting</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggsurvfit) <span class="co"># For plotting</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(readr) <span class="co"># Read in csv efficiently</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="read-in-data" class="level3">
<h3 class="anchored" data-anchor-id="read-in-data">Read in data</h3>
<p><strong>Data source info:</strong></p>
<p>SEER<em>Stat Version: 8.4.4</em></p>
<p><em>Session Type: Case Listing</em></p>
<p><em>Software: Surveillance Research Program, National Cancer Institute SEER</em>Stat software (www.seer.cancer.gov/seerstat) version 8.4.4.</p>
<p>Data: Surveillance, Epidemiology, and End Results (SEER) Program (www.seer.cancer.gov) SEER</p>
<p><em>SEER*Stat Database: Incidence - SEER Research Data, 8 Registries, Nov 2023 Sub (1975-2021) - Linked To County Attributes - Time Dependent (1990-2022) Income/Rurality, 1969-2022 Counties, National Cancer Institute, DCCPS, Surveillance Research Program, released April 2024, based on the November 2023 submission.</em></p>
<ul>
<li><p>Primary site: Breast</p></li>
<li><p>Behavior: Malignant</p></li>
<li><p>Sequence: First primary cancer</p></li>
<li><p>Diagnosis reporting source: Not diagnosed by autopsy or death certificate</p></li>
<li><p>Year of diagnosis: 2010-2015</p></li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>d <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"seer_breast_case_listings.csv"</span>, <span class="at">col_types =</span> <span class="fu">cols</span>(<span class="at">.default =</span> <span class="fu">col_factor</span>()))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
</section>
<section id="data-cleaning" class="level1">
<h1>Data cleaning</h1>
<p>Steps taken: Convert variables to desired type Drop irrelevant columns Handle missing and unknown vals Covariate categorization (collapse categories)</p>
<section id="convert-variables-to-desired-type" class="level3">
<h3 class="anchored" data-anchor-id="convert-variables-to-desired-type">Convert variables to desired type</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Convert some cols from factor to numeric or character</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>d <span class="ot"><-</span> d <span class="sc">|></span> </span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="st">`</span><span class="at">Year of diagnosis</span><span class="st">`</span><span class="ot">=</span><span class="fu">as.numeric</span>(<span class="st">`</span><span class="at">Year of diagnosis</span><span class="st">`</span>),</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Year of follow-up recode</span><span class="st">`</span><span class="ot">=</span><span class="fu">as.numeric</span>(<span class="st">`</span><span class="at">Year of follow-up recode</span><span class="st">`</span>),</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Survival months</span><span class="st">`</span><span class="ot">=</span><span class="fu">as.numeric</span>(<span class="st">`</span><span class="at">Survival months</span><span class="st">`</span>),</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Patient ID</span><span class="st">`</span><span class="ot">=</span><span class="fu">as.character</span>(<span class="st">`</span><span class="at">Patient ID</span><span class="st">`</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>We need the year and survival data to be numeric. Patient ID doesn’t need to be a factor.</p>
</section>
<section id="drop-cols-with-redundant-information" class="level3">
<h3 class="anchored" data-anchor-id="drop-cols-with-redundant-information">Drop cols with redundant information</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>d <span class="ot"><-</span> d <span class="sc">|></span> </span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(<span class="st">`</span><span class="at">Race recode (White, Black, Other)</span><span class="st">`</span>,</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Race and origin (recommended by SEER)</span><span class="st">`</span>,</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">ER Status Recode Breast Cancer (1990+)</span><span class="st">`</span>,</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">PR Status Recode Breast Cancer (1990+)</span><span class="st">`</span>,</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Derived HER2 Recode (2010+)</span><span class="st">`</span>)</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Let’s take a look at the data:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 19
`Patient ID` `Age recode with <1 year olds` `Year of diagnosis` Laterality
<chr> <fct> <dbl> <fct>
1 00149574 85+ years 1 Right - origi…
2 00164599 75-79 years 2 Right - origi…
3 00201849 75-79 years 3 Left - origin…
4 00237396 85+ years 4 Right - origi…
5 00241747 85+ years 3 Right - origi…
6 00249946 75-79 years 2 Right - origi…
# ℹ 15 more variables: `Histology recode - broad groupings` <fct>,
# `SEER historic stage A (1973-2015)` <fct>, `Radiation recode` <fct>,
# `Chemotherapy recode (yes, no/unk)` <fct>, `Breast Subtype (2010+)` <fct>,
# `SEER cause-specific death classification` <fct>,
# `SEER other cause of death classification` <fct>, `Survival months` <dbl>,
# `Vital status recode (study cutoff used)` <fct>,
# `Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)` <fct>, …</code></pre>
</div>
</div>
</section>
<section id="drop-unknowns-where-necessary" class="level3">
<h3 class="anchored" data-anchor-id="drop-unknowns-where-necessary">Drop unknowns where necessary</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>d_full <span class="ot"><-</span> d <span class="sc">|></span> </span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="st">`</span><span class="at">Rural-Urban Continuum Code</span><span class="st">`</span><span class="sc">!=</span> <span class="st">"Unknown/missing/no match/Not 1990-2022"</span>,</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Median household income inflation adj to 2022</span><span class="st">`</span><span class="sc">!=</span><span class="st">"Unknown/missing/no match/Not 1990-2022"</span>,</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> <span class="sc">!</span><span class="st">`</span><span class="at">Breast Subtype (2010+)</span><span class="st">`</span> <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Unknown"</span>,<span class="st">"Recode not available"</span>),</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">SEER historic stage A (1973-2015)</span><span class="st">`</span> <span class="sc">!=</span> <span class="st">"Unstaged"</span>,</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)</span><span class="st">`</span><span class="sc">!=</span><span class="st">"Non-Hispanic Unknown Race"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="collapse-categorical-variables" class="level3">
<h3 class="anchored" data-anchor-id="collapse-categorical-variables">Collapse categorical variables</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(d)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> Patient ID Age recode with <1 year olds Year of diagnosis
Length:94654 60-64 years:13187 Min. :1.000
Class :character 65-69 years:12256 1st Qu.:2.000
Mode :character 55-59 years:11888 Median :3.000
50-54 years:11709 Mean :3.493
45-49 years: 9672 3rd Qu.:5.000
70-74 years: 8997 Max. :6.000
(Other) :26945
Laterality
Right - origin of primary :46340
Left - origin of primary :47734
Paired site, but no information concerning laterality: 493
Bilateral, single primary : 28
Only one side - side unspecified : 59
Histology recode - broad groupings
8500-8549: ductal and lobular neoplasms :88872
8440-8499: cystic, mucinous and serous neoplasms: 1706
8140-8389: adenomas and adenocarcinomas : 1476
8010-8049: epithelial neoplasms, NOS : 929
8000-8009: unspecified neoplasms : 616
8560-8579: complex epithelial neoplasms : 439
(Other) : 616
SEER historic stage A (1973-2015)
Localized:61165
Regional :26072
Distant : 6208
Unstaged : 1209
Radiation recode
Beam radiation :50482
None/Unknown :37704
Radioactive implants (includes brachytherapy) (1988+): 2594
Recommended, unknown if administered : 1831
Refused (1988+) : 1268
Radiation, NOS method or source not specified : 548
(Other) : 227
Chemotherapy recode (yes, no/unk) Breast Subtype (2010+)
No/Unknown:56460 HR-/HER2- : 9193
Yes :38194 HR+/HER2- :65660
Unknown : 6204
Recode not available: 236
HR+/HER2+ : 9294
HR-/HER2+ : 4067
SEER cause-specific death classification
Alive or dead of other cause :82657
Dead (attributable to this cancer dx):11997
SEER other cause of death classification
Alive or dead due to cancer :83965
Dead (attributable to causes other than this cancer dx):10689
Survival months Vital status recode (study cutoff used)
Min. : 1.00 Alive:71968
1st Qu.: 32.00 Dead :22686
Median : 61.00
Mean : 62.88
3rd Qu.: 91.00
Max. :144.00
Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)
Non-Hispanic Asian or Pacific Islander :10960
Non-Hispanic White :66513
Hispanic (All Races) : 7812
Non-Hispanic Black : 8332
Non-Hispanic American Indian/Alaska Native: 767
Non-Hispanic Unknown Race : 270
Year of follow-up recode Year of death recode
Min. : 1.000 Alive at last contact:71968
1st Qu.: 1.000 2016 : 2603
Median : 1.000 2015 : 2534
Mean : 2.439 2017 : 2531
3rd Qu.: 2.000 2018 : 2346
Max. :12.000 2014 : 2208
(Other) :10464
Marital status at diagnosis
Widowed :11706
Divorced :10209
Married (including common law):52777
Single (never married) :14012
Unknown : 4715
Separated : 860
Unmarried or Domestic Partner : 375
Median household income inflation adj to 2022
$90,000 - $94,999 :14002
$75,000 - $79,999 :13501
$70,000 - $74,999 :11039
$95,000 - $99,999 : 8835
$80,000 - $84,999 : 8150
$100,000 - $109,999: 7688
(Other) :31439
Rural-Urban Continuum Code
Counties in metropolitan areas ge 1 million pop :50816
Counties in metropolitan areas of 250,000 to 1 million pop :25878
Nonmetropolitan counties adjacent to a metropolitan area : 5705
Nonmetropolitan counties not adjacent to a metropolitan area: 5810
Counties in metropolitan areas of lt 250 thousand pop : 6394
Unknown/missing/no match/Not 1990-2022 : 51
</code></pre>
</div>
</div>
<p>What are these (Other) categories? Expand levels:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">levels</span>(d<span class="sc">$</span><span class="st">`</span><span class="at">Median household income inflation adj to 2022</span><span class="st">`</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] "$90,000 - $94,999"
[2] "$95,000 - $99,999"
[3] "$120,000+"
[4] "$100,000 - $109,999"
[5] "$110,000 - $119,999"
[6] "$80,000 - $84,999"
[7] "$70,000 - $74,999"
[8] "$75,000 - $79,999"
[9] "$85,000 - $89,999"
[10] "$65,000 - $69,999"
[11] "$60,000 - $64,999"
[12] "$55,000 - $59,999"
[13] "$50,000 - $54,999"
[14] "$45,000 - $49,999"
[15] "$40,000 - $44,999"
[16] "< $40,000"
[17] "Unknown/missing/no match/Not 1990-2022"</code></pre>
</div>
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">levels</span>(d<span class="sc">$</span><span class="st">`</span><span class="at">Radiation recode</span><span class="st">`</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Beam radiation"
[2] "None/Unknown"
[3] "Radioactive implants (includes brachytherapy) (1988+)"
[4] "Combination of beam with implants or isotopes"
[5] "Radiation, NOS method or source not specified"
[6] "Radioisotopes (1988+)"
[7] "Refused (1988+)"
[8] "Recommended, unknown if administered" </code></pre>
</div>
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="fu">levels</span>(d<span class="sc">$</span><span class="st">`</span><span class="at">Histology recode - broad groupings</span><span class="st">`</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] "8500-8549: ductal and lobular neoplasms"
[2] "8140-8389: adenomas and adenocarcinomas"
[3] "8440-8499: cystic, mucinous and serous neoplasms"
[4] "9120-9169: blood vessel tumors"
[5] "8010-8049: epithelial neoplasms, NOS"
[6] "8000-8009: unspecified neoplasms"
[7] "8390-8429: adnexal and skin appendage neoplasms"
[8] "8930-8999: complex mixed and stromal neoplasms"
[9] "9180-9249: osseous and chondromatous neoplasms"
[10] "8560-8579: complex epithelial neoplasms"
[11] "9000-9039: fibroepithelial neoplasms"
[12] "8050-8089: squamous cell neoplasms"
[13] "8800-8809: soft tissue tumors and sarcomas, NOS"
[14] "8120-8139: transitional cell papillomas and carcinomas"
[15] "8890-8929: myomatous neoplasms"
[16] "8550-8559: acinar cell neoplasms"
[17] "8810-8839: fibromatous neoplasms"
[18] "8430-8439: mucoepidermoid neoplasms"
[19] "9040-9049: synovial-like neoplasms"
[20] "8850-8889: lipomatous neoplasms" </code></pre>
</div>
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="fu">levels</span>(d<span class="sc">$</span><span class="st">`</span><span class="at">Age recode with <1 year olds</span><span class="st">`</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] "85+ years" "75-79 years" "70-74 years" "55-59 years" "80-84 years"
[6] "65-69 years" "60-64 years" "50-54 years" "45-49 years" "40-44 years"
[11] "35-39 years" "30-34 years" "25-29 years" "20-24 years" "15-19 years"
[16] "01-04 years" "05-09 years"</code></pre>
</div>
</div>
<p>Explore income variable:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Create ordered factor income variable</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>income.o <span class="ot"><-</span> <span class="fu">factor</span>(</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> d_full<span class="sc">$</span><span class="st">`</span><span class="at">Median household income inflation adj to 2022</span><span class="st">`</span>,</span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"< $40,000"</span>, <span class="st">"$40,000 - $44,999"</span>, <span class="st">"$45,000 - $49,999"</span>,</span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"$50,000 - $54,999"</span>, <span class="st">"$55,000 - $59,999"</span>, <span class="st">"$60,000 - $64,999"</span>,</span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"$65,000 - $69,999"</span>, <span class="st">"$70,000 - $74,999"</span>, <span class="st">"$75,000 - $79,999"</span>,</span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a> <span class="st">"$80,000 - $84,999"</span>, <span class="st">"$85,000 - $89,999"</span>, <span class="st">"$90,000 - $94,999"</span>,</span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a> <span class="st">"$95,000 - $99,999"</span>, <span class="st">"$100,000 - $109,999"</span>, <span class="st">"$110,000 - $119,999"</span>,</span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a> <span class="st">"$120,000+"</span>),</span>
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a> <span class="at">ordered =</span> <span class="cn">TRUE</span>)</span>
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Create numeric income variable</span></span>
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>income.n <span class="ot"><-</span> <span class="fu">as.numeric</span>(<span class="fu">gsub</span>(<span class="st">"[^0-9]"</span>, <span class="st">""</span>, <span class="fu">sub</span>(<span class="st">" - .*"</span>, <span class="st">""</span>, </span>
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a> d_full<span class="sc">$</span><span class="st">`</span><span class="at">Median household income inflation adj to 2022</span><span class="st">`</span>)))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(d_full<span class="sc">$</span>income.n)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> Min. 1st Qu. Median Mean 3rd Qu. Max.
40000 70000 80000 79594 90000 120000 </code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(d_full, <span class="fu">aes</span>(<span class="at">y=</span>income.o))<span class="sc">+</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_bar</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="community_contribution_files/figure-html/unnamed-chunk-11-1.png" class="img-fluid figure-img" width="1440"></p>
</figure>
</div>
</div>
</div>
<p>Now that we know a bit more about the distribution of income, we can collapse it in a way that seems intuitive. We will also collapse some other vars at the same time based on domain knowledge:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>d_full <span class="ot"><-</span> d_full <span class="sc">|></span> </span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a> <span class="at">income_quantile =</span> <span class="fu">factor</span>(</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">fct_collapse</span>(</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Median household income inflation adj to 2022</span><span class="st">`</span>,</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a> <span class="at">Q1 =</span> <span class="fu">c</span>(<span class="st">"< $40,000"</span>, <span class="st">"$40,000 - $44,999"</span>, <span class="st">"$45,000 - $49,999"</span>, </span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a> <span class="st">"$50,000 - $54,999"</span>,<span class="st">"$55,000 - $59,999"</span>, <span class="st">"$60,000 - $64,999"</span>, </span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a> <span class="st">"$65,000 - $69,999"</span>),</span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a> <span class="at">Q2 =</span> <span class="fu">c</span>(<span class="st">"$70,000 - $74,999"</span>, <span class="st">"$75,000 - $79,999"</span>),</span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a> <span class="at">Q3 =</span> <span class="fu">c</span>(<span class="st">"$80,000 - $84,999"</span>, <span class="st">"$85,000 - $89,999"</span>),</span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a> <span class="at">Q4 =</span> <span class="fu">c</span>(<span class="st">"$90,000 - $94,999"</span>, <span class="st">"$95,000 - $99,999"</span>, <span class="st">"$100,000 - $109,999"</span>, </span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a> <span class="st">"$110,000 - $119,999"</span>, <span class="st">"$120,000+"</span>)</span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true" tabindex="-1"></a> <span class="at">ordered=</span><span class="cn">TRUE</span></span>
<span id="cb22-15"><a href="#cb22-15" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-16"><a href="#cb22-16" aria-hidden="true" tabindex="-1"></a> <span class="at">income_group =</span> <span class="fu">factor</span>(</span>
<span id="cb22-17"><a href="#cb22-17" aria-hidden="true" tabindex="-1"></a> <span class="fu">fct_collapse</span>(</span>
<span id="cb22-18"><a href="#cb22-18" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Median household income inflation adj to 2022</span><span class="st">`</span>,</span>
<span id="cb22-19"><a href="#cb22-19" aria-hidden="true" tabindex="-1"></a> <span class="st">"<60k"</span> <span class="ot">=</span> <span class="fu">c</span>(<span class="st">"< $40,000"</span>, <span class="st">"$40,000 - $44,999"</span>, <span class="st">"$45,000 - $49,999"</span>, </span>
<span id="cb22-20"><a href="#cb22-20" aria-hidden="true" tabindex="-1"></a> <span class="st">"$50,000 - $54,999"</span>,<span class="st">"$55,000 - $59,999"</span>),</span>
<span id="cb22-21"><a href="#cb22-21" aria-hidden="true" tabindex="-1"></a> <span class="st">"60-80k"</span><span class="ot">=</span><span class="fu">c</span>(<span class="st">"$60,000 - $64,999"</span>, <span class="st">"$65,000 - $69,999"</span>,<span class="st">"$70,000 - $74,999"</span>, </span>
<span id="cb22-22"><a href="#cb22-22" aria-hidden="true" tabindex="-1"></a> <span class="st">"$75,000 - $79,999"</span>),</span>
<span id="cb22-23"><a href="#cb22-23" aria-hidden="true" tabindex="-1"></a> <span class="st">"80-100k"</span><span class="ot">=</span><span class="fu">c</span>(<span class="st">"$80,000 - $84,999"</span>, <span class="st">"$85,000 - $89,999"</span>,<span class="st">"$90,000 - $94,999"</span>, </span>
<span id="cb22-24"><a href="#cb22-24" aria-hidden="true" tabindex="-1"></a> <span class="st">"$95,000 - $99,999"</span>),</span>
<span id="cb22-25"><a href="#cb22-25" aria-hidden="true" tabindex="-1"></a> <span class="st">">100k"</span><span class="ot">=</span><span class="fu">c</span>(<span class="st">"$100,000 - $109,999"</span>, <span class="st">"$110,000 - $119,999"</span>, <span class="st">"$120,000+"</span>), </span>
<span id="cb22-26"><a href="#cb22-26" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-27"><a href="#cb22-27" aria-hidden="true" tabindex="-1"></a> <span class="at">ordered=</span><span class="cn">TRUE</span></span>
<span id="cb22-28"><a href="#cb22-28" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-29"><a href="#cb22-29" aria-hidden="true" tabindex="-1"></a> <span class="at">urban_rural=</span><span class="fu">factor</span>(</span>
<span id="cb22-30"><a href="#cb22-30" aria-hidden="true" tabindex="-1"></a> <span class="fu">fct_recode</span>(</span>
<span id="cb22-31"><a href="#cb22-31" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Rural-Urban Continuum Code</span><span class="st">`</span>,</span>
<span id="cb22-32"><a href="#cb22-32" aria-hidden="true" tabindex="-1"></a> <span class="st">"Urban large"</span><span class="ot">=</span><span class="st">"Counties in metropolitan areas ge 1 million pop"</span>,</span>
<span id="cb22-33"><a href="#cb22-33" aria-hidden="true" tabindex="-1"></a> <span class="st">"Urban med"</span><span class="ot">=</span><span class="st">"Counties in metropolitan areas of 250,000 to 1 million pop"</span>,</span>
<span id="cb22-34"><a href="#cb22-34" aria-hidden="true" tabindex="-1"></a> <span class="st">"Urban med"</span><span class="ot">=</span><span class="st">"Counties in metropolitan areas of lt 250 thousand pop"</span>,</span>
<span id="cb22-35"><a href="#cb22-35" aria-hidden="true" tabindex="-1"></a> <span class="st">"Suburban"</span><span class="ot">=</span><span class="st">"Nonmetropolitan counties adjacent to a metropolitan area"</span>,</span>
<span id="cb22-36"><a href="#cb22-36" aria-hidden="true" tabindex="-1"></a> <span class="st">"Rural"</span><span class="ot">=</span><span class="st">"Nonmetropolitan counties not adjacent to a metropolitan area"</span></span>
<span id="cb22-37"><a href="#cb22-37" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-38"><a href="#cb22-38" aria-hidden="true" tabindex="-1"></a> <span class="at">ordered=</span><span class="cn">TRUE</span></span>
<span id="cb22-39"><a href="#cb22-39" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-40"><a href="#cb22-40" aria-hidden="true" tabindex="-1"></a> <span class="at">marital_status =</span> <span class="fu">fct_collapse</span>(</span>
<span id="cb22-41"><a href="#cb22-41" aria-hidden="true" tabindex="-1"></a> <span class="st">`</span><span class="at">Marital status at diagnosis</span><span class="st">`</span>,</span>
<span id="cb22-42"><a href="#cb22-42" aria-hidden="true" tabindex="-1"></a> <span class="st">"Married/Partnered"</span><span class="ot">=</span><span class="fu">c</span>(<span class="st">"Married (including common law)"</span>,</span>
<span id="cb22-43"><a href="#cb22-43" aria-hidden="true" tabindex="-1"></a> <span class="st">"Unmarried or Domestic Partner"</span>),</span>
<span id="cb22-44"><a href="#cb22-44" aria-hidden="true" tabindex="-1"></a> <span class="st">"Divorced/Separated"</span><span class="ot">=</span><span class="fu">c</span>(<span class="st">"Divorced"</span>,<span class="st">"Separated"</span>),</span>
<span id="cb22-45"><a href="#cb22-45" aria-hidden="true" tabindex="-1"></a> <span class="st">"Single (never married)"</span><span class="ot">=</span><span class="st">"Single (never married)"</span>,</span>
<span id="cb22-46"><a href="#cb22-46" aria-hidden="true" tabindex="-1"></a> <span class="st">"Unknown"</span><span class="ot">=</span><span class="st">"Unknown"</span></span>
<span id="cb22-47"><a href="#cb22-47" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb22-48"><a href="#cb22-48" aria-hidden="true" tabindex="-1"></a>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Let’s rename some vars for ease of use:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>d_full <span class="ot"><-</span> d_full <span class="sc">|></span> <span class="fu">rename</span>(<span class="at">age_at_dx=</span><span class="st">`</span><span class="at">Age recode with <1 year olds</span><span class="st">`</span>,</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a> <span class="at">stage=</span><span class="st">`</span><span class="at">SEER historic stage A (1973-2015)</span><span class="st">`</span>,</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a> <span class="at">radiation=</span><span class="st">`</span><span class="at">Radiation recode</span><span class="st">`</span>,</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a> <span class="at">chemo=</span><span class="st">`</span><span class="at">Chemotherapy recode (yes, no/unk)</span><span class="st">`</span>,</span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a> <span class="at">race_recode =</span> <span class="st">`</span><span class="at">Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)</span><span class="st">`</span>,</span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a> <span class="at">other_death.f=</span><span class="st">`</span><span class="at">SEER other cause of death classification</span><span class="st">`</span>,</span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a> <span class="at">cancer_death.f=</span><span class="st">`</span><span class="at">SEER cause-specific death classification</span><span class="st">`</span>,</span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a> <span class="at">all_death.f=</span><span class="st">`</span><span class="at">Vital status recode (study cutoff used)</span><span class="st">`</span>,</span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a> <span class="co"># er_status=`ER Status Recode Breast Cancer (1990+)`,</span></span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true" tabindex="-1"></a> <span class="co"># pr_status=`PR Status Recode Breast Cancer (1990+)`,</span></span>
<span id="cb23-11"><a href="#cb23-11" aria-hidden="true" tabindex="-1"></a> <span class="co"># her2_status=`Derived HER2 Recode (2010+)`,</span></span>
<span id="cb23-12"><a href="#cb23-12" aria-hidden="true" tabindex="-1"></a> <span class="at">breast_subtype=</span><span class="st">`</span><span class="at">Breast Subtype (2010+)</span><span class="st">`</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Make some categories ordinal:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>age_at_dx <span class="ot"><-</span> <span class="fu">factor</span>(d_full<span class="sc">$</span>age_at_dx, </span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a> <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"01-04 years"</span>, <span class="st">"05-09 years"</span>, <span class="st">"15-19 years"</span>, </span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"20-24 years"</span>, <span class="st">"25-29 years"</span>, <span class="st">"30-34 years"</span>, </span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a> <span class="st">"35-39 years"</span>, <span class="st">"40-44 years"</span>, <span class="st">"45-49 years"</span>, </span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"50-54 years"</span>, <span class="st">"55-59 years"</span>, <span class="st">"60-64 years"</span>, </span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"65-69 years"</span>, <span class="st">"70-74 years"</span>, <span class="st">"75-79 years"</span>, </span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a> <span class="st">"80-84 years"</span>, <span class="st">"85+ years"</span>), </span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a> <span class="at">ordered =</span> <span class="cn">TRUE</span>)</span>
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>stage <span class="ot"><-</span> <span class="fu">factor</span>(d_full<span class="sc">$</span>stage,</span>
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a> <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"Localized"</span>, <span class="st">"Regional"</span>,<span class="st">"Distant"</span>),</span>
<span id="cb24-11"><a href="#cb24-11" aria-hidden="true" tabindex="-1"></a> <span class="at">ordered=</span><span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Take a look at age distribution:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(d_full, <span class="fu">aes</span>(<span class="at">x=</span>age_at_dx))<span class="sc">+</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_bar</span>() <span class="sc">+</span></span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">angle =</span> <span class="dv">45</span>, <span class="at">hjust =</span> <span class="dv">1</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="community_contribution_files/figure-html/unnamed-chunk-15-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="creating-survival-and-competing-risk-variables" class="level1">
<h1>Creating survival and competing risk variables</h1>
<p>In survival analysis, we have a <strong>status</strong> variable which indicates whether an individual is still in the cohort (<strong>censored</strong>, meaning alive or lost to follow-up) or has experienced the event of interest (typically death, coded as 1 or higher). We define three specific status variables:</p>
<p>Single-event variables:</p>
<p><code>cancer_death</code>: Indicates 0 if the person is alive or has died from a non-cancer cause, and 1 if they died specifically from cancer (event of interest). <code>other_death</code>: Indicates 0 if the person is alive or died from cancer, and 1 if they died from a cause other than cancer (event of interest). <code>all_death</code>: Shows 0 if alive and 1 if deceased from any cause, effectively summing <code>cancer_death</code> and <code>other_death</code>.</p>
<p>Generally, we use <code>all_death</code> for <strong>overall survival</strong> analyses because it provides a comprehensive measure of survival, accounting for all possible causes of death, thus capturing overall mortality risk. For <strong>cancer-specific survival</strong>, we focus on <code>cancer_death</code>, which isolates cancer as the primary event of interest.</p>
<p>Multi-event variables:</p>
<p>The Competing Risk Status (<code>cmp_status</code>) variable combines the outcomes death from cancer and death from other causes, categorizing individuals as alive, cancer-specific death (CSD), or all-cause mortality (ACM).</p>
<p>In <strong>competing risks analysis</strong>, both <code>cancer_death</code> and <code>other_death</code> are combined into a single variable, allowing us to assess the probabilities of these events within one framework rather than evaluating each separately.</p>
<p>We will recode all of these in both factor form and 0/1/2.. numeric. It is smart to have both factor and numeric versions for the required packages.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>other_death.n <span class="ot"><-</span> <span class="fu">as.numeric</span>(</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">as.character</span>(</span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">fct_recode</span>(</span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a> d_full<span class="sc">$</span>other_death.f,</span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"0"</span><span class="ot">=</span> <span class="st">"Alive or dead due to cancer"</span>,</span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"1"</span><span class="ot">=</span> <span class="st">"Dead (attributable to causes other than this cancer dx)"</span></span>
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a>))</span>
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>cancer_death.n <span class="ot"><-</span> <span class="fu">as.numeric</span>(</span>
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">as.character</span>(</span>
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">fct_recode</span>(</span>
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true" tabindex="-1"></a> d_full<span class="sc">$</span>cancer_death.f,</span>
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true" tabindex="-1"></a> <span class="st">"0"</span><span class="ot">=</span> <span class="st">"Alive or dead of other cause"</span>,</span>
<span id="cb26-14"><a href="#cb26-14" aria-hidden="true" tabindex="-1"></a> <span class="st">"1"</span><span class="ot">=</span> <span class="st">"Dead (attributable to this cancer dx)"</span></span>
<span id="cb26-15"><a href="#cb26-15" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb26-16"><a href="#cb26-16" aria-hidden="true" tabindex="-1"></a>))</span>
<span id="cb26-17"><a href="#cb26-17" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>all_death.n <span class="ot"><-</span> <span class="fu">as.numeric</span>(</span>
<span id="cb26-18"><a href="#cb26-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">as.character</span>(</span>
<span id="cb26-19"><a href="#cb26-19" aria-hidden="true" tabindex="-1"></a> <span class="fu">fct_recode</span>(</span>
<span id="cb26-20"><a href="#cb26-20" aria-hidden="true" tabindex="-1"></a> d_full<span class="sc">$</span>all_death.f,</span>
<span id="cb26-21"><a href="#cb26-21" aria-hidden="true" tabindex="-1"></a> <span class="st">"0"</span><span class="ot">=</span> <span class="st">"Alive"</span>,</span>
<span id="cb26-22"><a href="#cb26-22" aria-hidden="true" tabindex="-1"></a> <span class="st">"1"</span><span class="ot">=</span> <span class="st">"Dead"</span></span>
<span id="cb26-23"><a href="#cb26-23" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb26-24"><a href="#cb26-24" aria-hidden="true" tabindex="-1"></a>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Create our competing risk variable.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>cmp_status.f <span class="ot"><-</span> <span class="fu">ifelse</span>(</span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a> d_full<span class="sc">$</span>cancer_death.f<span class="sc">==</span><span class="st">"Dead (attributable to this cancer dx)"</span>, <span class="st">"CSD"</span>, </span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">ifelse</span>(d_full<span class="sc">$</span>other_death.f<span class="sc">==</span><span class="st">"Dead (attributable to causes other than this cancer dx)"</span>, <span class="st">"ACM"</span>, <span class="st">"Alive"</span>))</span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a>d_full<span class="sc">$</span>cmp_status.n <span class="ot"><-</span> <span class="fu">as.numeric</span>(</span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">as.character</span>(</span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">fct_recode</span>(</span>
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true" tabindex="-1"></a> d_full<span class="sc">$</span>cmp_status.f,</span>
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true" tabindex="-1"></a> <span class="st">"0"</span><span class="ot">=</span><span class="st">"Alive"</span>,</span>
<span id="cb27-9"><a href="#cb27-9" aria-hidden="true" tabindex="-1"></a> <span class="st">"1"</span><span class="ot">=</span><span class="st">"CSD"</span>,</span>
<span id="cb27-10"><a href="#cb27-10" aria-hidden="true" tabindex="-1"></a> <span class="st">"2"</span><span class="ot">=</span><span class="st">"ACM"</span></span>
<span id="cb27-11"><a href="#cb27-11" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb27-12"><a href="#cb27-12" aria-hidden="true" tabindex="-1"></a>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="survival-analysis" class="level1">
<h1>Survival analysis</h1>
<p>To conduct a detailed survival and competing risks analysis, we use specialized packages like <code>survival</code>, <code>cmprsk</code>, <code>tidycmprsk</code>, and <code>ggsurvfit</code>. These packages allow us to estimate survival probabilities, visualize Kaplan-Meier curves, and handle competing risks with cumulative incidence functions (CIF).</p>
<p>survival: Core package for survival analysis in R. It includes functions to create survival objects (Surv) and fit survival models (survfit for Kaplan-Meier and coxph for Cox Proportional Hazards models). Highly customizable, but lacks some visualization features.</p>
<p>ggsurvfit: A wrapper around survival that enhances plot functionality by integrating with ggplot2, allowing easier addition of elements like risk tables and confidence intervals.</p>
<p>cmprsk: Provides functions for competing risks analysis, specifically cumulative incidence functions (CIF) via cuminc and Fine-Gray models (crr). Focus is stats, lacks ggplot2 compatibility</p>
<p>tidycmprsk: A tidyverse-friendly wrapper around cmprsk functions, simplifying syntax and enhancing compatibility with ggplot2 for visualization.</p>
<p>Using these different packages output different types of objects, which can get confusing. Let’s take is step by step and see a breakdown of how the components work together, along with their benefits.</p>
<section id="kaplan-meier-survival-analysis" class="level2">
<h2 class="anchored" data-anchor-id="kaplan-meier-survival-analysis">Kaplan-Meier Survival Analysis</h2>
<section id="creating-a-survival-object" class="level3">
<h3 class="anchored" data-anchor-id="creating-a-survival-object">Creating a survival object</h3>
<p>Survival objects (<code>Surv()</code>) in <code>survival</code> and <code>ggsurvfit</code> represent time-to-event data.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>overall_surv_obj <span class="ot"><-</span> survival<span class="sc">::</span><span class="fu">Surv</span>(<span class="at">time =</span> d_full<span class="sc">$</span><span class="st">`</span><span class="at">Survival months</span><span class="st">`</span>, </span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a> <span class="at">event =</span> d_full<span class="sc">$</span>all_death.n)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a>overall_surv_obj <span class="ot"><-</span> ggsurvfit<span class="sc">::</span><span class="fu">Surv</span>(<span class="at">time =</span> d_full<span class="sc">$</span><span class="st">`</span><span class="at">Survival months</span><span class="st">`</span>, </span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a> <span class="at">event =</span> d_full<span class="sc">$</span>all_death.n)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>The above gives us a <strong>survival object</strong>. This object can then be used as a <strong>response variable</strong> in survival models. (We don’t get that much information out of it until we use it in a survival model.)</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(overall_surv_obj)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> time status
Min. : 1.00 Min. :0.0000
1st Qu.: 31.00 1st Qu.:0.0000
Median : 61.00 Median :0.0000
Mean : 62.57 Mean :0.2291
3rd Qu.: 90.00 3rd Qu.:0.0000
Max. :144.00 Max. :1.0000 </code></pre>
</div>
</div>
<p>The summary of the survival object doesn’t display the survival probabilities directly, but does reveal the status and distribution of censored vs. event cases.</p>
</section>
<section id="fit-kaplan-meier-curve" class="level3">
<h3 class="anchored" data-anchor-id="fit-kaplan-meier-curve">Fit Kaplan Meier curve</h3>
<p>Lets’s now compute a survival curve using our censored time-to-event data.</p>
<p>The <code>ggsurvfit</code> package makes this easy. Below, we will use <code>ggsurvfit::survfit2</code> function which estimates survival probabilities over time. It does the same thing as <code>survival::survfit</code> but returns an environment compatible with <code>ggplot2</code>-good for plotting.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a>overall_surv_fit <span class="ot"><-</span> survival<span class="sc">::</span><span class="fu">survfit</span>(overall_surv_obj <span class="sc">~</span> stage, <span class="at">data=</span> d_full)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>overall_surv_fit <span class="ot"><-</span> ggsurvfit<span class="sc">::</span><span class="fu">survfit2</span>(overall_surv_obj <span class="sc">~</span> stage, <span class="at">data=</span>d_full)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a>overall_surv_fit</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Call: survfit(formula = overall_surv_obj ~ stage, data = d_full)
n events median 0.95LCL 0.95UCL
stage=Localized 57262 9382 124 124 125
stage=Regional 24854 6664 120 119 121
stage=Distant 5394 4001 108 104 110</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(overall_surv_fit, <span class="at">times=</span><span class="fu">c</span>(<span class="dv">12</span>,<span class="dv">24</span>,<span class="dv">36</span>,<span class="dv">48</span>,<span class="dv">60</span>,<span class="dv">72</span>,<span class="dv">84</span>,<span class="dv">96</span>,<span class="dv">108</span>,<span class="dv">120</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Call: survfit(formula = overall_surv_obj ~ stage, data = d_full)
stage=Localized
time n.risk n.event survival std.err lower 95% CI upper 95% CI
12 52237 766 0.986 0.000499 0.985 0.987
24 46385 713 0.972 0.000724 0.970 0.973
36 40393 743 0.955 0.000932 0.953 0.957
48 35599 570 0.941 0.001097 0.939 0.943
60 29130 728 0.919 0.001328 0.917 0.922
72 22740 770 0.892 0.001620 0.889 0.895
84 15595 686 0.860 0.001977 0.856 0.864
96 10424 750 0.811 0.002548 0.806 0.816
108 6406 787 0.735 0.003484 0.728 0.742
120 2466 975 0.563 0.005620 0.552 0.574
stage=Regional
time n.risk n.event survival std.err lower 95% CI upper 95% CI
12 22765 585 0.976 0.00099 0.974 0.978
24 20332 462 0.955 0.00136 0.952 0.958
36 17872 598 0.925 0.00178 0.922 0.929
48 15816 378 0.905 0.00204 0.901 0.909
60 13066 472 0.875 0.00238 0.870 0.880
72 10541 479 0.840 0.00278 0.834 0.845
84 7751 400 0.803 0.00321 0.797 0.809
96 5524 528 0.741 0.00395 0.733 0.748
108 3697 536 0.656 0.00491 0.647 0.666
120 1825 703 0.491 0.00658 0.478 0.504
stage=Distant
time n.risk n.event survival std.err lower 95% CI upper 95% CI
12 5041 238 0.955 0.00282 0.950 0.961
24 4646 253 0.907 0.00401 0.899 0.915
36 4280 290 0.849 0.00498 0.840 0.859
48 3728 368 0.774 0.00588 0.763 0.786
60 3394 159 0.740 0.00621 0.728 0.752
72 3091 167 0.703 0.00653 0.690 0.716
84 2728 171 0.663 0.00684 0.650 0.677
96 2375 351 0.575 0.00736 0.561 0.590
108 1880 292 0.499 0.00763 0.484 0.514
120 1350 462 0.369 0.00767 0.354 0.384</code></pre>
</div>
</div>
</section>
<section id="plotting-the-kaplan-meier-curve" class="level3">
<h3 class="anchored" data-anchor-id="plotting-the-kaplan-meier-curve">Plotting the Kaplan-Meier curve</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a>ggsurvfit<span class="sc">::</span><span class="fu">ggsurvfit</span>(overall_surv_fit) <span class="sc">+</span> </span>
<span id="cb38-2"><a href="#cb38-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">add_confidence_interval</span>() <span class="sc">+</span></span>
<span id="cb38-3"><a href="#cb38-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">add_risktable</span>(<span class="at">risktable_stats=</span><span class="st">"n.risk"</span>) <span class="sc">+</span> </span>
<span id="cb38-4"><a href="#cb38-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">120</span>), <span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">120</span>, <span class="at">by =</span> <span class="dv">12</span>)) <span class="sc">+</span> </span>
<span id="cb38-5"><a href="#cb38-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">1</span>), <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">percent_format</span>(), <span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">1</span>, <span class="at">by =</span> <span class="fl">0.25</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="community_contribution_files/figure-html/unnamed-chunk-25-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a>survminer<span class="sc">::</span><span class="fu">ggsurvplot</span>(overall_surv_fit, </span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a> <span class="at">risk.table=</span>T,</span>
<span id="cb39-3"><a href="#cb39-3" aria-hidden="true" tabindex="-1"></a> <span class="at">risk.table.height=</span><span class="fl">0.3</span>, <span class="co">#scale 0-1</span></span>
<span id="cb39-4"><a href="#cb39-4" aria-hidden="true" tabindex="-1"></a> <span class="at">pval =</span> T,</span>
<span id="cb39-5"><a href="#cb39-5" aria-hidden="true" tabindex="-1"></a> <span class="at">conf.int=</span>T,</span>
<span id="cb39-6"><a href="#cb39-6" aria-hidden="true" tabindex="-1"></a> <span class="at">palette =</span> <span class="st">"Blues"</span>,</span>
<span id="cb39-7"><a href="#cb39-7" aria-hidden="true" tabindex="-1"></a> <span class="at">surv.median.line=</span><span class="st">"hv"</span>,</span>
<span id="cb39-8"><a href="#cb39-8" aria-hidden="true" tabindex="-1"></a> <span class="at">title=</span><span class="st">"Survival plot"</span>,</span>
<span id="cb39-9"><a href="#cb39-9" aria-hidden="true" tabindex="-1"></a> <span class="at">xlab=</span><span class="st">"Months"</span>,</span>
<span id="cb39-10"><a href="#cb39-10" aria-hidden="true" tabindex="-1"></a> <span class="at">ylab=</span><span class="st">"Survival probability"</span>,</span>
<span id="cb39-11"><a href="#cb39-11" aria-hidden="true" tabindex="-1"></a> <span class="at">xlim=</span><span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">120</span>),</span>
<span id="cb39-12"><a href="#cb39-12" aria-hidden="true" tabindex="-1"></a> <span class="at">break.x.by=</span><span class="dv">24</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning in geom_segment(aes(x = 0, y = max(y2), xend = max(x1), yend = max(y2)), : All aesthetics have length 1, but the data has 3 rows.
ℹ Please consider using `annotate()` or provide this layer with data containing
a single row.
All aesthetics have length 1, but the data has 3 rows.
ℹ Please consider using `annotate()` or provide this layer with data containing
a single row.
All aesthetics have length 1, but the data has 3 rows.
ℹ Please consider using `annotate()` or provide this layer with data containing
a single row.
All aesthetics have length 1, but the data has 3 rows.
ℹ Please consider using `annotate()` or provide this layer with data containing
a single row.</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="community_contribution_files/figure-html/unnamed-chunk-26-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>return an object of class ggsurvplot which is list containing the following components:</p>
<p>plot: the survival plot (ggplot object)</p>
<p>table: the number of subjects at risk table per time (ggplot object).</p>
<p>cumevents: the cumulative number of events table (ggplot object).</p>
<p>ncensor.plot: the number of censoring (ggplot object).</p>
<p>data.survplot: the data used to plot the survival curves (data.frame).</p>
<p>data.survtable: the data used to plot the tables under the main survival curves (data.frame).</p>
<p>Can mix and match up to a certain point: If we create with <code>survival</code> we cannot add risk table and some other elements that ggsurvfit can do easily.</p>
</section>
<section id="getting-the-cox-ph-hazard-ratio" class="level3">
<h3 class="anchored" data-anchor-id="getting-the-cox-ph-hazard-ratio">Getting the Cox PH Hazard Ratio</h3>
<p>To calculate hazard ratios, we fit a Cox Proportional Hazards (Cox PH) model and check for proportional hazards assumptions using residuals.</p>
<p>Fit the coxph model:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Fit model</span></span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a>overall_ph <span class="ot"><-</span> survival<span class="sc">::</span><span class="fu">coxph</span>(overall_surv_obj <span class="sc">~</span> stage <span class="sc">+</span> marital_status <span class="sc">+</span> urban_rural <span class="sc">+</span> income_quantile, <span class="at">data=</span>d_full) <span class="co"># need survival pkg</span></span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Extract HRs</span></span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(overall_ph)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Call:
survival::coxph(formula = overall_surv_obj ~ stage + marital_status +
urban_rural + income_quantile, data = d_full)
n= 87510, number of events= 20047
coef exp(coef) se(coef) z
stage.L 0.500229 1.649099 0.013765 36.342
stage.Q 0.035072 1.035694 0.012647 2.773
marital_statusDivorced/Separated -0.425298 0.653575 0.024623 -17.272
marital_statusMarried/Partnered -0.653105 0.520427 0.018083 -36.118
marital_statusSingle (never married) -0.475805 0.621384 0.023035 -20.656
marital_statusUnknown -0.319424 0.726567 0.033572 -9.515
urban_rural.L 0.057867 1.059574 0.023619 2.450
urban_rural.Q -0.003222 0.996783 0.020513 -0.157
urban_rural.C -0.033973 0.966598 0.020938 -1.623
income_quantile.L 0.102771 1.108238 0.015879 6.472
income_quantile.Q -0.014896 0.985214 0.015679 -0.950
income_quantile.C -0.038395 0.962333 0.016771 -2.289
Pr(>|z|)
stage.L < 2e-16 ***
stage.Q 0.00555 **
marital_statusDivorced/Separated < 2e-16 ***
marital_statusMarried/Partnered < 2e-16 ***
marital_statusSingle (never married) < 2e-16 ***
marital_statusUnknown < 2e-16 ***
urban_rural.L 0.01429 *
urban_rural.Q 0.87518
urban_rural.C 0.10468
income_quantile.L 9.66e-11 ***
income_quantile.Q 0.34207
income_quantile.C 0.02206 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coef) exp(-coef) lower .95 upper .95
stage.L 1.6491 0.6064 1.6052 1.6942
stage.Q 1.0357 0.9655 1.0103 1.0617
marital_statusDivorced/Separated 0.6536 1.5300 0.6228 0.6859
marital_statusMarried/Partnered 0.5204 1.9215 0.5023 0.5392
marital_statusSingle (never married) 0.6214 1.6093 0.5940 0.6501
marital_statusUnknown 0.7266 1.3763 0.6803 0.7760
urban_rural.L 1.0596 0.9438 1.0116 1.1098
urban_rural.Q 0.9968 1.0032 0.9575 1.0377
urban_rural.C 0.9666 1.0346 0.9277 1.0071
income_quantile.L 1.1082 0.9023 1.0743 1.1433
income_quantile.Q 0.9852 1.0150 0.9554 1.0160
income_quantile.C 0.9623 1.0391 0.9312 0.9945
Concordance= 0.644 (se = 0.003 )
Likelihood ratio test= 2582 on 12 df, p=<2e-16
Wald test = 2727 on 12 df, p=<2e-16
Score (logrank) test = 2791 on 12 df, p=<2e-16</code></pre>
</div>
</div>
<p>Test for proportional hazards assumption:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a>overall_test <span class="ot"><-</span> survival<span class="sc">::</span><span class="fu">cox.zph</span>(overall_ph)</span>
<span id="cb43-2"><a href="#cb43-2" aria-hidden="true" tabindex="-1"></a>overall_test</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> chisq df p
stage 220.52 2 < 2e-16
marital_status 224.86 4 < 2e-16
urban_rural 7.79 3 0.05059
income_quantile 19.36 3 0.00023
GLOBAL 502.14 12 < 2e-16</code></pre>
</div>
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a>survminer<span class="sc">::</span><span class="fu">ggcoxzph</span>(overall_test) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="community_contribution_files/figure-html/unnamed-chunk-28-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>The ggcoxzph function from survminer provides plots for each covariate, indicating whether the proportional hazards assumption holds. <em>Non-horizontal lines suggest potential violations.</em> And we want a global p-value that is NOT significant (i.e. no significant evidence that the hazard ratio changes over time). Note if you get a significant value, look into: - stratifying by survival time (less than 5 years, greater than 5 years, e.g.) - creating an interaction term between time variable and a covariate that doesn’t pass (see if significant relationship)</p>
<p><code>survminer</code> gives you a wrapper around plot.cox.zph and makes plotting super easy!</p>
</section>
</section>
<section id="competing-risks-analysis" class="level2">
<h2 class="anchored" data-anchor-id="competing-risks-analysis">Competing risks analysis</h2>
<p>In cases where multiple events can occur, (in this case a patient can die from either cancer OR other causes) competing risks analysis is essential. KM cannot account for competing events – instead, we can look at cumulative incidence functions (CIFs) to estimate the probability of each event type – while acknowledging that competing events reduce the probability of observing the primary event of interest.</p>
<p>There are a couple of different packages out there for competing risk analysis, and it gets tricky figuring out which one to use!</p>
<p>Cumulative incidence function (CIF) objects in cmprsk and tidycmprsk handle competing risks, representing the probability of specific events over time.</p>
<p><code>cmprsk</code> is the original competing risk package</p>
<p><code>tidycmprsk</code> provides a tidyverse wrapper which makes it easy for plotting and compatible with <code>ggsurvfit</code></p>
<p>Again, we will start by fitting a model, this time with the event variable having more than 1 event. We will use our cmp_status variable, coded with 0=Alive, 1=Cancer-specific death, and 2=Other cause of death.</p>
<p><code>cmprsk::cuminc</code> can take either factor or numeric. Make sure to specify which level is your censoring variable.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a>cif_obj <span class="ot"><-</span> cmprsk<span class="sc">::</span><span class="fu">cuminc</span>(<span class="at">ftime=</span>d_full<span class="sc">$</span><span class="st">`</span><span class="at">Survival months</span><span class="st">`</span>, </span>
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a> <span class="at">fstatus=</span>d_full<span class="sc">$</span>cmp_status.f,</span>
<span id="cb46-3"><a href="#cb46-3" aria-hidden="true" tabindex="-1"></a> <span class="at">cencode=</span><span class="st">"Alive"</span>,</span>
<span id="cb46-4"><a href="#cb46-4" aria-hidden="true" tabindex="-1"></a> <span class="at">group=</span>d_full<span class="sc">$</span>stage)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a>cmprsk<span class="sc">::</span><span class="fu">plot.cuminc</span>(cif_obj,<span class="at">main=</span><span class="st">"Cumulative inc funciton"</span>, <span class="at">xlab=</span><span class="st">"Months"</span>,</span>
<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a> <span class="at">color=</span><span class="fu">c</span>(<span class="st">"blue"</span>,<span class="st">"red"</span>,<span class="st">"green"</span>,<span class="st">"blue"</span>,<span class="st">"red"</span>,<span class="st">"green"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="community_contribution_files/figure-html/unnamed-chunk-30-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Or, we can do it much more easily using the tidycmprsk package! Note: must use tidycmprsk object to plot it</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb48"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb48-1"><a href="#cb48-1" aria-hidden="true" tabindex="-1"></a>cr_surv_obj <span class="ot"><-</span> tidycmprsk<span class="sc">::</span><span class="fu">Surv</span>(d_full<span class="sc">$</span><span class="st">`</span><span class="at">Survival months</span><span class="st">`</span>, <span class="fu">as.factor</span>(d_full<span class="sc">$</span>cmp_status.n))</span>
<span id="cb48-2"><a href="#cb48-2" aria-hidden="true" tabindex="-1"></a>cif_ggfit <span class="ot"><-</span> tidycmprsk<span class="sc">::</span><span class="fu">cuminc</span>(<span class="fu">Surv</span>(<span class="st">`</span><span class="at">Survival months</span><span class="st">`</span>, <span class="fu">as.factor</span>(cmp_status.n)) <span class="sc">~</span> stage, <span class="at">data=</span>d_full)</span>
<span id="cb48-3"><a href="#cb48-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb48-4"><a href="#cb48-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Or pass Surv directly and model will default to tidycmprsk::Surv</span></span>
<span id="cb48-5"><a href="#cb48-5" aria-hidden="true" tabindex="-1"></a>cif_ggfit <span class="ot"><-</span> tidycmprsk<span class="sc">::</span><span class="fu">cuminc</span>(<span class="fu">Surv</span>(<span class="st">`</span><span class="at">Survival months</span><span class="st">`</span>, <span class="fu">as.factor</span>(cmp_status.n)) <span class="sc">~</span> stage, <span class="at">data=</span>d_full)</span>
<span id="cb48-6"><a href="#cb48-6" aria-hidden="true" tabindex="-1"></a>cif_ggfit</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code></code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>── cuminc() ────────────────────────────────────────────────────────────────────</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>• Failure type "1"</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>strata time n.risk estimate std.error 95% CI
Localized 50.0 34,059 0.017 0.001 0.016, 0.018
Localized 100 8,788 0.058 0.002 0.055, 0.062
Regional 50.0 15,224 0.061 0.002 0.058, 0.065
Regional 100 4,790 0.173 0.004 0.167, 0.180
Distant 50.0 3,674 0.205 0.006 0.194, 0.216
Distant 100 2,177 0.394 0.007 0.379, 0.408 </code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>• Failure type "2"</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>strata time n.risk estimate std.error 95% CI
Localized 50.0 34,059 0.045 0.001 0.043, 0.047
Localized 100 8,788 0.157 0.003 0.152, 0.162
Regional 50.0 15,224 0.039 0.001 0.037, 0.042
Regional 100 4,790 0.115 0.003 0.109, 0.121
Distant 50.0 3,674 0.025 0.002 0.021, 0.029
Distant 100 2,177 0.048 0.003 0.043, 0.055 </code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>• Tests</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>outcome statistic df p.value
1 8,215 2.00 <0.001
2 2,095 2.00 <0.001 </code></pre>
</div>
</div>
<p>Filename: Case Listing Session-1 Matrix-2 SEER*Stat Version: 8.4.4 Date: November 5, 2024</p>
<p>Session Type: Case Listing</p>
<p>SUGGESTED CITATION<br>
Software: Surveillance Research Program, National Cancer Institute SEER<em>Stat software (www.seer.cancer.gov/seerstat) version 8.4.4. Data: Surveillance, Epidemiology, and End Results (SEER) Program (www.seer.cancer.gov) SEER</em>Stat Database: Incidence - SEER Research Data, 8 Registries, Nov 2023 Sub (1975-2021) - Linked To County Attributes - Time Dependent (1990-2022) Income/Rurality, 1969-2022 Counties, National Cancer Institute, DCCPS, Surveillance Research Program, released April 2024, based on the November 2023 submission.</p>
<p>DATA<br>
Database: Incidence - SEER Research Data, 8 Registries, Nov 2023 Sub (1975-2021) - Linked To County Attributes - Time Dependent (1990-2022) Income/Rurality, 1969-2022 Counties</p>
<p>SELECTION<br>
Select Only: Malignant Behavior, Known Age</p>
<p>Case: {Site and Morphology.Site recode ICD-O-3/WHO 2008} = ‘Breast’ AND {Other.Type of Reporting Source} != ‘Autopsy only’, ‘Death certificate only’ AND {Cause of Death (COD) and Follow-up.Survival months flag} != ‘Not calculated because a Death Certificate Only or Autopsy Only case’ AND {Cause of Death (COD) and Follow-up.Survival months} != ‘Unknown’ AND {Cause of Death (COD) and Follow-up.SEER other cause of death classification} != ‘Dead (missing/unknown COD)’, ‘N/A not seq 0-59’ AND {Cause of Death (COD) and Follow-up.SEER cause-specific death classification} != ‘Dead (missing/unknown COD)’, ‘N/A not seq 0-59’ AND {Race, Sex, Year Dx.Sex} = ‘Female’ AND {Multiple Primary Fields.First malignant primary indicator} = ‘Yes’ AND {Race, Sex, Year Dx.Year of diagnosis} = ‘2010’, ‘2011’, ‘2012’, ‘2013’, ‘2014’, ‘2015’</p>
<p>OUTPUT<br>
Title: Breast Cancer survival data - Diagnoses 2010-2015</p>
<p>TABLE<br>
Column: Patient ID Age recode with <1 year olds Race recode (White, Black, Other) Year of diagnosis Laterality Histology recode - broad groupings SEER historic stage A (1973-2015) Radiation recode Chemotherapy recode (yes, no/unk) ER Status Recode Breast Cancer (1990+) PR Status Recode Breast Cancer (1990+) Derived HER2 Recode (2010+) Breast Subtype (2010+) SEER cause-specific death classification SEER other cause of death classification Survival months Vital status recode (study cutoff used) Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic) Year of follow-up recode Year of death recode Marital status at diagnosis Median household income inflation adj to 2022 Rural-Urban Continuum Code Race and origin (recommended by SEER) [Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic); PRCDA 2020]</p>
<p>USER DEFINITIONS<br>
Race and origin (recommended by SEER) [Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic); PRCDA 2020] Description: These are the groupings typcailly used by SEER for reporting by race and ethnicity for analyses starting in 1990 or later. For more details see:<br>
https://seer.cancer.gov/seerstat/variables/seer/race_ethnicity All races/ethnicities: {Race, Sex, Year Dx.Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)} = ‘Non-Hispanic White’, ‘Non-Hispanic Black’, ‘Non-Hispanic American Indian/Alaska Native’, ‘Non-Hispanic Asian or Pacific Islander’, ‘Hispanic (All Races)’, ‘Non-Hispanic Unknown Race’ Non-Hispanic White: {Race, Sex, Year Dx.Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)} = ‘Non-Hispanic White’ Non-Hispanic Black: {Race, Sex, Year Dx.Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)} = ‘Non-Hispanic Black’ Non-Hispanic American Indian/Alaska Native (PRCDA counties only): {Race, Sex, Year Dx.Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)} = ‘Non-Hispanic American Indian/Alaska Native’ AND {Race, Sex, Year Dx.PRCDA 2020} = ‘PRCDA’ Non-Hispanic Asian or Pacific Islander: {Race, Sex, Year Dx.Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)} = ‘Non-Hispanic Asian or Pacific Islander’ Hispanic (All Races): {Race, Sex, Year Dx.Race and origin recode (NHW, NHB, NHAIAN, NHAPI, Hispanic)} = ‘Hispanic (All Races)’</p>
</section>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const onCopySuccess = function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
}
const getTextToCopy = function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
text: getTextToCopy
});
clipboard.on('success', onCopySuccess);
if (window.document.getElementById('quarto-embedded-source-code-modal')) {
// For code content inside modals, clipBoardJS needs to be initialized with a container option