---
title: "Biostatistics III in R"
author:
- Code by Annika Tillander, Andreas Karlsson and Mark Clements
output:
  prettydoc::html_pretty:
    theme: cayman
    highlight: github
---

## Exercise 4. Localised melanoma: Comparing actuarial and Kaplan-Meier approaches with discrete time data ##

The aim of this exercise is to examine the effect of heavily grouped data (i.e., data with lots of ties) on estimates of survival made using the Kaplan-Meier method and the actuarial method.

For the patients diagnosed with localised skin melanoma, estimate the 10-year cause-specific survival proportion. Use both the Kaplan-Meier method and the actuarial method. Do this both with survival time recorded in completed years and survival time recorded in completed months. That is, you should obtain 4 separate estimates of the 10-year cause-specific survival proportion to complete the cells of the following table. The purpose of this exercise is to illustrate small differences between the two methods when there are large numbers of ties.

In order to reproduce the results in the printed solutions you’ll need to restrict to localised stage and estimate cause-specific survival ("Dead: cancer" indicates an event). Look at the code in the previous questions if you are unsure.

```{r setup, cache=FALSE, message=FALSE, echo=FALSE}
library('knitr')
read_chunk('../q4.R')
opts_chunk$set(cache=FALSE)
```

You may have to install the required packages the first time you use them. You can install a package by `install.packages("package_of_interest")` for each package you require.

```{r loadDependencies, message=FALSE}
```

```{r loadPreprocess, results="hide", fig.show="hide"}
```

## (a) ##

Of the two estimates (Kaplan-Meier and actuarial) made using time recorded in years, which do you think is the most appropriate and why? [HINT: Consider how each of the methods handle ties.]


Actuarial method, using survival time in completed years.

```{r actuarialYears, results="hide", fig.show="hide"}
```

Actuarial method, using survival time in completed months. Only showing 20 months around the 10th year.

```{r actuarialMonths, results="hide", fig.show="hide"}
```


## (b) ##

Which of the two estimates (Kaplan-Meier or actuarial) changes most when using survival time in months rather than years? Why?

Kaplan-Meier estimates, using survival time in completed  years.

```{r kmYears, results="hide", fig.show="hide"}
```

Kaplan-Meier estimates, using survival time in completed months. Only showing 20 months around the 10th year.

```{r kmMonths, results="hide", fig.show="hide"}
```

## (c) ##

Plot the four sets of curves for a graphical comparison. Describe the direction of the bias for the Kaplan-Meier curves using completed years.

```{r comparisonPlot, results="hide", fig.show="hide"}
```
