kidney/report.html
2026-05-19 09:37:05 +02:00

2899 lines
No EOL
162 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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.7.34">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>foo</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 */
html { -webkit-text-size-adjust: 100%; }
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;
}
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="report_files/libs/clipboard/clipboard.min.js"></script>
<script src="report_files/libs/quarto-html/quarto.js" type="module"></script>
<script src="report_files/libs/quarto-html/tabsets/tabsets.js" type="module"></script>
<script src="report_files/libs/quarto-html/popper.min.js"></script>
<script src="report_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="report_files/libs/quarto-html/anchor.min.js"></script>
<link href="report_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="report_files/libs/quarto-html/quarto-syntax-highlighting-c8ad9e5dbd60b7b70b38521ab19b7da4.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="report_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="report_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="report_files/libs/bootstrap/bootstrap-0e7144b51b1311dce330ab5b48d20e8e.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent quarto-light">
<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">foo</h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<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">library</span>(tidyverse)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr)</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(survival)</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(emmeans)</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(foreign)</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(gtsummary)</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="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>dat <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"./unos.txt"</span>, <span class="at">sep =</span> <span class="st">"</span><span class="sc">\t</span><span class="st">"</span>)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(dat)</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> hlamat age age.1 cold_isc death year sex txtype fu
1 2 25 15 6 0 2002 0 1 0
2 1 42 10 11 1 1999 0 1 0
3 1 9 14 8 0 2002 1 1 0
4 0 35 12 26 0 2002 1 1 0
5 2 17 12 28 1 1997 1 1 0
6 3 44 13 1 0 2002 1 0 0</code></pre>
</div>
<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><span class="fu">names</span>(dat) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"hla.match"</span>, <span class="st">"age.donor"</span>, <span class="st">"age.rec"</span>, <span class="st">"cold.isc"</span>, <span class="st">"death"</span>,</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="st">"year"</span>, <span class="st">"sex"</span>, <span class="st">"tx.type"</span>, <span class="st">"follow.up"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Complete case</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">nrow</span>(dat)</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] 9775</code></pre>
</div>
</div>
<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><span class="fu">sapply</span>(<span class="fu">names</span>(dat), <span class="cf">function</span>(col) {</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">is.na</span>(dat[, col]) <span class="sc">|&gt;</span> <span class="fu">sum</span>()</span>
<span id="cb7-3"><a href="#cb7-3" 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 class="cell-output cell-output-stdout">
<pre><code>hla.match age.donor age.rec cold.isc death year sex tx.type
234 113 9 2250 0 0 0 0
follow.up
0 </code></pre>
</div>
</div>
<section id="exercise" class="level1" data-number="1">
<h1 data-number="1"><span class="header-section-number">1</span> Exercise</h1>
<section id="exercise-1" class="level2" data-number="1.1">
<h2 data-number="1.1" class="anchored" data-anchor-id="exercise-1"><span class="header-section-number">1.1</span> Exercise 1</h2>
<blockquote class="blockquote">
<p>Illustrate in a table the characteristics of the population (age, sex, race, donor, . . . ).</p>
</blockquote>
<div class="cell">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">hist</span>(dat<span class="sc">$</span>age.donor)</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="report_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<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">hist</span>(dat<span class="sc">$</span>age.rec)</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="report_files/figure-html/unnamed-chunk-5-2.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">hist</span>(dat<span class="sc">$</span>cold.isc)</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="report_files/figure-html/unnamed-chunk-5-3.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</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">hist</span>(dat<span class="sc">$</span>year)</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="report_files/figure-html/unnamed-chunk-5-4.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">hist</span>(dat<span class="sc">$</span>follow.up)</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="report_files/figure-html/unnamed-chunk-5-5.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</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">unique</span>(dat<span class="sc">$</span>hla.match)</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] 2 1 0 3 4 NA 5 6</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">unique</span>(dat<span class="sc">$</span>year)</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] 2002 1999 1997 2001 1994 1995 1996 1993 1990 1991 1992 2000 1998</code></pre>
</div>
</div>
<p>Change the order!!</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>dat.table1 <span class="ot">&lt;-</span> dat <span class="sc">|&gt;</span> </span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> <span class="at">sex =</span> <span class="fu">factor</span>(sex, <span class="at">levels =</span> <span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">1</span>), <span class="at">labels =</span> <span class="fu">c</span>(<span class="st">"Female"</span>,<span class="st">"Male"</span>)),</span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> <span class="at">tx.type =</span> <span class="fu">factor</span>(tx.type, <span class="at">levels =</span> <span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">1</span>), <span class="at">labels =</span> <span class="fu">c</span>(<span class="st">"Cadaveric"</span>,<span class="st">"Living"</span>)),</span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a> <span class="at">hla.match =</span> <span class="fu">factor</span>(hla.match),</span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a> <span class="at">year =</span> <span class="fu">factor</span>(year)</span>
<span id="cb18-7"><a href="#cb18-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>
<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>table1 <span class="ot">&lt;-</span> dat.table1 <span class="sc">|&gt;</span> </span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(hla.match, age.donor, age.rec, cold.isc, year, sex, tx.type) <span class="sc">|&gt;</span> </span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">tbl_summary</span>(</span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a> <span class="at">statistic =</span> <span class="fu">list</span>(</span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">all_continuous</span>() <span class="sc">~</span> <span class="st">"{median} ({p25}, {p75})"</span></span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="fu">list</span>(</span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a> hla.match <span class="sc">~</span> <span class="st">"HLA matches, n(%)"</span>,</span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a> age.donor <span class="sc">~</span> <span class="st">"Donor age, median (IQR)"</span>,</span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a> age.rec <span class="sc">~</span> <span class="st">"Recipient age, median (IQR)"</span>,</span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true" tabindex="-1"></a> cold.isc <span class="sc">~</span> <span class="st">"Cold ischemic time (hours), median (IQR), "</span>,</span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true" tabindex="-1"></a> year <span class="sc">~</span> <span class="st">"Year of transplant"</span>,</span>
<span id="cb19-13"><a href="#cb19-13" aria-hidden="true" tabindex="-1"></a> sex <span class="sc">~</span> <span class="st">"Sex, n(%)"</span>,</span>
<span id="cb19-14"><a href="#cb19-14" aria-hidden="true" tabindex="-1"></a> tx.type <span class="sc">~</span> <span class="st">"Transplant type, n(%)"</span></span>
<span id="cb19-15"><a href="#cb19-15" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb19-16"><a href="#cb19-16" aria-hidden="true" tabindex="-1"></a> <span class="at">missing =</span> <span class="st">"ifany"</span></span>
<span id="cb19-17"><a href="#cb19-17" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">|&gt;</span> </span>
<span id="cb19-18"><a href="#cb19-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">modify_footnote</span>(<span class="fu">all_stat_cols</span>() <span class="sc">~</span> <span class="cn">NA</span>)</span>
<span id="cb19-19"><a href="#cb19-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-20"><a href="#cb19-20" aria-hidden="true" tabindex="-1"></a>table1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div id="zdtwyridgr" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#zdtwyridgr table {
font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
#zdtwyridgr thead, #zdtwyridgr tbody, #zdtwyridgr tfoot, #zdtwyridgr tr, #zdtwyridgr td, #zdtwyridgr th {
border-style: none;
}
#zdtwyridgr p {
margin: 0;
padding: 0;
}
#zdtwyridgr .gt_table {
display: table;
border-collapse: collapse;
line-height: normal;
margin-left: auto;
margin-right: auto;
color: #333333;
font-size: 16px;
font-weight: normal;
font-style: normal;
background-color: #FFFFFF;
width: auto;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #A8A8A8;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #A8A8A8;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
}
#zdtwyridgr .gt_caption {
padding-top: 4px;
padding-bottom: 4px;
}
#zdtwyridgr .gt_title {
color: #333333;
font-size: 125%;
font-weight: initial;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 5px;
padding-right: 5px;
border-bottom-color: #FFFFFF;
border-bottom-width: 0;
}
#zdtwyridgr .gt_subtitle {
color: #333333;
font-size: 85%;
font-weight: initial;
padding-top: 3px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
border-top-color: #FFFFFF;
border-top-width: 0;
}
#zdtwyridgr .gt_heading {
background-color: #FFFFFF;
text-align: center;
border-bottom-color: #FFFFFF;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
}
#zdtwyridgr .gt_bottom_border {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#zdtwyridgr .gt_col_headings {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
}
#zdtwyridgr .gt_col_heading {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: normal;
text-transform: inherit;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: bottom;
padding-top: 5px;
padding-bottom: 6px;
padding-left: 5px;
padding-right: 5px;
overflow-x: hidden;
}
#zdtwyridgr .gt_column_spanner_outer {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: normal;
text-transform: inherit;
padding-top: 0;
padding-bottom: 0;
padding-left: 4px;
padding-right: 4px;
}
#zdtwyridgr .gt_column_spanner_outer:first-child {
padding-left: 0;
}
#zdtwyridgr .gt_column_spanner_outer:last-child {
padding-right: 0;
}
#zdtwyridgr .gt_column_spanner {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
vertical-align: bottom;
padding-top: 5px;
padding-bottom: 5px;
overflow-x: hidden;
display: inline-block;
width: 100%;
}
#zdtwyridgr .gt_spanner_row {
border-bottom-style: hidden;
}
#zdtwyridgr .gt_group_heading {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
text-transform: inherit;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: middle;
text-align: left;
}
#zdtwyridgr .gt_empty_group_heading {
padding: 0.5px;
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
vertical-align: middle;
}
#zdtwyridgr .gt_from_md > :first-child {
margin-top: 0;
}
#zdtwyridgr .gt_from_md > :last-child {
margin-bottom: 0;
}
#zdtwyridgr .gt_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
margin: 10px;
border-top-style: solid;
border-top-width: 1px;
border-top-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: middle;
overflow-x: hidden;
}
#zdtwyridgr .gt_stub {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
text-transform: inherit;
border-right-style: solid;
border-right-width: 2px;
border-right-color: #D3D3D3;
padding-left: 5px;
padding-right: 5px;
}
#zdtwyridgr .gt_stub_row_group {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
text-transform: inherit;
border-right-style: solid;
border-right-width: 2px;
border-right-color: #D3D3D3;
padding-left: 5px;
padding-right: 5px;
vertical-align: top;
}
#zdtwyridgr .gt_row_group_first td {
border-top-width: 2px;
}
#zdtwyridgr .gt_row_group_first th {
border-top-width: 2px;
}
#zdtwyridgr .gt_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
}
#zdtwyridgr .gt_first_summary_row {
border-top-style: solid;
border-top-color: #D3D3D3;
}
#zdtwyridgr .gt_first_summary_row.thick {
border-top-width: 2px;
}
#zdtwyridgr .gt_last_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#zdtwyridgr .gt_grand_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
}
#zdtwyridgr .gt_first_grand_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
border-top-style: double;
border-top-width: 6px;
border-top-color: #D3D3D3;
}
#zdtwyridgr .gt_last_grand_summary_row_top {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
border-bottom-style: double;
border-bottom-width: 6px;
border-bottom-color: #D3D3D3;
}
#zdtwyridgr .gt_striped {
background-color: rgba(128, 128, 128, 0.05);
}
#zdtwyridgr .gt_table_body {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#zdtwyridgr .gt_footnotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
}
#zdtwyridgr .gt_footnote {
margin: 0px;
font-size: 90%;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 5px;
padding-right: 5px;
}
#zdtwyridgr .gt_sourcenotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
}
#zdtwyridgr .gt_sourcenote {
font-size: 90%;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 5px;
padding-right: 5px;
}
#zdtwyridgr .gt_left {
text-align: left;
}
#zdtwyridgr .gt_center {
text-align: center;
}
#zdtwyridgr .gt_right {
text-align: right;
font-variant-numeric: tabular-nums;
}
#zdtwyridgr .gt_font_normal {
font-weight: normal;
}
#zdtwyridgr .gt_font_bold {
font-weight: bold;
}
#zdtwyridgr .gt_font_italic {
font-style: italic;
}
#zdtwyridgr .gt_super {
font-size: 65%;
}
#zdtwyridgr .gt_footnote_marks {
font-size: 75%;
vertical-align: 0.4em;
position: initial;
}
#zdtwyridgr .gt_asterisk {
font-size: 100%;
vertical-align: 0;
}
#zdtwyridgr .gt_indent_1 {
text-indent: 5px;
}
#zdtwyridgr .gt_indent_2 {
text-indent: 10px;
}
#zdtwyridgr .gt_indent_3 {
text-indent: 15px;
}
#zdtwyridgr .gt_indent_4 {
text-indent: 20px;
}
#zdtwyridgr .gt_indent_5 {
text-indent: 25px;
}
#zdtwyridgr .katex-display {
display: inline-flex !important;
margin-bottom: 0.75em !important;
}
#zdtwyridgr div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
height: 0px !important;
}
</style>
<table class="gt_table caption-top table table-sm table-striped small" data-quarto-postprocess="true" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="gt_col_headings header">
<th id="label" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col"><strong>Characteristic</strong></th>
<th id="stat_0" class="gt_col_heading gt_columns_bottom_border gt_center" data-quarto-table-cell-role="th" scope="col"><strong>N = 9,775</strong></th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="label">HLA matches, n(%)</td>
<td class="gt_row gt_center" headers="stat_0"><br>
</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;0</td>
<td class="gt_row gt_center" headers="stat_0">784 (8.2%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1</td>
<td class="gt_row gt_center" headers="stat_0">1,504 (16%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;2</td>
<td class="gt_row gt_center" headers="stat_0">1,553 (16%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;3</td>
<td class="gt_row gt_center" headers="stat_0">3,778 (40%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;4</td>
<td class="gt_row gt_center" headers="stat_0">1,278 (13%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;5</td>
<td class="gt_row gt_center" headers="stat_0">365 (3.8%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;6</td>
<td class="gt_row gt_center" headers="stat_0">279 (2.9%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Unknown</td>
<td class="gt_row gt_center" headers="stat_0">234</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Donor age, median (IQR)</td>
<td class="gt_row gt_center" headers="stat_0">33 (21, 41)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Unknown</td>
<td class="gt_row gt_center" headers="stat_0">113</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Recipient age, median (IQR)</td>
<td class="gt_row gt_center" headers="stat_0">13 (8, 16)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Unknown</td>
<td class="gt_row gt_center" headers="stat_0">9</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Cold ischemic time (hours), median (IQR),</td>
<td class="gt_row gt_center" headers="stat_0">7 (1, 19)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Unknown</td>
<td class="gt_row gt_center" headers="stat_0">2,250</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Year of transplant</td>
<td class="gt_row gt_center" headers="stat_0"><br>
</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1990</td>
<td class="gt_row gt_center" headers="stat_0">728 (7.4%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1991</td>
<td class="gt_row gt_center" headers="stat_0">734 (7.5%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1992</td>
<td class="gt_row gt_center" headers="stat_0">666 (6.8%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1993</td>
<td class="gt_row gt_center" headers="stat_0">736 (7.5%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1994</td>
<td class="gt_row gt_center" headers="stat_0">787 (8.1%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1995</td>
<td class="gt_row gt_center" headers="stat_0">813 (8.3%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1996</td>
<td class="gt_row gt_center" headers="stat_0">789 (8.1%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1997</td>
<td class="gt_row gt_center" headers="stat_0">745 (7.6%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1998</td>
<td class="gt_row gt_center" headers="stat_0">740 (7.6%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1999</td>
<td class="gt_row gt_center" headers="stat_0">842 (8.6%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;2000</td>
<td class="gt_row gt_center" headers="stat_0">706 (7.2%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;2001</td>
<td class="gt_row gt_center" headers="stat_0">834 (8.5%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;2002</td>
<td class="gt_row gt_center" headers="stat_0">655 (6.7%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Sex, n(%)</td>
<td class="gt_row gt_center" headers="stat_0"><br>
</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Female</td>
<td class="gt_row gt_center" headers="stat_0">4,014 (41%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Male</td>
<td class="gt_row gt_center" headers="stat_0">5,761 (59%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">Transplant type, n(%)</td>
<td class="gt_row gt_center" headers="stat_0"><br>
</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Cadaveric</td>
<td class="gt_row gt_center" headers="stat_0">5,148 (53%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Living</td>
<td class="gt_row gt_center" headers="stat_0">4,627 (47%)</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>table.split <span class="ot">&lt;-</span> dat.table1 <span class="sc">|&gt;</span> </span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(hla.match, age.donor, age.rec, cold.isc, year, sex, tx.type) <span class="sc">|&gt;</span> </span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">tbl_summary</span>(</span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> <span class="at">by =</span> tx.type,</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a> <span class="at">statistic =</span> <span class="fu">list</span>(</span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">all_continuous</span>() <span class="sc">~</span> <span class="st">"{median} ({p25}, {p75})"</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="fu">list</span>(</span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a> hla.match <span class="sc">~</span> <span class="st">"HLA matches, n(%)"</span>,</span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a> age.donor <span class="sc">~</span> <span class="st">"Donor age, median (IQR)"</span>,</span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a> age.rec <span class="sc">~</span> <span class="st">"Recipient age, median (IQR)"</span>,</span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a> cold.isc <span class="sc">~</span> <span class="st">"Cold ischemic time (hours), median (IQR), "</span>,</span>
<span id="cb20-13"><a href="#cb20-13" aria-hidden="true" tabindex="-1"></a> year <span class="sc">~</span> <span class="st">"Year of transplant"</span>,</span>
<span id="cb20-14"><a href="#cb20-14" aria-hidden="true" tabindex="-1"></a> sex <span class="sc">~</span> <span class="st">"Sex, n(%)"</span></span>
<span id="cb20-15"><a href="#cb20-15" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb20-16"><a href="#cb20-16" aria-hidden="true" tabindex="-1"></a> <span class="at">missing =</span> <span class="st">"ifany"</span></span>
<span id="cb20-17"><a href="#cb20-17" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">|&gt;</span> </span>
<span id="cb20-18"><a href="#cb20-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">add_overall</span>() <span class="sc">|&gt;</span> </span>
<span id="cb20-19"><a href="#cb20-19" aria-hidden="true" tabindex="-1"></a> <span class="fu">modify_footnote</span>(<span class="fu">all_stat_cols</span>() <span class="sc">~</span> <span class="cn">NA</span>)</span>
<span id="cb20-20"><a href="#cb20-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-21"><a href="#cb20-21" aria-hidden="true" tabindex="-1"></a>table.split</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div id="qcjeqgjfum" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#qcjeqgjfum table {
font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
#qcjeqgjfum thead, #qcjeqgjfum tbody, #qcjeqgjfum tfoot, #qcjeqgjfum tr, #qcjeqgjfum td, #qcjeqgjfum th {
border-style: none;
}
#qcjeqgjfum p {
margin: 0;
padding: 0;
}
#qcjeqgjfum .gt_table {
display: table;
border-collapse: collapse;
line-height: normal;
margin-left: auto;
margin-right: auto;
color: #333333;
font-size: 16px;
font-weight: normal;
font-style: normal;
background-color: #FFFFFF;
width: auto;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #A8A8A8;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #A8A8A8;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
}
#qcjeqgjfum .gt_caption {
padding-top: 4px;
padding-bottom: 4px;
}
#qcjeqgjfum .gt_title {
color: #333333;
font-size: 125%;
font-weight: initial;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 5px;
padding-right: 5px;
border-bottom-color: #FFFFFF;
border-bottom-width: 0;
}
#qcjeqgjfum .gt_subtitle {
color: #333333;
font-size: 85%;
font-weight: initial;
padding-top: 3px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
border-top-color: #FFFFFF;
border-top-width: 0;
}
#qcjeqgjfum .gt_heading {
background-color: #FFFFFF;
text-align: center;
border-bottom-color: #FFFFFF;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
}
#qcjeqgjfum .gt_bottom_border {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#qcjeqgjfum .gt_col_headings {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
}
#qcjeqgjfum .gt_col_heading {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: normal;
text-transform: inherit;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: bottom;
padding-top: 5px;
padding-bottom: 6px;
padding-left: 5px;
padding-right: 5px;
overflow-x: hidden;
}
#qcjeqgjfum .gt_column_spanner_outer {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: normal;
text-transform: inherit;
padding-top: 0;
padding-bottom: 0;
padding-left: 4px;
padding-right: 4px;
}
#qcjeqgjfum .gt_column_spanner_outer:first-child {
padding-left: 0;
}
#qcjeqgjfum .gt_column_spanner_outer:last-child {
padding-right: 0;
}
#qcjeqgjfum .gt_column_spanner {
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
vertical-align: bottom;
padding-top: 5px;
padding-bottom: 5px;
overflow-x: hidden;
display: inline-block;
width: 100%;
}
#qcjeqgjfum .gt_spanner_row {
border-bottom-style: hidden;
}
#qcjeqgjfum .gt_group_heading {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
text-transform: inherit;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: middle;
text-align: left;
}
#qcjeqgjfum .gt_empty_group_heading {
padding: 0.5px;
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
vertical-align: middle;
}
#qcjeqgjfum .gt_from_md > :first-child {
margin-top: 0;
}
#qcjeqgjfum .gt_from_md > :last-child {
margin-bottom: 0;
}
#qcjeqgjfum .gt_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
margin: 10px;
border-top-style: solid;
border-top-width: 1px;
border-top-color: #D3D3D3;
border-left-style: none;
border-left-width: 1px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 1px;
border-right-color: #D3D3D3;
vertical-align: middle;
overflow-x: hidden;
}
#qcjeqgjfum .gt_stub {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
text-transform: inherit;
border-right-style: solid;
border-right-width: 2px;
border-right-color: #D3D3D3;
padding-left: 5px;
padding-right: 5px;
}
#qcjeqgjfum .gt_stub_row_group {
color: #333333;
background-color: #FFFFFF;
font-size: 100%;
font-weight: initial;
text-transform: inherit;
border-right-style: solid;
border-right-width: 2px;
border-right-color: #D3D3D3;
padding-left: 5px;
padding-right: 5px;
vertical-align: top;
}
#qcjeqgjfum .gt_row_group_first td {
border-top-width: 2px;
}
#qcjeqgjfum .gt_row_group_first th {
border-top-width: 2px;
}
#qcjeqgjfum .gt_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
}
#qcjeqgjfum .gt_first_summary_row {
border-top-style: solid;
border-top-color: #D3D3D3;
}
#qcjeqgjfum .gt_first_summary_row.thick {
border-top-width: 2px;
}
#qcjeqgjfum .gt_last_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#qcjeqgjfum .gt_grand_summary_row {
color: #333333;
background-color: #FFFFFF;
text-transform: inherit;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
}
#qcjeqgjfum .gt_first_grand_summary_row {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
border-top-style: double;
border-top-width: 6px;
border-top-color: #D3D3D3;
}
#qcjeqgjfum .gt_last_grand_summary_row_top {
padding-top: 8px;
padding-bottom: 8px;
padding-left: 5px;
padding-right: 5px;
border-bottom-style: double;
border-bottom-width: 6px;
border-bottom-color: #D3D3D3;
}
#qcjeqgjfum .gt_striped {
background-color: rgba(128, 128, 128, 0.05);
}
#qcjeqgjfum .gt_table_body {
border-top-style: solid;
border-top-width: 2px;
border-top-color: #D3D3D3;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
}
#qcjeqgjfum .gt_footnotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
}
#qcjeqgjfum .gt_footnote {
margin: 0px;
font-size: 90%;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 5px;
padding-right: 5px;
}
#qcjeqgjfum .gt_sourcenotes {
color: #333333;
background-color: #FFFFFF;
border-bottom-style: none;
border-bottom-width: 2px;
border-bottom-color: #D3D3D3;
border-left-style: none;
border-left-width: 2px;
border-left-color: #D3D3D3;
border-right-style: none;
border-right-width: 2px;
border-right-color: #D3D3D3;
}
#qcjeqgjfum .gt_sourcenote {
font-size: 90%;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 5px;
padding-right: 5px;
}
#qcjeqgjfum .gt_left {
text-align: left;
}
#qcjeqgjfum .gt_center {
text-align: center;
}
#qcjeqgjfum .gt_right {
text-align: right;
font-variant-numeric: tabular-nums;
}
#qcjeqgjfum .gt_font_normal {
font-weight: normal;
}
#qcjeqgjfum .gt_font_bold {
font-weight: bold;
}
#qcjeqgjfum .gt_font_italic {
font-style: italic;
}
#qcjeqgjfum .gt_super {
font-size: 65%;
}
#qcjeqgjfum .gt_footnote_marks {
font-size: 75%;
vertical-align: 0.4em;
position: initial;
}
#qcjeqgjfum .gt_asterisk {
font-size: 100%;
vertical-align: 0;
}
#qcjeqgjfum .gt_indent_1 {
text-indent: 5px;
}
#qcjeqgjfum .gt_indent_2 {
text-indent: 10px;
}
#qcjeqgjfum .gt_indent_3 {
text-indent: 15px;
}
#qcjeqgjfum .gt_indent_4 {
text-indent: 20px;
}
#qcjeqgjfum .gt_indent_5 {
text-indent: 25px;
}
#qcjeqgjfum .katex-display {
display: inline-flex !important;
margin-bottom: 0.75em !important;
}
#qcjeqgjfum div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
height: 0px !important;
}
</style>
<table class="gt_table caption-top table table-sm table-striped small" data-quarto-postprocess="true" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<colgroup>
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
</colgroup>
<thead>
<tr class="gt_col_headings header">
<th id="label" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col"><strong>Characteristic</strong></th>
<th id="stat_0" class="gt_col_heading gt_columns_bottom_border gt_center" data-quarto-table-cell-role="th" scope="col"><strong>Overall</strong><br>
N = 9,775</th>
<th id="stat_1" class="gt_col_heading gt_columns_bottom_border gt_center" data-quarto-table-cell-role="th" scope="col"><strong>Cadaveric</strong><br>
N = 5,148</th>
<th id="stat_2" class="gt_col_heading gt_columns_bottom_border gt_center" data-quarto-table-cell-role="th" scope="col"><strong>Living</strong><br>
N = 4,627</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="label">HLA matches, n(%)</td>
<td class="gt_row gt_center" headers="stat_0"><br>
</td>
<td class="gt_row gt_center" headers="stat_1"><br>
</td>
<td class="gt_row gt_center" headers="stat_2"><br>
</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;0</td>
<td class="gt_row gt_center" headers="stat_0">784 (8.2%)</td>
<td class="gt_row gt_center" headers="stat_1">125 (2.5%)</td>
<td class="gt_row gt_center" headers="stat_2">659 (14%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1</td>
<td class="gt_row gt_center" headers="stat_0">1,504 (16%)</td>
<td class="gt_row gt_center" headers="stat_1">160 (3.2%)</td>
<td class="gt_row gt_center" headers="stat_2">1,344 (29%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;2</td>
<td class="gt_row gt_center" headers="stat_0">1,553 (16%)</td>
<td class="gt_row gt_center" headers="stat_1">228 (4.6%)</td>
<td class="gt_row gt_center" headers="stat_2">1,325 (29%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;3</td>
<td class="gt_row gt_center" headers="stat_0">3,778 (40%)</td>
<td class="gt_row gt_center" headers="stat_1">3,039 (61%)</td>
<td class="gt_row gt_center" headers="stat_2">739 (16%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;4</td>
<td class="gt_row gt_center" headers="stat_0">1,278 (13%)</td>
<td class="gt_row gt_center" headers="stat_1">1,007 (20%)</td>
<td class="gt_row gt_center" headers="stat_2">271 (5.9%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;5</td>
<td class="gt_row gt_center" headers="stat_0">365 (3.8%)</td>
<td class="gt_row gt_center" headers="stat_1">241 (4.9%)</td>
<td class="gt_row gt_center" headers="stat_2">124 (2.7%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;6</td>
<td class="gt_row gt_center" headers="stat_0">279 (2.9%)</td>
<td class="gt_row gt_center" headers="stat_1">153 (3.1%)</td>
<td class="gt_row gt_center" headers="stat_2">126 (2.7%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Unknown</td>
<td class="gt_row gt_center" headers="stat_0">234</td>
<td class="gt_row gt_center" headers="stat_1">195</td>
<td class="gt_row gt_center" headers="stat_2">39</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Donor age, median (IQR)</td>
<td class="gt_row gt_center" headers="stat_0">33 (21, 41)</td>
<td class="gt_row gt_center" headers="stat_1">37 (31, 42)</td>
<td class="gt_row gt_center" headers="stat_2">22 (15, 37)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Unknown</td>
<td class="gt_row gt_center" headers="stat_0">113</td>
<td class="gt_row gt_center" headers="stat_1">112</td>
<td class="gt_row gt_center" headers="stat_2">1</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Recipient age, median (IQR)</td>
<td class="gt_row gt_center" headers="stat_0">13 (8, 16)</td>
<td class="gt_row gt_center" headers="stat_1">13 (7, 16)</td>
<td class="gt_row gt_center" headers="stat_2">14 (9, 16)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Unknown</td>
<td class="gt_row gt_center" headers="stat_0">9</td>
<td class="gt_row gt_center" headers="stat_1">7</td>
<td class="gt_row gt_center" headers="stat_2">2</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Cold ischemic time (hours), median (IQR),</td>
<td class="gt_row gt_center" headers="stat_0">7 (1, 19)</td>
<td class="gt_row gt_center" headers="stat_1">1 (0, 1)</td>
<td class="gt_row gt_center" headers="stat_2">19 (13, 25)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Unknown</td>
<td class="gt_row gt_center" headers="stat_0">2,250</td>
<td class="gt_row gt_center" headers="stat_1">1,490</td>
<td class="gt_row gt_center" headers="stat_2">760</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Year of transplant</td>
<td class="gt_row gt_center" headers="stat_0"><br>
</td>
<td class="gt_row gt_center" headers="stat_1"><br>
</td>
<td class="gt_row gt_center" headers="stat_2"><br>
</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1990</td>
<td class="gt_row gt_center" headers="stat_0">728 (7.4%)</td>
<td class="gt_row gt_center" headers="stat_1">318 (6.2%)</td>
<td class="gt_row gt_center" headers="stat_2">410 (8.9%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1991</td>
<td class="gt_row gt_center" headers="stat_0">734 (7.5%)</td>
<td class="gt_row gt_center" headers="stat_1">387 (7.5%)</td>
<td class="gt_row gt_center" headers="stat_2">347 (7.5%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1992</td>
<td class="gt_row gt_center" headers="stat_0">666 (6.8%)</td>
<td class="gt_row gt_center" headers="stat_1">345 (6.7%)</td>
<td class="gt_row gt_center" headers="stat_2">321 (6.9%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1993</td>
<td class="gt_row gt_center" headers="stat_0">736 (7.5%)</td>
<td class="gt_row gt_center" headers="stat_1">403 (7.8%)</td>
<td class="gt_row gt_center" headers="stat_2">333 (7.2%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1994</td>
<td class="gt_row gt_center" headers="stat_0">787 (8.1%)</td>
<td class="gt_row gt_center" headers="stat_1">355 (6.9%)</td>
<td class="gt_row gt_center" headers="stat_2">432 (9.3%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1995</td>
<td class="gt_row gt_center" headers="stat_0">813 (8.3%)</td>
<td class="gt_row gt_center" headers="stat_1">427 (8.3%)</td>
<td class="gt_row gt_center" headers="stat_2">386 (8.3%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1996</td>
<td class="gt_row gt_center" headers="stat_0">789 (8.1%)</td>
<td class="gt_row gt_center" headers="stat_1">416 (8.1%)</td>
<td class="gt_row gt_center" headers="stat_2">373 (8.1%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1997</td>
<td class="gt_row gt_center" headers="stat_0">745 (7.6%)</td>
<td class="gt_row gt_center" headers="stat_1">408 (7.9%)</td>
<td class="gt_row gt_center" headers="stat_2">337 (7.3%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1998</td>
<td class="gt_row gt_center" headers="stat_0">740 (7.6%)</td>
<td class="gt_row gt_center" headers="stat_1">412 (8.0%)</td>
<td class="gt_row gt_center" headers="stat_2">328 (7.1%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;1999</td>
<td class="gt_row gt_center" headers="stat_0">842 (8.6%)</td>
<td class="gt_row gt_center" headers="stat_1">436 (8.5%)</td>
<td class="gt_row gt_center" headers="stat_2">406 (8.8%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;2000</td>
<td class="gt_row gt_center" headers="stat_0">706 (7.2%)</td>
<td class="gt_row gt_center" headers="stat_1">392 (7.6%)</td>
<td class="gt_row gt_center" headers="stat_2">314 (6.8%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;2001</td>
<td class="gt_row gt_center" headers="stat_0">834 (8.5%)</td>
<td class="gt_row gt_center" headers="stat_1">483 (9.4%)</td>
<td class="gt_row gt_center" headers="stat_2">351 (7.6%)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;2002</td>
<td class="gt_row gt_center" headers="stat_0">655 (6.7%)</td>
<td class="gt_row gt_center" headers="stat_1">366 (7.1%)</td>
<td class="gt_row gt_center" headers="stat_2">289 (6.2%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">Sex, n(%)</td>
<td class="gt_row gt_center" headers="stat_0"><br>
</td>
<td class="gt_row gt_center" headers="stat_1"><br>
</td>
<td class="gt_row gt_center" headers="stat_2"><br>
</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Female</td>
<td class="gt_row gt_center" headers="stat_0">4,014 (41%)</td>
<td class="gt_row gt_center" headers="stat_1">2,105 (41%)</td>
<td class="gt_row gt_center" headers="stat_2">1,909 (41%)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label">&nbsp;&nbsp;&nbsp;&nbsp;Male</td>
<td class="gt_row gt_center" headers="stat_0">5,761 (59%)</td>
<td class="gt_row gt_center" headers="stat_1">3,043 (59%)</td>
<td class="gt_row gt_center" headers="stat_2">2,718 (59%)</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Calculate median follow-up (reverse Kaplan-Meier method), with 95% CI</p>
<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>rev_km <span class="ot">&lt;-</span> <span class="fu">survfit</span>(<span class="fu">Surv</span>(follow.up, death <span class="sc">==</span> <span class="dv">0</span>) <span class="sc">~</span> <span class="dv">1</span>, <span class="at">data =</span> dat)</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(rev_km)<span class="sc">$</span>table</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> records n.max n.start events rmean se(rmean)
9.775000e+03 9.775000e+03 9.775000e+03 9.310000e+03 4.055027e+00 3.202711e-02
median 0.95LCL 0.95UCL
3.380822e+00 3.227397e+00 3.567123e+00 </code></pre>
</div>
<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>median_followup <span class="ot">&lt;-</span> <span class="fu">summary</span>(rev_km)<span class="sc">$</span>table[<span class="st">"median"</span>]</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>confidence_interval <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">summary</span>(rev_km)<span class="sc">$</span>table[<span class="st">"0.95LCL"</span>], <span class="fu">summary</span>(rev_km)<span class="sc">$</span>table[<span class="st">"0.95UCL"</span>])</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>median_followup</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> median
3.380822 </code></pre>
</div>
<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>confidence_interval</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> 0.95LCL 0.95UCL
3.227397 3.567123 </code></pre>
</div>
</div>
<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>g <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(dat)</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="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>g <span class="sc">+</span> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">x =</span> follow.up, <span class="at">y =</span> death))</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="report_files/figure-html/unnamed-chunk-11-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<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>g <span class="sc">+</span> <span class="fu">geom_density</span>(<span class="fu">aes</span>(<span class="at">x =</span> follow.up))</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="report_files/figure-html/unnamed-chunk-11-2.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<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>g <span class="sc">+</span> <span class="fu">geom_density</span>(<span class="fu">aes</span>(<span class="at">x =</span> age.donor))</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: Removed 113 rows containing non-finite outside the scale range
(`stat_density()`).</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="report_files/figure-html/unnamed-chunk-11-3.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<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>g <span class="sc">+</span> <span class="fu">geom_bar</span>(<span class="fu">aes</span>(<span class="at">x =</span> age.rec))</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: Removed 9 rows containing non-finite outside the scale range
(`stat_count()`).</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="report_files/figure-html/unnamed-chunk-11-4.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<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>g <span class="sc">+</span> <span class="fu">geom_boxplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> age.rec, <span class="at">y =</span> age.donor, <span class="at">group =</span> age.donor))</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: Removed 113 rows containing missing values or values outside the scale range
(`stat_boxplot()`).</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Removed 7 rows containing non-finite outside the scale range
(`stat_boxplot()`).</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="report_files/figure-html/unnamed-chunk-11-5.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a><span class="co"># dat$age.1 |&gt; table()</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="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>g <span class="sc">+</span> <span class="fu">geom_boxplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> year, <span class="at">y =</span> follow.up, <span class="at">group =</span> year))</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="report_files/figure-html/unnamed-chunk-12-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="exercise-2" class="level2" data-number="1.2">
<h2 data-number="1.2" class="anchored" data-anchor-id="exercise-2"><span class="header-section-number">1.2</span> Exercise 2</h2>
<p>Plot the Kaplan-Meier overall survival curve for pediatric kid- ney transplant recipients for the first 12 years after transplantation.</p>
<p>!!!!!!!! just set xlim to 12, do not remove those individuals !!!!!!!</p>
<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>km <span class="ot">&lt;-</span> <span class="fu">survfit</span>(<span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> <span class="dv">1</span>, <span class="at">data =</span> dat[dat<span class="sc">$</span>follow.up <span class="sc">&lt;=</span> <span class="dv">12</span>, ])</span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(km)</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="report_files/figure-html/unnamed-chunk-13-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="exercise-3" class="level2" data-number="1.3">
<h2 data-number="1.3" class="anchored" data-anchor-id="exercise-3"><span class="header-section-number">1.3</span> Exercise 3</h2>
<p>We are going to compare mortality rates (hazard functions) between children whose transplanted kidney was provided by a living donor (in general a family member) and those whose source was recently deceased (variable donor type: <code>txtype</code>). Use the life table method to calculate the death rates for the first 5 years for each group (take in the first year intervals of 4 months and then look at each year) and show the results in a table. Estimate the hazard ratio in each time interval as the ratio between the mortality rates in the two groups. What do you notice?</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a>dat<span class="fl">.5</span> <span class="ot">&lt;-</span> dat[dat<span class="sc">$</span>follow.up <span class="sc">&lt;=</span> <span class="dv">5</span>, ]</span>
<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(dat<span class="fl">.5</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> hla.match age.donor age.rec cold.isc death year sex tx.type follow.up
1 2 25 15 6 0 2002 0 1 0
2 1 42 10 11 1 1999 0 1 0
3 1 9 14 8 0 2002 1 1 0
4 0 35 12 26 0 2002 1 1 0
5 2 17 12 28 1 1997 1 1 0
6 3 44 13 1 0 2002 1 0 0</code></pre>
</div>
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a>classify_time_interval <span class="ot">=</span> <span class="cf">function</span>(fu) {</span>
<span id="cb42-2"><a href="#cb42-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (fu <span class="sc">&lt;=</span> <span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>) {</span>
<span id="cb42-3"><a href="#cb42-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>)</span>
<span id="cb42-4"><a href="#cb42-4" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> <span class="cf">if</span> (fu <span class="sc">&lt;=</span> <span class="dv">2</span><span class="sc">/</span><span class="dv">3</span>) {</span>
<span id="cb42-5"><a href="#cb42-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="dv">2</span><span class="sc">/</span><span class="dv">3</span>)</span>
<span id="cb42-6"><a href="#cb42-6" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> <span class="cf">if</span> (fu <span class="sc">&lt;=</span> <span class="dv">1</span>) {</span>
<span id="cb42-7"><a href="#cb42-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="dv">1</span>)</span>
<span id="cb42-8"><a href="#cb42-8" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb42-9"><a href="#cb42-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">ceiling</span>(fu)</span>
<span id="cb42-10"><a href="#cb42-10" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb42-11"><a href="#cb42-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-12"><a href="#cb42-12" aria-hidden="true" tabindex="-1"></a>dat<span class="fl">.5</span><span class="sc">$</span>fu.interval <span class="ot">&lt;-</span> <span class="fu">sapply</span>(dat<span class="fl">.5</span><span class="sc">$</span>follow.up, classify_time_interval)</span>
<span id="cb42-13"><a href="#cb42-13" aria-hidden="true" tabindex="-1"></a><span class="fu">table</span>(dat<span class="fl">.5</span><span class="sc">$</span>fu.interval)</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>
0.333333333333333 0.666666666666667 1 2
982 528 640 1226
3 4 5
1184 1093 950 </code></pre>
</div>
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(dat<span class="fl">.5</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> hla.match age.donor age.rec cold.isc death year sex tx.type follow.up
1 2 25 15 6 0 2002 0 1 0
2 1 42 10 11 1 1999 0 1 0
3 1 9 14 8 0 2002 1 1 0
4 0 35 12 26 0 2002 1 1 0
5 2 17 12 28 1 1997 1 1 0
6 3 44 13 1 0 2002 1 0 0
fu.interval
1 0.3333333
2 0.3333333
3 0.3333333
4 0.3333333
5 0.3333333
6 0.3333333</code></pre>
</div>
</div>
<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>dat.<span class="fl">5.</span>life <span class="ot">&lt;-</span> dat<span class="fl">.5</span> <span class="sc">|&gt;</span></span>
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(fu.interval) <span class="sc">|&gt;</span></span>
<span id="cb46-3"><a href="#cb46-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(</span>
<span id="cb46-4"><a href="#cb46-4" aria-hidden="true" tabindex="-1"></a> <span class="at">n.censored =</span> <span class="fu">sum</span>(death <span class="sc">==</span> <span class="dv">0</span>),</span>
<span id="cb46-5"><a href="#cb46-5" aria-hidden="true" tabindex="-1"></a> <span class="at">n.event =</span> <span class="fu">sum</span>(death),</span>
<span id="cb46-6"><a href="#cb46-6" aria-hidden="true" tabindex="-1"></a> <span class="at">n.at.risk =</span> <span class="fu">nrow</span>(dat),</span>
<span id="cb46-7"><a href="#cb46-7" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb46-8"><a href="#cb46-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb46-9"><a href="#cb46-9" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">2</span><span class="sc">:</span><span class="fu">nrow</span>(dat.<span class="fl">5.</span>life)) {</span>
<span id="cb46-10"><a href="#cb46-10" aria-hidden="true" tabindex="-1"></a> j <span class="ot">&lt;-</span> i <span class="sc">-</span> <span class="dv">1</span></span>
<span id="cb46-11"><a href="#cb46-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb46-12"><a href="#cb46-12" aria-hidden="true" tabindex="-1"></a> n.censored.pre <span class="ot">&lt;-</span> dat.<span class="fl">5.</span>life<span class="sc">$</span>n.censored[j]</span>
<span id="cb46-13"><a href="#cb46-13" aria-hidden="true" tabindex="-1"></a> n.event.pre <span class="ot">&lt;-</span> dat.<span class="fl">5.</span>life<span class="sc">$</span>n.event[j]</span>
<span id="cb46-14"><a href="#cb46-14" aria-hidden="true" tabindex="-1"></a> n.at.risk.pre <span class="ot">&lt;-</span> dat.<span class="fl">5.</span>life<span class="sc">$</span>n.at.risk[j]</span>
<span id="cb46-15"><a href="#cb46-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb46-16"><a href="#cb46-16" aria-hidden="true" tabindex="-1"></a> n.at.risk <span class="ot">&lt;-</span> n.at.risk.pre <span class="sc">-</span> n.event.pre <span class="sc">-</span> n.censored.pre</span>
<span id="cb46-17"><a href="#cb46-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb46-18"><a href="#cb46-18" aria-hidden="true" tabindex="-1"></a> dat.<span class="fl">5.</span>life<span class="sc">$</span>n.at.risk[i] <span class="ot">&lt;-</span> n.at.risk</span>
<span id="cb46-19"><a href="#cb46-19" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb46-20"><a href="#cb46-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb46-21"><a href="#cb46-21" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(<span class="fu">nrow</span>(dat))</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] 9775</code></pre>
</div>
<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>dat.<span class="fl">5.</span>life</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: 7 × 4
fu.interval n.censored n.event n.at.risk
&lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt;
1 0.333 830 152 9775
2 0.667 491 37 8793
3 1 613 27 8265
4 2 1164 62 7625
5 3 1143 41 6399
6 4 1053 40 5215
7 5 919 31 4122</code></pre>
</div>
</div>
<p>n.removed.acc</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb50"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb50-1"><a href="#cb50-1" aria-hidden="true" tabindex="-1"></a>dat.<span class="fl">5.</span>life <span class="ot">&lt;-</span> dat.<span class="fl">5.</span>life <span class="sc">|&gt;</span></span>
<span id="cb50-2"><a href="#cb50-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb50-3"><a href="#cb50-3" aria-hidden="true" tabindex="-1"></a> <span class="at">hazard.rate =</span> n.event <span class="sc">/</span> n.at.risk</span>
<span id="cb50-4"><a href="#cb50-4" 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>
<hr>
<div class="cell">
<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a>get_life_table <span class="ot">=</span> <span class="cf">function</span>(dat.sub, dat) {</span>
<span id="cb51-2"><a href="#cb51-2" aria-hidden="true" tabindex="-1"></a> dat.sub <span class="ot">&lt;-</span> dat.sub <span class="sc">|&gt;</span></span>
<span id="cb51-3"><a href="#cb51-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(fu.interval) <span class="sc">|&gt;</span></span>
<span id="cb51-4"><a href="#cb51-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(</span>
<span id="cb51-5"><a href="#cb51-5" aria-hidden="true" tabindex="-1"></a> <span class="at">n.censored =</span> <span class="fu">sum</span>(death <span class="sc">==</span> <span class="dv">0</span>),</span>
<span id="cb51-6"><a href="#cb51-6" aria-hidden="true" tabindex="-1"></a> <span class="at">n.event =</span> <span class="fu">sum</span>(death),</span>
<span id="cb51-7"><a href="#cb51-7" aria-hidden="true" tabindex="-1"></a> <span class="at">n.at.risk =</span> <span class="fu">nrow</span>(dat),</span>
<span id="cb51-8"><a href="#cb51-8" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb51-9"><a href="#cb51-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-10"><a href="#cb51-10" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">2</span><span class="sc">:</span><span class="fu">nrow</span>(dat.sub)) {</span>
<span id="cb51-11"><a href="#cb51-11" aria-hidden="true" tabindex="-1"></a> j <span class="ot">&lt;-</span> i <span class="sc">-</span> <span class="dv">1</span></span>
<span id="cb51-12"><a href="#cb51-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-13"><a href="#cb51-13" aria-hidden="true" tabindex="-1"></a> n.censored.pre <span class="ot">&lt;-</span> dat.sub<span class="sc">$</span>n.censored[j]</span>
<span id="cb51-14"><a href="#cb51-14" aria-hidden="true" tabindex="-1"></a> n.event.pre <span class="ot">&lt;-</span> dat.sub<span class="sc">$</span>n.event[j]</span>
<span id="cb51-15"><a href="#cb51-15" aria-hidden="true" tabindex="-1"></a> n.at.risk.pre <span class="ot">&lt;-</span> dat.sub<span class="sc">$</span>n.at.risk[j]</span>
<span id="cb51-16"><a href="#cb51-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-17"><a href="#cb51-17" aria-hidden="true" tabindex="-1"></a> n.at.risk <span class="ot">&lt;-</span> n.at.risk.pre <span class="sc">-</span> n.event.pre <span class="sc">-</span> n.censored.pre</span>
<span id="cb51-18"><a href="#cb51-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-19"><a href="#cb51-19" aria-hidden="true" tabindex="-1"></a> dat.sub<span class="sc">$</span>n.at.risk[i] <span class="ot">&lt;-</span> n.at.risk</span>
<span id="cb51-20"><a href="#cb51-20" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb51-21"><a href="#cb51-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-22"><a href="#cb51-22" aria-hidden="true" tabindex="-1"></a> dat.sub <span class="ot">&lt;-</span> dat.sub <span class="sc">|&gt;</span></span>
<span id="cb51-23"><a href="#cb51-23" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb51-24"><a href="#cb51-24" aria-hidden="true" tabindex="-1"></a> <span class="at">hazard.rate =</span> n.event <span class="sc">/</span> n.at.risk</span>
<span id="cb51-25"><a href="#cb51-25" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb51-26"><a href="#cb51-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-27"><a href="#cb51-27" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(dat.sub)</span>
<span id="cb51-28"><a href="#cb51-28" 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>
<div class="cell">
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a>dat.<span class="fl">5.</span>tx0 <span class="ot">=</span> dat<span class="fl">.5</span>[dat<span class="fl">.5</span><span class="sc">$</span>tx.type <span class="sc">==</span> <span class="dv">0</span>, ]</span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a>dat.<span class="fl">5.</span>tx1 <span class="ot">=</span> dat<span class="fl">.5</span>[dat<span class="fl">.5</span><span class="sc">$</span>tx.type <span class="sc">==</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>
<div class="cell">
<div class="sourceCode cell-code" id="cb53"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb53-1"><a href="#cb53-1" aria-hidden="true" tabindex="-1"></a>tx0.life <span class="ot">&lt;-</span> <span class="fu">get_life_table</span>(dat.<span class="fl">5.</span>tx0, dat[dat<span class="sc">$</span>tx.type <span class="sc">==</span> <span class="dv">0</span>, ])</span>
<span id="cb53-2"><a href="#cb53-2" aria-hidden="true" tabindex="-1"></a>tx0.life</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: 7 × 5
fu.interval n.censored n.event n.at.risk hazard.rate
&lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt;
1 0.333 463 49 5148 0.00952
2 0.667 253 13 4636 0.00280
3 1 340 11 4370 0.00252
4 2 591 24 4019 0.00597
5 3 568 17 3404 0.00499
6 4 521 16 2819 0.00568
7 5 501 11 2282 0.00482</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb55"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb55-1"><a href="#cb55-1" aria-hidden="true" tabindex="-1"></a>tx1.life <span class="ot">&lt;-</span> <span class="fu">get_life_table</span>(dat.<span class="fl">5.</span>tx1, dat[dat<span class="sc">$</span>tx.type <span class="sc">==</span> <span class="dv">1</span>, ])</span>
<span id="cb55-2"><a href="#cb55-2" aria-hidden="true" tabindex="-1"></a>tx1.life</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: 7 × 5
fu.interval n.censored n.event n.at.risk hazard.rate
&lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt;
1 0.333 367 103 4627 0.0223
2 0.667 238 24 4157 0.00577
3 1 273 16 3895 0.00411
4 2 573 38 3606 0.0105
5 3 575 24 2995 0.00801
6 4 532 24 2396 0.0100
7 5 418 20 1840 0.0109 </code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb57"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb57-1"><a href="#cb57-1" aria-hidden="true" tabindex="-1"></a>tx1.life<span class="sc">$</span>hazard.rate <span class="sc">/</span> tx0.life<span class="sc">$</span>hazard.rate</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] 2.338731 2.058881 1.631929 1.764675 1.604557 1.764816 2.254941</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb59"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb59-1"><a href="#cb59-1" aria-hidden="true" tabindex="-1"></a>hazard.df <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(</span>
<span id="cb59-2"><a href="#cb59-2" aria-hidden="true" tabindex="-1"></a> <span class="at">fu.interval =</span> tx1.life<span class="sc">$</span>fu.interval,</span>
<span id="cb59-3"><a href="#cb59-3" aria-hidden="true" tabindex="-1"></a> <span class="at">hazard.rate.0 =</span> tx0.life<span class="sc">$</span>hazard.rate,</span>
<span id="cb59-4"><a href="#cb59-4" aria-hidden="true" tabindex="-1"></a> <span class="at">hazard.rate.1 =</span> tx1.life<span class="sc">$</span>hazard.rate,</span>
<span id="cb59-5"><a href="#cb59-5" aria-hidden="true" tabindex="-1"></a> <span class="at">hazard.ratio =</span> tx1.life<span class="sc">$</span>hazard.rate <span class="sc">/</span> tx0.life<span class="sc">$</span>hazard.rate</span>
<span id="cb59-6"><a href="#cb59-6" aria-hidden="true" tabindex="-1"></a>) </span>
<span id="cb59-7"><a href="#cb59-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb59-8"><a href="#cb59-8" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(hazard.df, <span class="fu">aes</span>(<span class="at">x =</span> fu.interval)) <span class="sc">+</span></span>
<span id="cb59-9"><a href="#cb59-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>(<span class="fu">aes</span>(<span class="at">y =</span> hazard.rate<span class="fl">.0</span>), <span class="at">color =</span> <span class="st">"blue"</span>) <span class="sc">+</span> </span>
<span id="cb59-10"><a href="#cb59-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>(<span class="fu">aes</span>(<span class="at">y =</span> hazard.rate<span class="fl">.1</span>), <span class="at">color =</span> <span class="st">"orange"</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="report_files/figure-html/unnamed-chunk-22-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="sourceCode cell-code" id="cb60"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb60-1"><a href="#cb60-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(hazard.df, <span class="fu">aes</span>(<span class="at">x =</span> fu.interval)) <span class="sc">+</span></span>
<span id="cb60-2"><a href="#cb60-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>(<span class="fu">aes</span>(<span class="at">y =</span> hazard.ratio))</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="report_files/figure-html/unnamed-chunk-22-2.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>General Solution:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb61"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb61-1"><a href="#cb61-1" aria-hidden="true" tabindex="-1"></a>get.life.table <span class="ot">&lt;-</span> <span class="cf">function</span>(dat, time.intervals) {</span>
<span id="cb61-2"><a href="#cb61-2" aria-hidden="true" tabindex="-1"></a> n.pop <span class="ot">&lt;-</span> <span class="fu">nrow</span>(dat)</span>
<span id="cb61-3"><a href="#cb61-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb61-4"><a href="#cb61-4" aria-hidden="true" tabindex="-1"></a> dat <span class="sc">|&gt;</span></span>
<span id="cb61-5"><a href="#cb61-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">recode.dat</span>(time.intervals) <span class="sc">|&gt;</span></span>
<span id="cb61-6"><a href="#cb61-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(fu.interval) <span class="sc">|&gt;</span></span>
<span id="cb61-7"><a href="#cb61-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(</span>
<span id="cb61-8"><a href="#cb61-8" aria-hidden="true" tabindex="-1"></a> <span class="at">n.censored =</span> <span class="fu">sum</span>(.data<span class="sc">$</span>death <span class="sc">==</span> <span class="dv">0</span>),</span>
<span id="cb61-9"><a href="#cb61-9" aria-hidden="true" tabindex="-1"></a> <span class="at">n.event =</span> <span class="fu">sum</span>(.data<span class="sc">$</span>death),</span>
<span id="cb61-10"><a href="#cb61-10" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">|&gt;</span></span>
<span id="cb61-11"><a href="#cb61-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">ungroup</span>() <span class="sc">|&gt;</span></span>
<span id="cb61-12"><a href="#cb61-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">calculate.hazard</span>(n.pop)</span>
<span id="cb61-13"><a href="#cb61-13" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb61-14"><a href="#cb61-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb61-15"><a href="#cb61-15" aria-hidden="true" tabindex="-1"></a>get.life.table.by.groups <span class="ot">&lt;-</span> <span class="cf">function</span>(dat, time.intervals, grps) {</span>
<span id="cb61-16"><a href="#cb61-16" aria-hidden="true" tabindex="-1"></a> grps <span class="sc">|&gt;</span></span>
<span id="cb61-17"><a href="#cb61-17" aria-hidden="true" tabindex="-1"></a> <span class="fu">lapply</span>(<span class="cf">function</span>(grp) {</span>
<span id="cb61-18"><a href="#cb61-18" aria-hidden="true" tabindex="-1"></a> dat <span class="sc">|&gt;</span></span>
<span id="cb61-19"><a href="#cb61-19" aria-hidden="true" tabindex="-1"></a> <span class="fu">get.life.table.by.group</span>(time.intervals, grp) <span class="sc">|&gt;</span></span>
<span id="cb61-20"><a href="#cb61-20" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb61-21"><a href="#cb61-21" aria-hidden="true" tabindex="-1"></a> <span class="at">grp.name =</span> grp,</span>
<span id="cb61-22"><a href="#cb61-22" aria-hidden="true" tabindex="-1"></a> <span class="at">grp.value =</span> <span class="fu">pick</span>(<span class="dv">1</span>)[[<span class="dv">1</span>]]</span>
<span id="cb61-23"><a href="#cb61-23" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">|&gt;</span></span>
<span id="cb61-24"><a href="#cb61-24" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(<span class="sc">-</span><span class="dv">1</span>)</span>
<span id="cb61-25"><a href="#cb61-25" aria-hidden="true" tabindex="-1"></a> }) <span class="sc">|&gt;</span></span>
<span id="cb61-26"><a href="#cb61-26" aria-hidden="true" tabindex="-1"></a> <span class="fu">bind_rows</span>()</span>
<span id="cb61-27"><a href="#cb61-27" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb61-28"><a href="#cb61-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb61-29"><a href="#cb61-29" aria-hidden="true" tabindex="-1"></a>get.life.table.by.group <span class="ot">&lt;-</span> <span class="cf">function</span>(dat, time.intervals, grp) {</span>
<span id="cb61-30"><a href="#cb61-30" aria-hidden="true" tabindex="-1"></a> dat <span class="sc">|&gt;</span></span>
<span id="cb61-31"><a href="#cb61-31" aria-hidden="true" tabindex="-1"></a> <span class="fu">recode.dat</span>(time.intervals) <span class="sc">|&gt;</span></span>
<span id="cb61-32"><a href="#cb61-32" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(fu.interval, .data[[grp]]) <span class="sc">|&gt;</span></span>
<span id="cb61-33"><a href="#cb61-33" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(</span>
<span id="cb61-34"><a href="#cb61-34" aria-hidden="true" tabindex="-1"></a> <span class="at">n.censored =</span> <span class="fu">sum</span>(.data<span class="sc">$</span>death <span class="sc">==</span> <span class="dv">0</span>),</span>
<span id="cb61-35"><a href="#cb61-35" aria-hidden="true" tabindex="-1"></a> <span class="at">n.event =</span> <span class="fu">sum</span>(.data<span class="sc">$</span>death),</span>
<span id="cb61-36"><a href="#cb61-36" aria-hidden="true" tabindex="-1"></a> <span class="at">.groups =</span> <span class="st">"keep"</span></span>
<span id="cb61-37"><a href="#cb61-37" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">|&gt;</span></span>
<span id="cb61-38"><a href="#cb61-38" aria-hidden="true" tabindex="-1"></a> <span class="fu">ungroup</span>(fu.interval) <span class="sc">|&gt;</span></span>
<span id="cb61-39"><a href="#cb61-39" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_modify</span>(<span class="cf">function</span>(df.sub, grp) {</span>
<span id="cb61-40"><a href="#cb61-40" aria-hidden="true" tabindex="-1"></a> grp.name <span class="ot">&lt;-</span> <span class="fu">names</span>(grp)</span>
<span id="cb61-41"><a href="#cb61-41" aria-hidden="true" tabindex="-1"></a> grp.value <span class="ot">&lt;-</span> grp[[<span class="dv">1</span>]]</span>
<span id="cb61-42"><a href="#cb61-42" aria-hidden="true" tabindex="-1"></a> n.pop <span class="ot">&lt;-</span> (dat[[grp.name]] <span class="sc">==</span> grp.value) <span class="sc">|&gt;</span> <span class="fu">sum</span>()</span>
<span id="cb61-43"><a href="#cb61-43" aria-hidden="true" tabindex="-1"></a> <span class="fu">calculate.hazard</span>(df.sub, n.pop)</span>
<span id="cb61-44"><a href="#cb61-44" aria-hidden="true" tabindex="-1"></a> }) <span class="sc">|&gt;</span></span>
<span id="cb61-45"><a href="#cb61-45" aria-hidden="true" tabindex="-1"></a> <span class="fu">ungroup</span>()</span>
<span id="cb61-46"><a href="#cb61-46" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb61-47"><a href="#cb61-47" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb61-48"><a href="#cb61-48" aria-hidden="true" tabindex="-1"></a>calculate.hazard <span class="ot">&lt;-</span> <span class="cf">function</span>(life.table, n.pop) {</span>
<span id="cb61-49"><a href="#cb61-49" aria-hidden="true" tabindex="-1"></a> n.removed <span class="ot">&lt;-</span> life.table<span class="sc">$</span>n.event <span class="sc">+</span> life.table<span class="sc">$</span>n.censored</span>
<span id="cb61-50"><a href="#cb61-50" aria-hidden="true" tabindex="-1"></a> n.removed.accum <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="fu">cumsum</span>(n.removed)[<span class="sc">-</span><span class="fu">length</span>(n.removed)])</span>
<span id="cb61-51"><a href="#cb61-51" aria-hidden="true" tabindex="-1"></a> life.table <span class="sc">|&gt;</span></span>
<span id="cb61-52"><a href="#cb61-52" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb61-53"><a href="#cb61-53" aria-hidden="true" tabindex="-1"></a> <span class="at">n.at.risk =</span> n.pop <span class="sc">-</span> n.removed.accum,</span>
<span id="cb61-54"><a href="#cb61-54" aria-hidden="true" tabindex="-1"></a> <span class="co"># </span><span class="al">TODO</span><span class="co">: how to account for censored? How do we adjust for uneven interval?</span></span>
<span id="cb61-55"><a href="#cb61-55" aria-hidden="true" tabindex="-1"></a> <span class="at">hazard.rate =</span> n.event <span class="sc">/</span> n.at.risk</span>
<span id="cb61-56"><a href="#cb61-56" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb61-57"><a href="#cb61-57" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb61-58"><a href="#cb61-58" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb61-59"><a href="#cb61-59" aria-hidden="true" tabindex="-1"></a>recode.dat <span class="ot">&lt;-</span> <span class="cf">function</span>(dat, time.intervals) {</span>
<span id="cb61-60"><a href="#cb61-60" aria-hidden="true" tabindex="-1"></a> df <span class="ot">&lt;-</span> dat[dat<span class="sc">$</span>follow.up <span class="sc">&lt;=</span> <span class="fu">sum</span>(time.intervals), ]</span>
<span id="cb61-61"><a href="#cb61-61" aria-hidden="true" tabindex="-1"></a> time.points <span class="ot">&lt;-</span> <span class="fu">cumsum</span>(time.intervals)</span>
<span id="cb61-62"><a href="#cb61-62" aria-hidden="true" tabindex="-1"></a> df<span class="sc">$</span>fu.interval <span class="ot">&lt;-</span> <span class="fu">sapply</span>(df<span class="sc">$</span>follow.up, <span class="cf">function</span>(time) {</span>
<span id="cb61-63"><a href="#cb61-63" aria-hidden="true" tabindex="-1"></a> time.points[time <span class="sc">&lt;=</span> time.points][<span class="dv">1</span>]</span>
<span id="cb61-64"><a href="#cb61-64" aria-hidden="true" tabindex="-1"></a> })</span>
<span id="cb61-65"><a href="#cb61-65" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb61-66"><a href="#cb61-66" aria-hidden="true" tabindex="-1"></a> df</span>
<span id="cb61-67"><a href="#cb61-67" 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>
<div class="cell">
<div class="sourceCode cell-code" id="cb62"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb62-1"><a href="#cb62-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>)</span>
<span id="cb62-2"><a href="#cb62-2" aria-hidden="true" tabindex="-1"></a>grps <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"tx.type"</span>, <span class="st">"sex"</span>, <span class="st">"hla.match"</span>, <span class="st">"cold.isc"</span>)</span>
<span id="cb62-3"><a href="#cb62-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb62-4"><a href="#cb62-4" aria-hidden="true" tabindex="-1"></a><span class="fu">get.life.table.by.groups</span>(dat, time.intervals, grps)</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: 593 × 7
fu.interval n.censored n.event n.at.risk hazard.rate grp.name grp.value
&lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;chr&gt; &lt;dbl&gt;
1 0.333 463 49 5148 0.00952 tx.type 0
2 0.667 253 13 4636 0.00280 tx.type 0
3 1 340 11 4370 0.00252 tx.type 0
4 2 591 24 4019 0.00597 tx.type 0
5 3 568 17 3404 0.00499 tx.type 0
6 4 521 16 2819 0.00568 tx.type 0
7 5 501 11 2282 0.00482 tx.type 0
8 0.333 367 103 4627 0.0223 tx.type 1
9 0.667 238 24 4157 0.00577 tx.type 1
10 1 273 16 3895 0.00411 tx.type 1
# 583 more rows</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb64"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb64-1"><a href="#cb64-1" aria-hidden="true" tabindex="-1"></a>grps <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"tx.type"</span>, <span class="st">"sex"</span>, <span class="st">"hla.match"</span>, <span class="st">"cold.isc"</span>)</span>
<span id="cb64-2"><a href="#cb64-2" aria-hidden="true" tabindex="-1"></a>grps <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"tx.type"</span>)</span>
<span id="cb64-3"><a href="#cb64-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-4"><a href="#cb64-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-5"><a href="#cb64-5" aria-hidden="true" tabindex="-1"></a>plot.hazard.rate.by.groups <span class="ot">&lt;-</span> <span class="cf">function</span>(dat, time.intervals, grps) {</span>
<span id="cb64-6"><a href="#cb64-6" aria-hidden="true" tabindex="-1"></a> dat <span class="sc">|&gt;</span></span>
<span id="cb64-7"><a href="#cb64-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">get.life.table.by.groups</span>(time.intervals, grps) <span class="sc">|&gt;</span></span>
<span id="cb64-8"><a href="#cb64-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> fu.interval, <span class="at">y =</span> hazard.rate,</span>
<span id="cb64-9"><a href="#cb64-9" aria-hidden="true" tabindex="-1"></a> <span class="at">color =</span> <span class="fu">paste</span>(grp.name, grp.value, <span class="at">sep =</span> <span class="st">" = "</span>))) <span class="sc">+</span></span>
<span id="cb64-10"><a href="#cb64-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb64-11"><a href="#cb64-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb64-12"><a href="#cb64-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(</span>
<span id="cb64-13"><a href="#cb64-13" aria-hidden="true" tabindex="-1"></a> <span class="at">color =</span> <span class="st">"Group"</span></span>
<span id="cb64-14"><a href="#cb64-14" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">+</span></span>
<span id="cb64-15"><a href="#cb64-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(</span>
<span id="cb64-16"><a href="#cb64-16" aria-hidden="true" tabindex="-1"></a> <span class="at">legend.position =</span> <span class="st">"bottom"</span></span>
<span id="cb64-17"><a href="#cb64-17" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb64-18"><a href="#cb64-18" 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>
<div class="cell">
<div class="sourceCode cell-code" id="cb65"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb65-1"><a href="#cb65-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">rep</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">3</span>), <span class="fu">rep</span>(<span class="dv">1</span>, <span class="dv">4</span>))</span>
<span id="cb65-2"><a href="#cb65-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.hazard.rate.by.groups</span>(dat, time.intervals, <span class="fu">c</span>(<span class="st">"tx.type"</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="report_files/figure-html/unnamed-chunk-26-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb66"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb66-1"><a href="#cb66-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">rep</span>(<span class="dv">1</span>, <span class="dv">5</span>) </span>
<span id="cb66-2"><a href="#cb66-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.hazard.rate.by.groups</span>(dat, time.intervals, <span class="fu">c</span>(<span class="st">"tx.type"</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="report_files/figure-html/unnamed-chunk-27-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb67"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb67-1"><a href="#cb67-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">rep</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">15</span>)</span>
<span id="cb67-2"><a href="#cb67-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.hazard.rate.by.groups</span>(dat, time.intervals, <span class="fu">c</span>(<span class="st">"tx.type"</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="report_files/figure-html/unnamed-chunk-28-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb68"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb68-1"><a href="#cb68-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">rep</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">3</span><span class="sc">*</span><span class="dv">3</span>), <span class="fu">rep</span>(<span class="dv">1</span>, <span class="dv">2</span>))</span>
<span id="cb68-2"><a href="#cb68-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.hazard.rate.by.groups</span>(dat, time.intervals, <span class="fu">c</span>(<span class="st">"tx.type"</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="report_files/figure-html/unnamed-chunk-29-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb69"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb69-1"><a href="#cb69-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">rep</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">4</span>, <span class="dv">4</span>), <span class="fu">rep</span>(<span class="dv">1</span>, <span class="dv">4</span>))</span>
<span id="cb69-2"><a href="#cb69-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.hazard.rate.by.groups</span>(dat, time.intervals, <span class="fu">c</span>(<span class="st">"tx.type"</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="report_files/figure-html/unnamed-chunk-30-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb70"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb70-1"><a href="#cb70-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">rep</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">4</span>, <span class="dv">4</span><span class="sc">*</span><span class="dv">2</span>), <span class="fu">rep</span>(<span class="dv">1</span>, <span class="dv">3</span>))</span>
<span id="cb70-2"><a href="#cb70-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.hazard.rate.by.groups</span>(dat, time.intervals, <span class="fu">c</span>(<span class="st">"tx.type"</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="report_files/figure-html/unnamed-chunk-31-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb71"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb71-1"><a href="#cb71-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">rep</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">4</span>, <span class="dv">4</span><span class="sc">*</span><span class="dv">2</span>), <span class="fu">rep</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">3</span><span class="sc">*</span><span class="dv">3</span>), <span class="fu">rep</span>(<span class="dv">1</span>, <span class="dv">6</span>))</span>
<span id="cb71-2"><a href="#cb71-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.hazard.rate.by.groups</span>(dat, time.intervals, <span class="fu">c</span>(<span class="st">"tx.type"</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="report_files/figure-html/unnamed-chunk-32-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Compare</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb72"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb72-1"><a href="#cb72-1" aria-hidden="true" tabindex="-1"></a>time.intervals <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">1</span><span class="sc">/</span><span class="dv">3</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>)</span>
<span id="cb72-2"><a href="#cb72-2" aria-hidden="true" tabindex="-1"></a><span class="fu">get.life.table.by.groups</span>(dat, time.intervals, grps)</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: 14 × 7
fu.interval n.censored n.event n.at.risk hazard.rate grp.name grp.value
&lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;chr&gt; &lt;int&gt;
1 0.333 463 49 5148 0.00952 tx.type 0
2 0.667 253 13 4636 0.00280 tx.type 0
3 1 340 11 4370 0.00252 tx.type 0
4 2 591 24 4019 0.00597 tx.type 0
5 3 568 17 3404 0.00499 tx.type 0
6 4 521 16 2819 0.00568 tx.type 0
7 5 501 11 2282 0.00482 tx.type 0
8 0.333 367 103 4627 0.0223 tx.type 1
9 0.667 238 24 4157 0.00577 tx.type 1
10 1 273 16 3895 0.00411 tx.type 1
11 2 573 38 3606 0.0105 tx.type 1
12 3 575 24 2995 0.00801 tx.type 1
13 4 532 24 2396 0.0100 tx.type 1
14 5 418 20 1840 0.0109 tx.type 1</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb74"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb74-1"><a href="#cb74-1" aria-hidden="true" tabindex="-1"></a>hazard.df</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> fu.interval hazard.rate.0 hazard.rate.1 hazard.ratio
1 0.3333333 0.009518260 0.022260644 2.338731
2 0.6666667 0.002804142 0.005773394 2.058881
3 1.0000000 0.002517162 0.004107831 1.631929
4 2.0000000 0.005971635 0.010537992 1.764675
5 3.0000000 0.004994125 0.008013356 1.604557
6 4.0000000 0.005675772 0.010016694 1.764816
7 5.0000000 0.004820333 0.010869565 2.254941</code></pre>
</div>
</div>
</section>
<section id="exercise-4" class="level2" data-number="1.4">
<h2 data-number="1.4" class="anchored" data-anchor-id="exercise-4"><span class="header-section-number">1.4</span> Exercise 4</h2>
<p>Show a plot with Kaplan-Meier survival curves for the two donor types.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb76"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb76-1"><a href="#cb76-1" aria-hidden="true" tabindex="-1"></a>km.tx <span class="ot">&lt;-</span> <span class="fu">survfit</span>(<span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type, <span class="at">data =</span> dat[dat<span class="sc">$</span>follow.up <span class="sc">&lt;=</span> <span class="dv">12</span>, ])</span>
<span id="cb76-2"><a href="#cb76-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb76-3"><a href="#cb76-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(km.tx, <span class="at">col =</span> <span class="fu">c</span>(<span class="st">"blue"</span>, <span class="st">"orange"</span>))</span>
<span id="cb76-4"><a href="#cb76-4" aria-hidden="true" tabindex="-1"></a><span class="fu">legend</span>(<span class="at">legend =</span> <span class="fu">c</span>(<span class="st">"cadaveric"</span>, <span class="st">"living"</span>), <span class="st">"bottomleft"</span>, <span class="at">lwd =</span> <span class="dv">2</span>, <span class="at">col =</span> <span class="fu">c</span>(<span class="st">"blue"</span>, <span class="st">"orange"</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="report_files/figure-html/unnamed-chunk-35-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="exercise-5" class="level2" data-number="1.5">
<h2 data-number="1.5" class="anchored" data-anchor-id="exercise-5"><span class="header-section-number">1.5</span> Exercise 5</h2>
<p>Fit a univariate Cox model with predictor donor type. Report the hazard ratio and 95% confidence interval and interpret the result obtained.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb77"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb77-1"><a href="#cb77-1" aria-hidden="true" tabindex="-1"></a>cox.tx <span class="ot">&lt;-</span> <span class="fu">coxph</span>(<span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type, <span class="at">data =</span> dat)</span>
<span id="cb77-2"><a href="#cb77-2" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(cox.tx)</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:
coxph(formula = Surv(follow.up, death) ~ tx.type, data = dat)
n= 9775, number of events= 465
coef exp(coef) se(coef) z Pr(&gt;|z|)
tx.type 0.64469 1.90539 0.09558 6.745 1.53e-11 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coef) exp(-coef) lower .95 upper .95
tx.type 1.905 0.5248 1.58 2.298
Concordance= 0.586 (se = 0.012 )
Likelihood ratio test= 47.1 on 1 df, p=7e-12
Wald test = 45.5 on 1 df, p=2e-11
Score (logrank) test = 47.09 on 1 df, p=7e-12</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb79"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb79-1"><a href="#cb79-1" aria-hidden="true" tabindex="-1"></a>log.hazard.ratio.hat <span class="ot">&lt;-</span> cox.tx<span class="sc">$</span>coefficient</span>
<span id="cb79-2"><a href="#cb79-2" aria-hidden="true" tabindex="-1"></a>hazard.ratio.hat <span class="ot">&lt;-</span> log.hazard.ratio.hat <span class="sc">|&gt;</span> <span class="fu">exp</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="cb80"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb80-1"><a href="#cb80-1" aria-hidden="true" tabindex="-1"></a>log.hazard.ratio.se <span class="ot">&lt;-</span> <span class="fu">summary</span>(cox.tx)<span class="sc">$</span>coefficients[<span class="dv">3</span>]</span>
<span id="cb80-2"><a href="#cb80-2" aria-hidden="true" tabindex="-1"></a>log.hazard.ratio.hat.lower.bound <span class="ot">&lt;-</span> log.hazard.ratio.hat <span class="sc">-</span> <span class="fu">qnorm</span>(<span class="fl">0.975</span>) <span class="sc">*</span> log.hazard.ratio.se</span>
<span id="cb80-3"><a href="#cb80-3" aria-hidden="true" tabindex="-1"></a>log.hazard.ratio.hat.upper.bound <span class="ot">&lt;-</span> log.hazard.ratio.hat <span class="sc">+</span> <span class="fu">qnorm</span>(<span class="fl">0.975</span>) <span class="sc">*</span> log.hazard.ratio.se</span>
<span id="cb80-4"><a href="#cb80-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb80-5"><a href="#cb80-5" aria-hidden="true" tabindex="-1"></a><span class="fu">c</span>(log.hazard.ratio.hat.lower.bound, log.hazard.ratio.hat.upper.bound) <span class="sc">|&gt;</span> <span class="fu">exp</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> tx.type tx.type
1.579899 2.297932 </code></pre>
</div>
</div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>Patients receiving kidney transplants from living donors (<code>tx.type = 1</code>) has 1.91 higher hazard rate than those receiving from cadaveric donors (<code>tx.type = 0</code>).</p>
<p>Since 1 is not in the 95% confidence interval, the result is statistically significant.</p>
</div>
</div>
</section>
</section>
<section id="exercise-6" class="level1" data-number="2">
<h1 data-number="2"><span class="header-section-number">2</span> Exercise 6</h1>
<p>Research shows that an important determinant of mortality after kidney transplant is the age of the recipient. Fit a Cox model with age as predictor and estimate the hazard ratio and its confidence interval. Consider age first as continuous variable and then divide into categories.</p>
<section id="continuous" class="level2" data-number="2.1">
<h2 data-number="2.1" class="anchored" data-anchor-id="continuous"><span class="header-section-number">2.1</span> Continuous</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb82"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb82-1"><a href="#cb82-1" aria-hidden="true" tabindex="-1"></a>cox.age.rec <span class="ot">&lt;-</span> <span class="fu">coxph</span>(<span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> age.rec, <span class="at">data =</span> dat)</span>
<span id="cb82-2"><a href="#cb82-2" aria-hidden="true" tabindex="-1"></a>cox.age.rec <span class="sc">|&gt;</span> <span class="fu">summary</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:
coxph(formula = Surv(follow.up, death) ~ age.rec, data = dat)
n= 9766, number of events= 464
(9 observations deleted due to missingness)
coef exp(coef) se(coef) z Pr(&gt;|z|)
age.rec -0.042550 0.958342 0.008434 -5.045 4.53e-07 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coef) exp(-coef) lower .95 upper .95
age.rec 0.9583 1.043 0.9426 0.9743
Concordance= 0.586 (se = 0.016 )
Likelihood ratio test= 24.81 on 1 df, p=6e-07
Wald test = 25.45 on 1 df, p=5e-07
Score (logrank) test = 25.75 on 1 df, p=4e-07</code></pre>
</div>
</div>
</section>
<section id="categorical-case-1" class="level2" data-number="2.2">
<h2 data-number="2.2" class="anchored" data-anchor-id="categorical-case-1"><span class="header-section-number">2.2</span> Categorical (Case 1)</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb84"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb84-1"><a href="#cb84-1" aria-hidden="true" tabindex="-1"></a>recode.age <span class="ot">&lt;-</span> <span class="cf">function</span>(dat, ages) {</span>
<span id="cb84-2"><a href="#cb84-2" aria-hidden="true" tabindex="-1"></a> df<span class="sc">$</span>age.group <span class="ot">&lt;-</span> <span class="fu">sapply</span>(df<span class="sc">$</span>follow.up, <span class="cf">function</span>(time) {</span>
<span id="cb84-3"><a href="#cb84-3" aria-hidden="true" tabindex="-1"></a> time.points[time <span class="sc">&lt;=</span> time.points][<span class="dv">1</span>]</span>
<span id="cb84-4"><a href="#cb84-4" aria-hidden="true" tabindex="-1"></a> })</span>
<span id="cb84-5"><a href="#cb84-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb84-6"><a href="#cb84-6" aria-hidden="true" tabindex="-1"></a> df</span>
<span id="cb84-7"><a href="#cb84-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>
<div class="cell">
<div class="sourceCode cell-code" id="cb85"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb85-1"><a href="#cb85-1" aria-hidden="true" tabindex="-1"></a>dat.age.rec <span class="ot">&lt;-</span> dat[<span class="sc">!</span><span class="fu">is.na</span>(dat<span class="sc">$</span>age.rec), ]</span>
<span id="cb85-2"><a href="#cb85-2" aria-hidden="true" tabindex="-1"></a>class.age <span class="ot">&lt;-</span> <span class="cf">function</span>(age) {</span>
<span id="cb85-3"><a href="#cb85-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (age <span class="sc">&lt;</span> <span class="dv">2</span>) { </span>
<span id="cb85-4"><a href="#cb85-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="st">"0,1"</span>)</span>
<span id="cb85-5"><a href="#cb85-5" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> <span class="cf">if</span> (age <span class="sc">&lt;</span> <span class="dv">6</span>) {</span>
<span id="cb85-6"><a href="#cb85-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="st">"2,3,4,5"</span>)</span>
<span id="cb85-7"><a href="#cb85-7" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> <span class="cf">if</span> (age <span class="sc">&lt;</span> <span class="dv">11</span>) {</span>
<span id="cb85-8"><a href="#cb85-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="st">"6,7,8,9,10"</span>)</span>
<span id="cb85-9"><a href="#cb85-9" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> <span class="cf">if</span> (age <span class="sc">&lt;</span> <span class="dv">19</span>) {</span>
<span id="cb85-10"><a href="#cb85-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="st">"11-18"</span>)</span>
<span id="cb85-11"><a href="#cb85-11" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb85-12"><a href="#cb85-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>
<div class="cell">
<div class="sourceCode cell-code" id="cb86"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb86-1"><a href="#cb86-1" aria-hidden="true" tabindex="-1"></a>dat.age.rec<span class="sc">$</span>age.group <span class="ot">&lt;-</span> <span class="fu">sapply</span>(dat.age.rec<span class="sc">$</span>age.rec, class.age) <span class="sc">|&gt;</span></span>
<span id="cb86-2"><a href="#cb86-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">factor</span>(<span class="at">levels =</span> <span class="fu">c</span>(</span>
<span id="cb86-3"><a href="#cb86-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"0,1"</span>,</span>
<span id="cb86-4"><a href="#cb86-4" aria-hidden="true" tabindex="-1"></a> <span class="st">"2,3,4,5"</span>,</span>
<span id="cb86-5"><a href="#cb86-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"6,7,8,9,10"</span>,</span>
<span id="cb86-6"><a href="#cb86-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"11-18"</span></span>
<span id="cb86-7"><a href="#cb86-7" aria-hidden="true" tabindex="-1"></a> ))</span>
<span id="cb86-8"><a href="#cb86-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb86-9"><a href="#cb86-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb86-10"><a href="#cb86-10" aria-hidden="true" tabindex="-1"></a>cox.age.rec <span class="ot">&lt;-</span> <span class="fu">coxph</span>(<span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> age.group, <span class="at">data =</span> dat.age.rec)</span>
<span id="cb86-11"><a href="#cb86-11" aria-hidden="true" tabindex="-1"></a>cox.age.rec <span class="sc">|&gt;</span> <span class="fu">summary</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:
coxph(formula = Surv(follow.up, death) ~ age.group, data = dat.age.rec)
n= 9766, number of events= 464
coef exp(coef) se(coef) z Pr(&gt;|z|)
age.group2,3,4,5 -0.5947 0.5517 0.1767 -3.366 0.000764 ***
age.group6,7,8,9,10 -1.0578 0.3472 0.1776 -5.956 2.59e-09 ***
age.group11-18 -1.0192 0.3609 0.1513 -6.736 1.63e-11 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coef) exp(-coef) lower .95 upper .95
age.group2,3,4,5 0.5517 1.813 0.3902 0.7801
age.group6,7,8,9,10 0.3472 2.880 0.2452 0.4918
age.group11-18 0.3609 2.771 0.2683 0.4855
Concordance= 0.584 (se = 0.015 )
Likelihood ratio test= 44.93 on 3 df, p=1e-09
Wald test = 53.97 on 3 df, p=1e-11
Score (logrank) test = 57.87 on 3 df, p=2e-12</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb88"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb88-1"><a href="#cb88-1" aria-hidden="true" tabindex="-1"></a><span class="fu">emmeans</span>(cox.age.rec, pairwise <span class="sc">~</span> age.group, <span class="at">type =</span> <span class="st">"response"</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>$emmeans
age.group response SE df asymp.LCL asymp.UCL
0,1 1.000 0.0000 Inf 1.000 1.000
2,3,4,5 0.552 0.0975 Inf 0.390 0.780
6,7,8,9,10 0.347 0.0617 Inf 0.245 0.492
11-18 0.361 0.0546 Inf 0.268 0.485
Confidence level used: 0.95
Intervals are back-transformed from the log scale
$contrasts
contrast ratio SE df null z.ratio p.value
0,1 / 2,3,4,5 1.813 0.320 Inf 1 3.366 0.0043
0,1 / 6,7,8,9,10 2.880 0.511 Inf 1 5.956 &lt;.0001
0,1 / (11-18) 2.771 0.419 Inf 1 6.736 &lt;.0001
2,3,4,5 / 6,7,8,9,10 1.589 0.251 Inf 1 2.928 0.0179
2,3,4,5 / (11-18) 1.529 0.196 Inf 1 3.314 0.0051
6,7,8,9,10 / (11-18) 0.962 0.124 Inf 1 -0.298 0.9908
P value adjustment: tukey method for comparing a family of 4 estimates
Tests are performed on the log scale </code></pre>
</div>
</div>
</section>
</section>
<section id="exercise-7" class="level1" data-number="3">
<h1 data-number="3"><span class="header-section-number">3</span> Exercise 7</h1>
<p>Fit a multivariate Cox model by using other predictors and describe your results.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb90"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb90-1"><a href="#cb90-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sapply</span>(<span class="fu">names</span>(dat), <span class="cf">function</span>(col) {</span>
<span id="cb90-2"><a href="#cb90-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">is.na</span>(dat[, col]) <span class="sc">|&gt;</span> <span class="fu">sum</span>()</span>
<span id="cb90-3"><a href="#cb90-3" 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 class="cell-output cell-output-stdout">
<pre><code>hla.match age.donor age.rec cold.isc death year sex tx.type
234 113 9 2250 0 0 0 0
follow.up
0 </code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb92"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb92-1"><a href="#cb92-1" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(dat)</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] "hla.match" "age.donor" "age.rec" "cold.isc" "death" "year"
[7] "sex" "tx.type" "follow.up"</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb94"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb94-1"><a href="#cb94-1" aria-hidden="true" tabindex="-1"></a>Waldtest <span class="ot">&lt;-</span> <span class="cf">function</span>(cox.fit, i.betas){</span>
<span id="cb94-2"><a href="#cb94-2" aria-hidden="true" tabindex="-1"></a> q <span class="ot">&lt;-</span> <span class="fu">length</span>(i.betas)</span>
<span id="cb94-3"><a href="#cb94-3" aria-hidden="true" tabindex="-1"></a> coefs <span class="ot">&lt;-</span> cox.fit<span class="sc">$</span>coefficients</span>
<span id="cb94-4"><a href="#cb94-4" aria-hidden="true" tabindex="-1"></a> <span class="co"># print(cox.fit$var)</span></span>
<span id="cb94-5"><a href="#cb94-5" aria-hidden="true" tabindex="-1"></a> var <span class="ot">&lt;-</span> cox.fit<span class="sc">$</span>var[i.betas, i.betas]</span>
<span id="cb94-6"><a href="#cb94-6" aria-hidden="true" tabindex="-1"></a> Wald <span class="ot">&lt;-</span> coefs[i.betas]<span class="sc">%*%</span><span class="fu">solve</span>(var)<span class="sc">%*%</span>coefs[i.betas]</span>
<span id="cb94-7"><a href="#cb94-7" aria-hidden="true" tabindex="-1"></a> p.value <span class="ot">&lt;-</span> <span class="dv">1</span><span class="sc">-</span><span class="fu">pchisq</span>(<span class="fu">as.numeric</span>(Wald), <span class="at">df =</span> q)</span>
<span id="cb94-8"><a href="#cb94-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="fu">cbind</span>(Wald, p.value))</span>
<span id="cb94-9"><a href="#cb94-9" 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>
<div class="cell">
<div class="sourceCode cell-code" id="cb95"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb95-1"><a href="#cb95-1" aria-hidden="true" tabindex="-1"></a>fit.cox.model <span class="ot">&lt;-</span> <span class="cf">function</span>(surv, i.betas) {</span>
<span id="cb95-2"><a href="#cb95-2" aria-hidden="true" tabindex="-1"></a> fit.tx <span class="ot">&lt;-</span> <span class="fu">coxph</span>(surv, <span class="at">data =</span> dat)</span>
<span id="cb95-3"><a href="#cb95-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">Waldtest</span>(fit.tx, i.betas)</span>
<span id="cb95-4"><a href="#cb95-4" 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>Start with <code>tx.type</code></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb96"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb96-1"><a href="#cb96-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec</span>
<span id="cb96-2"><a href="#cb96-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">1</span><span class="sc">:</span><span class="dv">2</span>) <span class="co"># </span><span class="al">NOTE</span><span class="co">: Why is this 1???</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> p.value
[1,] 77.3778 0</code></pre>
</div>
</div>
<p>Iteration 1: <code>tx.type + age + ?</code></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb98"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb98-1"><a href="#cb98-1" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(dat)</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] "hla.match" "age.donor" "age.rec" "cold.isc" "death" "year"
[7] "sex" "tx.type" "follow.up"</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb100"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb100-1"><a href="#cb100-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match</span>
<span id="cb100-2"><a href="#cb100-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">3</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> p.value
[1,] 8.146717 0.004313919</code></pre>
</div>
<div class="sourceCode cell-code" id="cb102"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb102-1"><a href="#cb102-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> age.donor</span>
<span id="cb102-2"><a href="#cb102-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">3</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> p.value
[1,] 6.509223 0.01073164</code></pre>
</div>
<div class="sourceCode cell-code" id="cb104"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb104-1"><a href="#cb104-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> cold.isc</span>
<span id="cb104-2"><a href="#cb104-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">3</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> p.value
[1,] 0.7057259 0.4008664</code></pre>
</div>
<div class="sourceCode cell-code" id="cb106"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb106-1"><a href="#cb106-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> year</span>
<span id="cb106-2"><a href="#cb106-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">3</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> p.value
[1,] 4.680593 0.03050521</code></pre>
</div>
<div class="sourceCode cell-code" id="cb108"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb108-1"><a href="#cb108-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> sex</span>
<span id="cb108-2"><a href="#cb108-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">3</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> p.value
[1,] 1.921176 0.1657271</code></pre>
</div>
</div>
<p>Add <code>hla.match</code></p>
<p>Iteration 2: <code>tx.type + age.rec + hla.match + ?</code></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb110"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb110-1"><a href="#cb110-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> age.donor</span>
<span id="cb110-2"><a href="#cb110-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">4</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> p.value
[1,] 5.211567 0.0224371</code></pre>
</div>
<div class="sourceCode cell-code" id="cb112"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb112-1"><a href="#cb112-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> cold.isc</span>
<span id="cb112-2"><a href="#cb112-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">4</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> p.value
[1,] 0.9157965 0.3385811</code></pre>
</div>
<div class="sourceCode cell-code" id="cb114"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb114-1"><a href="#cb114-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> year</span>
<span id="cb114-2"><a href="#cb114-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">4</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> p.value
[1,] 4.94216 0.02620927</code></pre>
</div>
<div class="sourceCode cell-code" id="cb116"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb116-1"><a href="#cb116-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> sex</span>
<span id="cb116-2"><a href="#cb116-2" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">4</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> p.value
[1,] 0.981911 0.3217275</code></pre>
</div>
</div>
<p>Add <code>age.donor</code></p>
<p>Iteration 2: <code>tx.type + age.rec + hla.match + age.donor + ?</code></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb118"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb118-1"><a href="#cb118-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> age.donor <span class="sc">+</span></span>
<span id="cb118-2"><a href="#cb118-2" aria-hidden="true" tabindex="-1"></a> cold.isc</span>
<span id="cb118-3"><a href="#cb118-3" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">5</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> p.value
[1,] 0.4450261 0.5047065</code></pre>
</div>
<div class="sourceCode cell-code" id="cb120"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb120-1"><a href="#cb120-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> age.donor <span class="sc">+</span></span>
<span id="cb120-2"><a href="#cb120-2" aria-hidden="true" tabindex="-1"></a> year</span>
<span id="cb120-3"><a href="#cb120-3" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">5</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> p.value
[1,] 4.367751 0.03662531</code></pre>
</div>
<div class="sourceCode cell-code" id="cb122"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb122-1"><a href="#cb122-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> age.donor <span class="sc">+</span></span>
<span id="cb122-2"><a href="#cb122-2" aria-hidden="true" tabindex="-1"></a> sex</span>
<span id="cb122-3"><a href="#cb122-3" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">5</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> p.value
[1,] 0.9343691 0.3337302</code></pre>
</div>
</div>
<p>Add <code>year</code></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb124"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb124-1"><a href="#cb124-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> age.donor <span class="sc">+</span> </span>
<span id="cb124-2"><a href="#cb124-2" aria-hidden="true" tabindex="-1"></a> year <span class="sc">+</span> cold.isc</span>
<span id="cb124-3"><a href="#cb124-3" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">6</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> p.value
[1,] 0.1614349 0.6878388</code></pre>
</div>
<div class="sourceCode cell-code" id="cb126"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb126-1"><a href="#cb126-1" aria-hidden="true" tabindex="-1"></a>surv <span class="ot">&lt;-</span> <span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> age.donor <span class="sc">+</span> </span>
<span id="cb126-2"><a href="#cb126-2" aria-hidden="true" tabindex="-1"></a> year <span class="sc">+</span> sex</span>
<span id="cb126-3"><a href="#cb126-3" aria-hidden="true" tabindex="-1"></a><span class="fu">fit.cox.model</span>(surv, <span class="dv">6</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> p.value
[1,] 0.9641705 0.3261383</code></pre>
</div>
</div>
<p>Next, we test for each remaining variables</p>
</section>
<section id="exercise-8" class="level1" data-number="4">
<h1 data-number="4"><span class="header-section-number">4</span> Exercise 8</h1>
<p>Estimate the survival function for specific covariate patterns. Based on the previous results choose the best predictors.</p>
<p>Exercise 9 — Check the proportional hazards assumption. You may use the function cox.zph. Discuss the result and possible implications.</p>
<p>H0: PH-assumption holds H1: PH-assumption doesnt hold</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb128"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb128-1"><a href="#cb128-1" aria-hidden="true" tabindex="-1"></a><span class="co"># different cox model!!</span></span>
<span id="cb128-2"><a href="#cb128-2" aria-hidden="true" tabindex="-1"></a>cox.final <span class="ot">&lt;-</span> <span class="fu">coxph</span>(<span class="fu">Surv</span>(follow.up, death) <span class="sc">~</span> tx.type <span class="sc">+</span> age.rec <span class="sc">+</span> hla.match <span class="sc">+</span> age.donor, <span class="at">data =</span> dat)</span>
<span id="cb128-3"><a href="#cb128-3" aria-hidden="true" tabindex="-1"></a><span class="fu">cox.zph</span>(cox.final)</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
tx.type 2.56 1 0.10948
age.rec 35.98 1 2.0e-09
hla.match 8.22 1 0.00414
age.donor 11.05 1 0.00089
GLOBAL 47.37 4 1.3e-09</code></pre>
</div>
</div>
<p>Exercise 10 — Plot the Schoenfeld residuals and comment. A non-random pattern or slope in a plot of scaled residuals against time indicates a violation, suggesting the covariates impact changes, while a horizontal line around zero supports the assumption.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb130"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb130-1"><a href="#cb130-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">cox.zph</span>(cox.final))</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="report_files/figure-html/unnamed-chunk-56-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="report_files/figure-html/unnamed-chunk-56-2.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="report_files/figure-html/unnamed-chunk-56-3.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="report_files/figure-html/unnamed-chunk-56-4.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>NOTES: left censoring: event happened before time zero -&gt; not applicable left truncation: not applicable?? right censoring: we saw this in the follow up times, administrative censoring high</p>
<p>! No left truncation, since our target population is patients who received a kidney transplant. So we dont care about patients who died before receiving a transplant.</p>
<p>! ADD: we used a Cox model but we already saw that the PH assumption doesnt hold !</p>
<p>? remove year from prediction model, since it is not a patient characteristic and may not be stable for future predictions. It mainly captures changes in clinical practice rather than individual risk.</p>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
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')) {
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
text: getTextToCopy,
container: window.document.getElementById('quarto-embedded-source-code-modal')
});
clipboardModal.on('success', onCopySuccess);
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var mailtoRegex = new RegExp(/^mailto:/);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// undo the damage that might have been done by quarto-nav.js in the case of
// links that we want to consider external
if (link.dataset.originalHref !== undefined) {
link.href = link.dataset.originalHref;
}
}
}
function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
const config = {
allowHTML: true,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start',
};
if (contentFn) {
config.content = contentFn;
}
if (onTriggerFn) {
config.onTrigger = onTriggerFn;
}
if (onUntriggerFn) {
config.onUntrigger = onUntriggerFn;
}
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note) {
return note.innerHTML;
} else {
return "";
}
});
}
const xrefs = window.document.querySelectorAll('a.quarto-xref');
const processXRef = (id, note) => {
// Strip column container classes
const stripColumnClz = (el) => {
el.classList.remove("page-full", "page-columns");
if (el.children) {
for (const child of el.children) {
stripColumnClz(child);
}
}
}
stripColumnClz(note)
if (id === null || id.startsWith('sec-')) {
// Special case sections, only their first couple elements
const container = document.createElement("div");
if (note.children && note.children.length > 2) {
container.appendChild(note.children[0].cloneNode(true));
for (let i = 1; i < note.children.length; i++) {
const child = note.children[i];
if (child.tagName === "P" && child.innerText === "") {
continue;
} else {
container.appendChild(child.cloneNode(true));
break;
}
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(container);
}
return container.innerHTML
} else {
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
return note.innerHTML;
}
} else {
// Remove any anchor links if they are present
const anchorLink = note.querySelector('a.anchorjs-link');
if (anchorLink) {
anchorLink.remove();
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
if (note.classList.contains("callout")) {
return note.outerHTML;
} else {
return note.innerHTML;
}
}
}
for (var i=0; i<xrefs.length; i++) {
const xref = xrefs[i];
tippyHover(xref, undefined, function(instance) {
instance.disable();
let url = xref.getAttribute('href');
let hash = undefined;
if (url.startsWith('#')) {
hash = url;
} else {
try { hash = new URL(url).hash; } catch {}
}
if (hash) {
const id = hash.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note !== null) {
try {
const html = processXRef(id, note.cloneNode(true));
instance.setContent(html);
} finally {
instance.enable();
instance.show();
}
} else {
// See if we can fetch this
fetch(url.split('#')[0])
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.getElementById(id);
if (note !== null) {
const html = processXRef(id, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
} else {
// See if we can fetch a full url (with no hash to target)
// This is a special case and we should probably do some content thinning / targeting
fetch(url)
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.querySelector('main.content');
if (note !== null) {
// This should only happen for chapter cross references
// (since there is no id in the URL)
// remove the first header
if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
note.children[0].remove();
}
const html = processXRef(null, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
}, function(instance) {
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
div.style.left = 0;
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Handle positioning of the toggle
window.addEventListener(
"resize",
throttle(() => {
elRect = undefined;
if (selectedAnnoteEl) {
selectCodeLines(selectedAnnoteEl);
}
}, 10)
);
function throttle(fn, ms) {
let throttle = false;
let timer;
return (...args) => {
if(!throttle) { // first call gets through
fn.apply(this, args);
throttle = true;
} else { // all the others get throttled
if(timer) clearTimeout(timer); // cancel #2
timer = setTimeout(() => {
fn.apply(this, args);
timer = throttle = false;
}, ms);
}
};
}
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>