{"id":1196,"date":"2015-08-27T10:37:04","date_gmt":"2015-08-27T09:37:04","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=1196"},"modified":"2025-06-26T09:14:05","modified_gmt":"2025-06-26T08:14:05","slug":"answers-survival-analysis","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/answers-survival-analysis\/","title":{"rendered":"Answers Survival Analysis"},"content":{"rendered":"\n<p><em>The table below shows 20 patients who have been diagnosed with cancer. The first column shows the follow up (in years) of the patients who were alive at review. In the second column, the follow up till time of death is indicated. The third column shows the time to last review in the patients who were lost to follow up:<\/em><\/p>\n\n\n\n<p>The data is also available in <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/Q9.rda\" target=\"_blank\" rel=\"noreferrer noopener\">Q9.rda <\/a>and for convenience the table is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"268\" height=\"226\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-1.png\" alt=\"\" class=\"wp-image-3491\"\/><\/figure>\n\n\n\n<p><strong>1. Calculate the 5-year survival in the <em>best-case scenario,<\/em> using life table analysis.<\/strong><\/p>\n\n\n\n<p>The <strong><em>best-case scenario<\/em><\/strong> is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"472\" height=\"215\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-2.png\" alt=\"\" class=\"wp-image-3492\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-2.png 472w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-2-300x137.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/figure>\n\n\n\n<p>So, the 5-year survival in the <em>best-case scenario<\/em> as estimated with life table analysis is 41%.<\/p>\n\n\n\n<p><strong>2. Calculate the 5-year survival in the <em>worst-case scenario,<\/em> using life table analysis.<\/strong><\/p>\n\n\n\n<p>The <strong><em>worst-case scenario <\/em><\/strong>life table is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"467\" height=\"214\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-3.png\" alt=\"\" class=\"wp-image-3493\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-3.png 467w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-3-300x137.png 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/figure>\n\n\n\n<p>So, the 5-year survival in the <em>worst-case scenario<\/em> as estimated with life table analysis is 20%.<\/p>\n\n\n\n<p><strong>3. Show the <em>best-case scenario <\/em>and<em> worst-case scenario <\/em>survival curves in one graph, using life table analysis.<\/strong><\/p>\n\n\n\n<p>Using the tables constructed in Q1 and Q2, survival curves can be drawn:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"259\" height=\"217\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-4.png\" alt=\"\" class=\"wp-image-3494\"\/><\/figure>\n\n\n\n<p>The <strong><em>best-case scenario<\/em> <\/strong>is shown in black and the <strong><em>worst-case scenario<\/em> <\/strong>is shown in grey.<\/p>\n\n\n\n<p><strong>4. Perform the Kaplan-Meier survival analysis in the <em>best-case scenario<\/em>.<\/strong><\/p>\n\n\n\n<p>In the&nbsp;<strong><em>best-case scenario<\/em><\/strong>, the patients lost to follow up count as a success. The Kaplan-Meier table is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"326\" height=\"552\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-5.png\" alt=\"\" class=\"wp-image-3495\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-5.png 326w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-5-177x300.png 177w\" sizes=\"auto, (max-width: 326px) 100vw, 326px\" \/><\/figure>\n\n\n\n<p>In R:<\/p>\n\n\n\n<p>Once the data frame is loaded, the data should be visible with the variables &#8216;Number&#8217;, &#8216;FU&#8217; and &#8216;Outcome&#8217;. <\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fa0808\" class=\"has-inline-color\">load(\"\/path\/to_file\/Q9 (1).rda\")\nQ9<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0c0ef0\" class=\"has-inline-color\">   Number  FU Outcome\n1       1 0.2   alive\n2       2 0.4   alive\n3       3 1.5   alive\n4       4 2.2   alive\n5       5 2.5   alive\n6       6 3.1   alive\n7       7 3.5   alive\n8       8 4.1   alive\n9       9 0.6    dead\n10     10 1.2    dead\n11     11 1.4    dead\n12     12 1.9    dead\n13     13 2.1    dead\n14     14 2.5    dead\n15     15 3.8    dead\n16     16 0.8    lost\n17     17 1.4    lost\n18     18 1.8    lost\n19     19 2.1    lost\n20     20 3.6    lost<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>It is of course possible to create a new logical variable that is needed for survival analysis (called &#8216;Best&#8217;) and go through the data manually; setting the value to FALSE (0) if the &#8216;Outcome&#8217; variable is &#8216;alive&#8217; or &#8216;lost&#8217; and TRUE (1) if the &#8216;Outcome&#8217; variable is &#8216;dead&#8217;. However, this would become tedious for larger data sets. It would be easier to recode the variable &#8216;Outcome&#8217; in a new variable &#8216;Best&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f60404\" class=\"has-inline-color\">Q9$Best &lt;- ifelse(Q9$Outcome == 'dead', 1, 0)\nQ9<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0e09ed\" class=\"has-inline-color\">   Number  FU Outcome Best\n1       1 0.2   alive    0\n2       2 0.4   alive    0\n3       3 1.5   alive    0\n4       4 2.2   alive    0\n5       5 2.5   alive    0\n6       6 3.1   alive    0\n7       7 3.5   alive    0\n8       8 4.1   alive    0\n9       9 0.6    dead    1\n10     10 1.2    dead    1\n11     11 1.4    dead    1\n12     12 1.9    dead    1\n13     13 2.1    dead    1\n14     14 2.5    dead    1\n15     15 3.8    dead    1\n16     16 0.8    lost    0\n17     17 1.4    lost    0\n18     18 1.8    lost    0\n19     19 2.1    lost    0\n20     20 3.6    lost    0<\/mark><\/em>\n<em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f70101\" class=\"has-inline-color\">str(Q9)<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0619f3\" class=\"has-inline-color\">'data.frame':\t20 obs. of  4 variables:\n $ Number : num  1 2 3 4 5 6 7 8 9 10 ...\n $ FU     : num  0.2 0.4 1.5 2.2 2.5 3.1 3.5 4.1 0.6 1.2 ...\n $ Outcome: Factor w\/ 3 levels \"alive\",\"dead\",..: 1 1 1 1 1 1 1 1 2 2 ...\n $ Best   : num  0 0 0 0 0 0 0 0 1 1 ...<\/mark><\/em><\/code><\/pre>\n\n\n\n<p class=\"is-style-text-annotation is-style-text-annotation--1\">If the variable Outcome (Q9$Outcome) is equal to (==) &#8216;dead&#8217;, then the Best variable (Q9$Best) = 1, else it is 0.<\/p>\n\n\n\n<p>As can be seen in the structure of the data frame (str), the newly created variable &#8216;Best&#8217; is numerical and takes values 0 and 1.<\/p>\n\n\n\n<p>Now perform the survival analysis with the survival package<sup class='sup-ref-note' id='note-zotero-ref-p1196-r1-o1'><a class='sup-ref-note' href='#zotero-ref-p1196-r1'>1<\/a><\/sup>. Make sure the package survival is <a href=\"https:\/\/pcool.dyndns.org\/index.php\/packages\/\" data-type=\"page\" data-id=\"22\">installed<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30303\" class=\"has-inline-color\">my_survival &lt;- Surv(Q9$FU, Q9$Best)\nmy_survival\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#2709f4\" class=\"has-inline-color\"> &#091;1] 0.2+ 0.4+ 1.5+ 2.2+ 2.5+ 3.1+ 3.5+ 4.1+ 0.6  1.2  1.4  1.9  2.1  2.5  3.8  0.8+ 1.4+ 1.8+\n&#091;19] 2.1+ 3.6+<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#f10303\" class=\"has-inline-color\">summary(my_survival)<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a1cea\" class=\"has-inline-color\">      time           status    \n Min.   :0.200   Min.   :0.00  \n 1st Qu.:1.350   1st Qu.:0.00  \n Median :2.000   Median :0.00  \n Mean   :2.035   Mean   :0.35  \n 3rd Qu.:2.650   3rd Qu.:1.00  \n Max.   :4.100   Max.   :1.00  <\/mark><\/em><\/code><\/pre>\n\n\n\n<p>And calculate the survival curve:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30606\" class=\"has-inline-color\">my_curve &lt;- survfit(my_survival ~ 1, conf.int = 0.95, data=Q9)\nsummary(my_curve)<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#140fe6\" class=\"has-inline-color\">Call: survfit(formula = my_survival ~ 1, data = Q9, conf.int = 0.95)\n\n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  0.6     18       1    0.944  0.0540       0.8443        1.000\n  1.2     16       1    0.885  0.0763       0.7477        1.000\n  1.4     15       1    0.826  0.0913       0.6655        1.000\n  1.9     11       1    0.751  0.1096       0.5644        1.000\n  2.1     10       1    0.676  0.1217       0.4751        0.962\n  2.5      7       1    0.580  0.1374       0.3642        0.922\n  3.8      2       1    0.290  0.2161       0.0672        1.000<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Plot the curve:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f50505\" class=\"has-inline-color\"><em>par(mar=c(2,2,2,2)) # to increase plot margins in RStudio<\/em>\n<em>plot(my_curve, col='black', main='Kaplan Meier Curve',  \n  xlab='Follow Up Duration', ylab='Cumulative Survival Probability')<\/em><\/mark><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"769\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q4_best-1024x769.jpeg\" alt=\"\" class=\"wp-image-4407\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q4_best-1024x769.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q4_best-300x225.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q4_best-768x577.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q4_best.jpeg 1350w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"is-style-text-annotation is-style-text-annotation--2\">Please note the survival estimate is similar to the table above, but the last two values are slightly different due to rounding error.<\/p>\n\n\n\n<p><strong>5. What is the survival in Q4 at 4.1 years?<\/strong><\/p>\n\n\n\n<p>The survival at 4.1 years in the <em>best-case scenario<\/em> as estimated with Kaplan-Meier analysis as calculated in the table in Q4 above is 28%.<\/p>\n\n\n\n<p>In R:<\/p>\n\n\n\n<p><span style=\"color: #000000;\">Using the output from R in Q4 above: 29%.<\/span><\/p>\n\n\n\n<p>Or alternatively in the console on the recoded variable &#8216;Best&#8217; following on from above:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f60909\" class=\"has-inline-color\">summary(my_curve,time=4.1)<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#110cf1\" class=\"has-inline-color\">Call: survfit(formula = my_survival ~ 1, conf.int = 0.95)\n\n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  4.1      1       7     <strong>0.29 <\/strong>  0.216       0.0672            1<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Therefore, the survival at 4.1 years is 29%.<\/p>\n\n\n\n<p><strong>6. What is the median survival in Q4?<\/strong><\/p>\n\n\n\n<p>For the answer to this question we need to plot the survival curve:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"281\" height=\"215\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-6.png\" alt=\"\" class=\"wp-image-3496\"\/><\/figure>\n\n\n\n<p><a href=\"http:\/\/pcool.dyndns.org:8080\/statsbook\/wp-content\/uploads\/Q9-6.png\"><\/a>It can be seen from the graph that the median survival \u2248 3.75 years.<\/p>\n\n\n\n<p>In R:<\/p>\n\n\n\n<p><span style=\"color: #99cc00;\"><span style=\"color: #000000;\">Alternatively, using the console method (as above):<\/span><\/span><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f40101\" class=\"has-inline-color\">my_curve<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#2e0aec\" class=\"has-inline-color\">Call: survfit(formula = my_survival ~ 1, data = Q9, conf.int = 0.95)\n\n      n events median 0.95LCL 0.95UCL\n&#091;1,] 20      7    <strong>3.8<\/strong>     2.1      NA<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Therefore, the median survival is 3.8 years.<\/p>\n\n\n\n<p><strong>7. Perform the Kaplan-Meier survival analysis in the <em>worst-case scenario<\/em>.<\/strong><\/p>\n\n\n\n<p>In the <strong><em>worst-case scenario<\/em><\/strong>, the patients lost to follow up count as a failure. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"329\" height=\"596\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-7.png\" alt=\"\" class=\"wp-image-3497\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-7.png 329w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-7-166x300.png 166w\" sizes=\"auto, (max-width: 329px) 100vw, 329px\" \/><\/figure>\n\n\n\n<p><span style=\"color: #99cc00;\"><span style=\"color: #000000;\">Similarly as in Q4, the &#8216;Outcome&#8217; variable can be recoded into a new variable &#8216;Worst&#8217;; when the &#8216;Outcome&#8217; is &#8216;alive&#8217; &#8216;Worst&#8217; is coded as 0 and when the &#8216;Outcome&#8217; is &#8216;dead&#8217; or &#8216;lost&#8217; &#8216;Worst&#8217; is coded as 1:<\/span><\/span><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>Q9$Worst &lt;- ifelse(Q9$Outcome == 'alive', 0, 1)<\/em>\n<em>Q9<\/em><\/mark><em>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#2903f0\" class=\"has-inline-color\">   Number  FU Outcome Best Worst\n1       1 0.2   alive    0     0\n2       2 0.4   alive    0     0\n3       3 1.5   alive    0     0\n4       4 2.2   alive    0     0\n5       5 2.5   alive    0     0\n6       6 3.1   alive    0     0\n7       7 3.5   alive    0     0\n8       8 4.1   alive    0     0\n9       9 0.6    dead    1     1\n10     10 1.2    dead    1     1\n11     11 1.4    dead    1     1\n12     12 1.9    dead    1     1\n13     13 2.1    dead    1     1\n14     14 2.5    dead    1     1\n15     15 3.8    dead    1     1\n16     16 0.8    lost    0     1\n17     17 1.4    lost    0     1\n18     18 1.8    lost    0     1\n19     19 2.1    lost    0     1\n20     20 3.6    lost    0     1<\/mark><\/em>\n<em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f00727\" class=\"has-inline-color\">str(Q9)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#2508f0\" class=\"has-inline-color\">\n'data.frame':\t20 obs. of  5 variables:\n $ Number : num  1 2 3 4 5 6 7 8 9 10 ...\n $ FU     : num  0.2 0.4 1.5 2.2 2.5 3.1 3.5 4.1 0.6 1.2 ...\n $ Outcome: Factor w\/ 3 levels \"alive\",\"dead\",..: 1 1 1 1 1 1 1 1 2 2 ...\n $ Best   : num  0 0 0 0 0 0 0 0 1 1 ...\n $ Worst  : num  0 0 0 0 0 0 0 0 1 1 ...<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Next perform the survival analysis as described above.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>my_survival &lt;- Surv(Q9$FU, Q9$Worst)\nmy_survival\n<\/em><\/mark><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0508f2\" class=\"has-inline-color\"> &#091;1] 0.2+ 0.4+ 1.5+ 2.2+ 2.5+ 3.1+ 3.5+ 4.1+ 0.6  1.2  1.4  1.9 \n&#091;13] 2.1  2.5  3.8  0.8  1.4  1.8  2.1  3.6 \n<\/mark><\/em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>summary(my_survival)\n<\/em><\/mark><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#2305f2\" class=\"has-inline-color\">      time           status   \n Min.   :0.200   Min.   :0.0  \n 1st Qu.:1.350   1st Qu.:0.0  \n Median :2.000   Median :1.0  \n Mean   :2.035   Mean   :0.6  \n 3rd Qu.:2.650   3rd Qu.:1.0  \n Max.   :4.100   Max.   :1.0  <\/mark><\/em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>\nmy_curve &lt;- survfit(my_survival ~ 1, data= Q9, conf.int=0.95)\nsummary(my_curve)\n<\/em><\/mark><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0a05f2\" class=\"has-inline-color\">Call: survfit(formula = my_survival ~ 1, data = Q9, conf.int = 0.95)\n\n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  0.6     18       1    0.944  0.0540       0.8443        1.000\n  0.8     17       1    0.889  0.0741       0.7549        1.000\n  1.2     16       1    0.833  0.0878       0.6778        1.000\n  1.4     15       2    0.722  0.1056       0.5423        0.962\n  1.8     12       1    0.662  0.1126       0.4743        0.924\n  1.9     11       1    0.602  0.1174       0.4107        0.882\n  2.1     10       2    0.481  0.1209       0.2944        0.788\n  2.5      7       1    0.413  0.1216       0.2316        0.735\n  3.6      3       1    0.275  0.1385       0.1026        0.738\n  3.8      2       1    0.138  0.1194       0.0251        0.754<\/mark><\/em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>\npar(mar=c(2,2,2,2)) # to increase plot margins in RStudio\nplot(my_curve, col='black', main='Kaplan Meier Curve', <\/em>\n  <em>xlab='Follow Up Duration', ylab='Cumulative Survival Probability')<\/em><\/mark><em>\n<\/em><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"769\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q7-worst-1024x769.jpeg\" alt=\"\" class=\"wp-image-4408\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q7-worst-1024x769.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q7-worst-300x225.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q7-worst-768x577.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q7-worst.jpeg 1350w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>8. What is the survival in Q7 at 4.1 years?<\/strong><\/p>\n\n\n\n<p><span style=\"color: #000000;\">Using the table in Q7: 13.8%.<\/span><\/p>\n\n\n\n<p>Or alternatively in the console on the recoded variable &#8216;Worst&#8217;:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#e81330\" class=\"has-inline-color\">summary(my_curve,time=4.1)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1324e7\" class=\"has-inline-color\">\nCall: survfit(formula = my_survival ~ 1, data = Q9, conf.int = 0.95)\n\n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  4.1      1      12    <strong>0.138<\/strong>   0.119       0.0251        0.754<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Therefore, the survival at 4.1 years is 13.8%.<\/p>\n\n\n\n<p><strong>9. What is the median survival in Q7?<\/strong><\/p>\n\n\n\n<p>For the answer to this question we need to plot the survival curve:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"278\" height=\"196\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-8.png\" alt=\"\" class=\"wp-image-3498\"\/><\/figure>\n\n\n\n<p>It can be estimated from the graph that the median survival&nbsp;\u2248 2.25 years.<\/p>\n\n\n\n<p>In R:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f00525\" class=\"has-inline-color\">my_curve<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#4a05f0\" class=\"has-inline-color\">\nCall: survfit(formula = my_survival ~ 1, data = Q9, conf.int = 0.95)\n\n      n events median 0.95LCL 0.95UCL\n&#091;1,] 20     12    <strong>2.1<\/strong>     1.8      NA<\/mark><\/code><\/pre>\n\n\n\n<p>Therefore, the median survival is 2.1 years.<\/p>\n\n\n\n<p><em>The outcome data of 20 patients who had a total ankle replacement are listed in&nbsp; <\/em><a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/survivalankle.rda\" target=\"_blank\" rel=\"noreferrer noopener\">survivalankle.rda.<\/a><\/p>\n\n\n\n<p><strong>10. Calculate the 10-year Kaplan-Meier survival of the prosthesis using revision for <em>aseptic loosening<\/em> as \u2018hard end point\u2019.<\/strong><\/p>\n\n\n\n<p>Only patients who had a <strong><em>\u2018Revision\u2019 for aseptic loosening<\/em><\/strong> are counted as failures. The Kaplan-Meier table is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"494\" height=\"408\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-9.png\" alt=\"\" class=\"wp-image-3499\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-9.png 494w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-9-300x248.png 300w\" sizes=\"auto, (max-width: 494px) 100vw, 494px\" \/><\/figure>\n\n\n\n<p><a href=\"http:\/\/pcool.dyndns.org:8080\/statsbook\/wp-content\/uploads\/Q9-9.png\"><\/a>The 10-year Kaplan-Meier survival for aseptic loosening is therefore 80%:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"233\" height=\"173\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-10.png\" alt=\"\" class=\"wp-image-3500\"\/><\/figure>\n\n\n\n<p>In R:<\/p>\n\n\n\n<p>First recode the &#8216;Outcome&#8217; variable to a variable called &#8216;Censor&#8217; as described above (Q4).<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f5023c\" class=\"has-inline-color\">load(\"\/path\/to_file\/survivalankle.rda\")\nsurvivalankle<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1802f4\" class=\"has-inline-color\">\n   Number   FU                     Outcome\n1       1  1.1                        Well\n2       2  1.2         Revised (infection)\n3       3  1.9                        Well\n4       4  2.1                        Well\n5       5  2.9                        Well\n6       6  3.1                        Well\n7       7  3.9                        Well\n8       8  5.0                        Well\n9       9  5.3 Revised (aseptic loosening)\n10     10  5.5                        Well\n11     11  6.1                  Lost to FU\n12     12  6.3                        Well\n13     13  6.9 Revised (aseptic loosening)\n14     14  7.1                        Well\n15     15  7.3                  Lost to FU\n16     16  7.4                  Lost to FU\n17     17  7.5                  Lost to FU\n18     18  8.9                        Well\n19     19  9.5                  Lost to FU\n20     20 10.2                        Well\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f50223\" class=\"has-inline-color\">survivalankle$Censor &lt;- ifelse(survivalankle$Outcome == 'Revised (aseptic loosening)', 1, 0)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1802f4\" class=\"has-inline-color\">\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f5021b\" class=\"has-inline-color\">survivalankle<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1802f4\" class=\"has-inline-color\">\n   Number   FU                     Outcome Censor\n1       1  1.1                        Well      0\n2       2  1.2         Revised (infection)      0\n3       3  1.9                        Well      0\n4       4  2.1                        Well      0\n5       5  2.9                        Well      0\n6       6  3.1                        Well      0\n7       7  3.9                        Well      0\n8       8  5.0                        Well      0\n9       9  5.3 Revised (aseptic loosening)      1\n10     10  5.5                        Well      0\n11     11  6.1                  Lost to FU      0\n12     12  6.3                        Well      0\n13     13  6.9 Revised (aseptic loosening)      1\n14     14  7.1                        Well      0\n15     15  7.3                  Lost to FU      0\n16     16  7.4                  Lost to FU      0\n17     17  7.5                  Lost to FU      0\n18     18  8.9                        Well      0\n19     19  9.5                  Lost to FU      0\n20     20 10.2                        Well      0<\/mark><\/em>\n<em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f50223\" class=\"has-inline-color\">survival_ankle &lt;- Surv(survivalankle$FU, survivalankle$Censor)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1802f4\" class=\"has-inline-color\">\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f5022c\" class=\"has-inline-color\">summary(survival_ankle)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1802f4\" class=\"has-inline-color\">\n      time            status   \n Min.   : 1.100   Min.   :0.0  \n 1st Qu.: 3.050   1st Qu.:0.0  \n Median : 5.800   Median :0.0  \n Mean   : 5.460   Mean   :0.1  \n 3rd Qu.: 7.325   3rd Qu.:0.0  \n Max.   :10.200   Max.   :1.0  \n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f50234\" class=\"has-inline-color\">ankle_curve &lt;- survfit(survival_ankle ~ 1, data=survivalankle, conf.int=0.95)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1802f4\" class=\"has-inline-color\">\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f5021b\" class=\"has-inline-color\">summary(ankle_curve)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1802f4\" class=\"has-inline-color\">\nCall: survfit(formula = survival_ankle ~ 1, data = survivalankle, conf.int = 0.95)\n\n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  5.3     12       1    0.917  0.0798        0.773            1\n  6.9      8       1    0.802  0.1279        0.587            1<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Plot the curve:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>par(mar=c(2,2,2,2)) # to increase plot margins in RStudio\nplot(ankle_curve, col='black', main='Kaplan Meier Curve', <\/em>\n  <em>xlab='Follow Up Duration', ylab='Cumulative Survival Probability')<\/em><\/mark><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"770\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q10-aseptic-1024x770.jpeg\" alt=\"\" class=\"wp-image-4417\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q10-aseptic-1024x770.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q10-aseptic-300x225.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q10-aseptic-768x577.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q10-aseptic.jpeg 1353w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Therefore, the 10 year survival is 80%.<\/p>\n\n\n\n<p>In the console:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f0053d\" class=\"has-inline-color\">summary(ankle_curve,time=10)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0b06f0\" class=\"has-inline-color\">\nCall: survfit(formula = survival_ankle ~ 1, data = survivalankle, conf.int = 0.95)\n\n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n   10      1       2    <strong>0.802<\/strong>   0.128        0.587            1<\/mark><\/em><\/code><\/pre>\n\n\n\n<p><strong>11. Calculate the 10-year Kaplan-Meier survival of the prosthesis using revision as \u2018hard end point\u2019.<\/strong><\/p>\n\n\n\n<p>All patients who had a <strong>\u2018Revision\u2019<\/strong> are counted as failures. The Kaplan-Meier table is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"488\" height=\"413\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-11.png\" alt=\"\" class=\"wp-image-3501\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-11.png 488w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-11-300x254.png 300w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/figure>\n\n\n\n<p>The 10-year Kaplan-Meier survival for revision is therefore 76%:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"233\" height=\"173\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-12.png\" alt=\"\" class=\"wp-image-3502\"\/><\/figure>\n\n\n\n<p>In R:<\/p>\n\n\n\n<p>Perform recoding similar as to above into a new variable &#8216;Censor2&#8217;, but now counting all revisions as failures and perform the analysis.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f80606\" class=\"has-inline-color\">survivalankle$Censor2 &lt;- ifelse(survivalankle$Outcome == 'Revised (aseptic loosening)', 1, 0)\nsurvivalankle$Censor2 &lt;- ifelse(survivalankle$Outcome == 'Revised (infection)', 1, survivalankle$Censor2)\nsurvivalankle<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#2609f1\" class=\"has-inline-color\">   Number   FU                     Outcome Censor Censor2\n1       1  1.1                        Well      0       0\n2       2  1.2         Revised (infection)      0       1\n3       3  1.9                        Well      0       0\n4       4  2.1                        Well      0       0\n5       5  2.9                        Well      0       0\n6       6  3.1                        Well      0       0\n7       7  3.9                        Well      0       0\n8       8  5.0                        Well      0       0\n9       9  5.3 Revised (aseptic loosening)      1       1\n10     10  5.5                        Well      0       0\n11     11  6.1                  Lost to FU      0       0\n12     12  6.3                        Well      0       0\n13     13  6.9 Revised (aseptic loosening)      1       1\n14     14  7.1                        Well      0       0\n15     15  7.3                  Lost to FU      0       0\n16     16  7.4                  Lost to FU      0       0\n17     17  7.5                  Lost to FU      0       0\n18     18  8.9                        Well      0       0\n19     19  9.5                  Lost to FU      0       0\n20     20 10.2                        Well      0       0<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Survival analysis:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f2071f\" class=\"has-inline-color\">survival_ankle &lt;- Surv(survivalankle$FU, survivalankle$Censor2)\nsurvival_ankle<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3507f3\" class=\"has-inline-color\">\n &#091;1]  1.1+  1.2   1.9+  2.1+  2.9+  3.1+  3.9+  5.0+  5.3   5.5+\n&#091;11]  6.1+  6.3+  6.9   7.1+  7.3+  7.4+  7.5+  8.9+  9.5+ 10.2+\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20717\" class=\"has-inline-color\">summary(survival_ankle)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3507f3\" class=\"has-inline-color\">\n      time            status    \n Min.   : 1.100   Min.   :0.00  \n 1st Qu.: 3.050   1st Qu.:0.00  \n Median : 5.800   Median :0.00  \n Mean   : 5.460   Mean   :0.15  \n 3rd Qu.: 7.325   3rd Qu.:0.00  \n Max.   :10.200   Max.   :1.00  \n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f20717\" class=\"has-inline-color\">ankle_curve &lt;- survfit(survival_ankle ~ 1, data=survivalankle, conf.int=0.95)\nsummary(ankle_curve)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3507f3\" class=\"has-inline-color\">\nCall: survfit(formula = survival_ankle ~ 1, data = survivalankle, conf.int = 0.95)\n\n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  1.2     19       1    0.947  0.0512        0.852            1\n  5.3     12       1    0.868  0.0890        0.710            1\n  6.9      8       1    0.760  0.1280        0.546            1<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Plot the curve:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>par(mar=c(2,2,2,2)) # to increase plot margins in RStudio\nplot(ankle_curve, col='black', main='Kaplan Meier Curve', <\/em>\n  <em>xlab='Follow Up Duration', ylab='Cumulative Survival Probability')<\/em><\/mark><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"770\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q11-revision-1024x770.jpeg\" alt=\"\" class=\"wp-image-4424\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q11-revision-1024x770.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q11-revision-300x225.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q11-revision-768x577.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q11-revision.jpeg 1353w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><a href=\"http:\/\/pcool.dyndns.org:8080\/statsbook\/wp-content\/uploads\/Q11.png\"><\/a>Therefore, the 10 year survival is 76%.<\/p>\n\n\n\n<p><strong>12. Calculate the 10-year <em>worst-case scenario<\/em> Kaplan-Meier survival of the prosthesis using revision as \u2018hard end point\u2019.<\/strong><\/p>\n\n\n\n<p>In the <strong><em>worst-case scenario<\/em><\/strong>, all patients who are lost to follow up are also counted as a failure:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"493\" height=\"495\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-13.png\" alt=\"\" class=\"wp-image-3503\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-13.png 493w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-13-300x300.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-13-150x150.png 150w\" sizes=\"auto, (max-width: 493px) 100vw, 493px\" \/><\/figure>\n\n\n\n<p><a href=\"http:\/\/pcool.dyndns.org:8080\/statsbook\/wp-content\/uploads\/Q9-13.png\"><\/a>The <em>worst-case scenario <\/em>10-year Kaplan-Meier survival for revision is therefore 17%:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"245\" height=\"176\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q9-14.png\" alt=\"\" class=\"wp-image-3504\"\/><\/figure>\n\n\n\n<p>In R:<\/p>\n\n\n\n<p>Again, perform recoding similar to above into a new variable called &#8216;Censor3&#8217;, now counting all revisions and all patients lost to follow up as a failure.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30606\" class=\"has-inline-color\">survivalankle$Censor3 &lt;- ifelse(survivalankle$Outcome == 'Revised (aseptic loosening)', 1, 0)\nsurvivalankle$Censor3 &lt;- ifelse(survivalankle$Outcome == 'Revised (infection)', 1, survivalankle$Censor3)\nsurvivalankle$Censor3 &lt;- ifelse(survivalankle$Outcome == 'Lost to FU', 1, survivalankle$Censor3)\nsurvivalankle<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0);color:#4a03f1\" class=\"has-inline-color\">   Number   FU                     Outcome Censor Censor2 Censor3\n1       1  1.1                        Well      0       0       0\n2       2  1.2         Revised (infection)      0       1       1\n3       3  1.9                        Well      0       0       0\n4       4  2.1                        Well      0       0       0\n5       5  2.9                        Well      0       0       0\n6       6  3.1                        Well      0       0       0\n7       7  3.9                        Well      0       0       0\n8       8  5.0                        Well      0       0       0\n9       9  5.3 Revised (aseptic loosening)      1       1       1\n10     10  5.5                        Well      0       0       0\n11     11  6.1                  Lost to FU      0       0       1\n12     12  6.3                        Well      0       0       0\n13     13  6.9 Revised (aseptic loosening)      1       1       1\n14     14  7.1                        Well      0       0       0\n15     15  7.3                  Lost to FU      0       0       1\n16     16  7.4                  Lost to FU      0       0       1\n17     17  7.5                  Lost to FU      0       0       1\n18     18  8.9                        Well      0       0       0\n19     19  9.5                  Lost to FU      0       0       1\n20     20 10.2                        Well      0       0       0<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Perform survival analysis:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#ed072e\" class=\"has-inline-color\">survival_ankle = Surv(survivalankle$FU, survivalankle$Censor3)\nsurvival_ankle<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#4307ee\" class=\"has-inline-color\">\n &#091;1]  1.1+  1.2   1.9+  2.1+  2.9+  3.1+  3.9+  5.0+  5.3   5.5+\n&#091;11]  6.1   6.3+  6.9   7.1+  7.3   7.4   7.5   8.9+  9.5  10.2+\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#ed0726\" class=\"has-inline-color\">summary(survival_ankle)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#4307ee\" class=\"has-inline-color\">\n      time            status   \n Min.   : 1.100   Min.   :0.0  \n 1st Qu.: 3.050   1st Qu.:0.0  \n Median : 5.800   Median :0.0  \n Mean   : 5.460   Mean   :0.4  \n 3rd Qu.: 7.325   3rd Qu.:1.0  \n Max.   :10.200   Max.   :1.0  \n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#ed070f\" class=\"has-inline-color\">ankle_curve &lt;- survfit(survival_ankle ~ 1, data=survivalankle, conf.int=0.95)\nsummary(ankle_curve)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#4307ee\" class=\"has-inline-color\">\nCall: survfit(formula = survival_ankle ~ 1, data = survivalankle, conf.int = 0.95)\n\n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  1.2     19       1    0.947  0.0512       0.8521        1.000\n  5.3     12       1    0.868  0.0890       0.7104        1.000\n  6.1     10       1    0.782  0.1149       0.5859        1.000\n  6.9      8       1    0.684  0.1359       0.4633        1.000\n  7.3      6       1    0.570  0.1538       0.3358        0.967\n  7.4      5       1    0.456  0.1598       0.2294        0.906\n  7.5      4       1    0.342  0.1552       0.1404        0.833\n  9.5      2       1    0.171  0.1437       0.0329        0.888<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Plot the survival curve:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>par(mar=c(2,2,2,2)) # to increase plot margins in RStudio\nplot(ankle_curve, col='black', main='Kaplan Meier Curve', <\/em>\n  <em>xlab='Follow Up Duration', ylab='Cumulative Survival Probability')<\/em><\/mark><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"772\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q12-worse-1024x772.jpeg\" alt=\"\" class=\"wp-image-4425\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q12-worse-1024x772.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q12-worse-300x226.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q12-worse-768x579.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q12-worse.jpeg 1353w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Again, giving the result 17%.<\/p>\n\n\n\n<p>These questions illustrate the importance of choosing a \u2018hard end point\u2019. They also show that if all patients lost to follow up are counted as a failure (<em>worst-case scenario<\/em>), the survival curve drops steeply.<\/p>\n\n\n\n<p>There was not much difference in the 10-year survival for \u2018revision\u2019 and \u2018revision for aseptic loosening\u2019. This is because the one patient who had an infection had this relatively early (at 1.2 years). At this time there were 18 patients who had a longer follow up. Consequently, the effect on the failure rate (1 out of 19) is not as big as it would have been if only 1 patient had a longer follow up (1 out of 2).<\/p>\n\n\n\n<p><strong>So, a failure at the \u2018tail end\u2019 (longer follow up) of the survival curve has a far more pronounced effect on the cumulative survival than a failure at the beginning (short follow up).<\/strong><\/p>\n\n\n\n<p><strong>13. The plot can be created using console with the survival<sup class='sup-ref-note' id='note-zotero-ref-p1196-r2-o1'><a class='sup-ref-note' href='#zotero-ref-p1196-r2'>2<\/a><\/sup> package .<\/strong><\/p>\n\n\n\n<p>Download the <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/survivalhip1.rda\">data<\/a> and perform the analysis:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f60435\" class=\"has-inline-color\">load(\"\/path\/to_file\/survivalhip1.rda\")\nsurvivalhip1<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3207c3\" class=\"has-inline-color\">\n   Number   FU Censor Group\n1       1  5.1  FALSE Hip 1\n2       2  6.4   TRUE Hip 1\n3       3  7.8   TRUE Hip 1\n4       4  8.2   TRUE Hip 1\n5       5  9.3   TRUE Hip 1\n6       6 10.4  FALSE Hip 1\n7       7 10.5   TRUE Hip 1\n8       8 10.7  FALSE Hip 1\n9       9 10.9   TRUE Hip 1\n10     10 11.1  FALSE Hip 1\n11     11  4.6  FALSE Hip 2\n12     12  5.2  FALSE Hip 2\n13     13  6.9  FALSE Hip 2\n14     14  7.6  FALSE Hip 2\n15     15  8.1  FALSE Hip 2\n16     16  8.4  FALSE Hip 2\n17     17  8.9  FALSE Hip 2\n18     18  9.7   TRUE Hip 2\n19     19 10.6   TRUE Hip 2\n20     20 11.3  FALSE Hip 2\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f40626\" class=\"has-inline-color\">hip_survival &lt;- Surv(survivalhip1$FU, survivalhip1$Censor)\nhip_survival<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3207c3\" class=\"has-inline-color\">\n &#091;1]  5.1+  6.4   7.8   8.2   9.3  10.4+ 10.5  10.7+ 10.9  11.1+\n&#091;11]  4.6+  5.2+  6.9+  7.6+  8.1+  8.4+  8.9+  9.7  10.6  11.3+\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f80c24\" class=\"has-inline-color\">summary(hip_survival)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3207c3\" class=\"has-inline-color\">\n      time            status   \n Min.   : 4.600   Min.   :0.0  \n 1st Qu.: 7.425   1st Qu.:0.0  \n Median : 8.650   Median :0.0  \n Mean   : 8.585   Mean   :0.4  \n 3rd Qu.:10.525   3rd Qu.:1.0  \n Max.   :11.300   Max.   :1.0  \n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f60a01\" class=\"has-inline-color\">hip_curve &lt;- survfit(hip_survival ~ Group, data=survivalhip1, conf.int=0.95)\nsummary(hip_curve)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3207c3\" class=\"has-inline-color\">\nCall: survfit(formula = hip_survival ~ Group, data = survivalhip1, \n    conf.int = 0.95)\n\n                Group=Hip 1 \n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  6.4      9       1    0.889   0.105       0.7056        1.000\n  7.8      8       1    0.778   0.139       0.5485        1.000\n  8.2      7       1    0.667   0.157       0.4200        1.000\n  9.3      6       1    0.556   0.166       0.3097        0.997\n 10.5      4       1    0.417   0.173       0.1847        0.940\n 10.9      2       1    0.208   0.171       0.0418        1.000\n\n                Group=Hip 2 \n time n.risk n.event survival std.err lower 95% CI upper 95% CI\n  9.7      3       1    0.667   0.272       0.2995            1\n 10.6      2       1    0.333   0.272       0.0673            1<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Plot the curve:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f30505\" class=\"has-inline-color\"><em>par(mar=c(2,2,2,2)) # to increase plot margins in RStudio\nplot(hip_curve, col=c('red', 'blue'), main='Kaplan Meier Curve', <\/em>\n  <em>xlab='Follow Up Duration', ylab='Cumulative Survival Probability')<\/em><\/mark><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"772\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q13-hips-1024x772.jpeg\" alt=\"\" class=\"wp-image-4431\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q13-hips-1024x772.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q13-hips-300x226.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q13-hips-768x579.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q13-hips.jpeg 1353w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"is-style-text-annotation is-style-text-annotation--3\">Hip 1 is red and Hip 2 is blue<\/p>\n\n\n\n<p>R labels the curves alphabetically and it may be necessary to check which curve is which or add a legend (i.e. with the survminer<sup class='sup-ref-note' id='note-zotero-ref-p1196-r3-o1'><a class='sup-ref-note' href='#zotero-ref-p1196-r3'>3<\/a><\/sup> package). From the output above, it can be seen that there were 6 failures in &#8216;Hip 1&#8217; and two failures in &#8216;Hip 2&#8217;. Therefore, There should be 6 steps in the red curve and only two in the blue which is correct. The drops in the curve are steeper for &#8216;Hip 2&#8217; because 7 patients were censored at the time of the first failure.<\/p>\n\n\n\n<p><strong>14. This can be done using the console and the survival package<sup class='sup-ref-note' id='note-zotero-ref-p1196-r4-o1'><a class='sup-ref-note' href='#zotero-ref-p1196-r4'>4<\/a><\/sup>.<\/strong><\/p>\n\n\n\n<p>Using the hip_survival object from question 13:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f40626\" class=\"has-inline-color\">hip_survival &lt;- Surv(survivalhip1$FU, survivalhip1$Censor)\nhip_survival<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3207c3\" class=\"has-inline-color\">\n &#091;1]  5.1+  6.4   7.8   8.2   9.3  10.4+ 10.5  10.7+ 10.9  11.1+\n&#091;11]  4.6+  5.2+  6.9+  7.6+  8.1+  8.4+  8.9+  9.7  10.6  11.3+\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f80c24\" class=\"has-inline-color\">summary(hip_survival)<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3207c3\" class=\"has-inline-color\">\n      time            status   \n Min.   : 4.600   Min.   :0.0  \n 1st Qu.: 7.425   1st Qu.:0.0  \n Median : 8.650   Median :0.0  \n Mean   : 8.585   Mean   :0.4  \n 3rd Qu.:10.525   3rd Qu.:1.0  \n Max.   :11.300   Max.   :1.0  <\/mark><\/em>\n<\/code><\/pre>\n\n\n\n<p>Perform the logrank test:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>hip_logrank &lt;- survdiff(hip_survival ~ Group, data=survivalhip1)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>hip_logrank<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Call:<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>survdiff(formula = hip_survival ~ Group, data = survivalhip1)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; N Observed Expected (O-E)^2\/E (O-E)^2\/V<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Group=Hip 1 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6&nbsp;&nbsp;&nbsp;&nbsp; 4.91&nbsp;&nbsp;&nbsp;&nbsp; 0.242&nbsp;&nbsp;&nbsp;&nbsp; 0.634<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Group=Hip 2 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 3.09&nbsp;&nbsp;&nbsp;&nbsp; 0.385&nbsp;&nbsp;&nbsp;&nbsp; 0.634<\/em><\/span>\n\n<span style=\"color: #ff0000;\"><em><span style=\"color: #0000ff;\">Chisq= 0.6&nbsp; on 1 degrees of freedom, <strong>p= 0.4<\/strong><\/span> <\/em><\/span><\/code><\/pre>\n\n\n\n<p>Perform Cox Proportional Hazards:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>hip_coxph &lt;- coxph(hip_survival ~ Group, data=survivalhip1)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>hip_coxph<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Call:<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>coxph(formula = hip_survival ~ Group, data = survivalhip1)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; coef exp(coef) se(coef)&nbsp;&nbsp;&nbsp;&nbsp; z&nbsp;&nbsp;&nbsp; p<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>GroupHip 2 -0.642&nbsp;&nbsp;&nbsp;&nbsp; 0.526&nbsp;&nbsp;&nbsp; 0.820 -0.78 0.43<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Likelihood ratio test=0.67&nbsp; on 1 df, <strong>p=0.412<\/strong><\/em><\/span>\n<span style=\"color: #ff0000;\"><em><span style=\"color: #0000ff;\">n= 20, number of events= 8<\/span> <\/em><\/span><\/code><\/pre>\n\n\n\n<p>And parametric Weibull:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>hip_parametric &lt;- survreg(hip_survival ~ Group , dist = \"weibull\"<\/em><\/span><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fa0808\" class=\"has-inline-color\">, <\/mark><\/em>\n  <em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fa0808\" class=\"has-inline-color\">data=survivalhip1)<\/mark><\/em>\n<span style=\"color: #ff0000;\"><em>hip_parametric<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Call:<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>survreg(formula = hip_survival ~ Group, data = survivalhip1,<\/em><\/span>\n    <span style=\"color: #0000ff;\"><em>dist = \"weibull\")<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Coefficients:<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>(Intercept)&nbsp; GroupHip 2 <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;2.36525220&nbsp; 0.08988363 <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Scale= 0.1416005 <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Loglik(model)= -20.5&nbsp;&nbsp; Loglik(intercept only)= -20.8<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp; &nbsp;Chisq= 0.66 on 1 degrees of freedom, <strong>p= 0.4<\/strong><\/em><\/span><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#200bf6\" class=\"has-inline-color\">16<\/mark><\/strong>\n<span style=\"color: #ff0000;\"><em><span style=\"color: #0000ff;\">n= 20<\/span> <\/em><\/span><\/code><\/pre>\n\n\n\n<p>Similarly, perform the exponential parametric test which should show the following output (parts omitted for brevity):<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>hip_parametric &lt;- survreg(hip_survival ~ Group , dist = \"<span style=\"color: #ff0000;\"><em>exponential<\/em><\/span>\"<\/em><\/span><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fa0808\" class=\"has-inline-color\">, <\/mark><\/em>\n<em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fa0808\" class=\"has-inline-color\">  data=survivalhip1)<\/mark><\/em>\n<span style=\"color: #ff0000;\"><em>hip_parametric<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Call:<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>survreg(formula = hip_survival ~ Group, data = survivalhip1,<\/em><\/span>\n    <span style=\"color: #0000ff;\"><em>dist = \"exponential\")<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Coefficients:<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>(Intercept)&nbsp; GroupHip 2 <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp; 2.712485&nbsp;&nbsp;&nbsp; 0.992514 <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Scale fixed at 1 <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Loglik(model)= -31.7&nbsp;&nbsp; Loglik(intercept only)= -32.5<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp; &nbsp;Chisq= 1.69 on 1 degrees of freedom, <strong>p= 0.193<\/strong> <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>n= 20<\/em><\/span><\/code><\/pre>\n\n\n\n<p>There is no statistical significant difference using the log rank test (p=0.42), cox proportional hazards model (p=0.412) and parametric regression analysis using the exponential (p=0.193) and Weibull (p=0.416) distributions between the survival curves of both hips. Therefore, the null hypothesis can&#8217;t be rejected and it should be concluded that there is no difference in the outcome of both hips.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The table below shows 20 patients who have been diagnosed with cancer. The first column shows the follow up (in years) of the patients who were alive at review. In the second column, the follow up till time of death is indicated. The third column shows the time to last review in the patients who [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-1196","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=1196"}],"version-history":[{"count":29,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1196\/revisions"}],"predecessor-version":[{"id":4447,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1196\/revisions\/4447"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=1196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}