# Biostatistics III in R

#### Code by Annika Tillander, Andreas Karlsson and Mark Clements

# Exercise 3. Localised melanoma: Comparing estimates of cause-specific survival between periods; first graphically and then using the log rank test

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.

    library(biostat3)
    library(dplyr)    # for data manipulation

We will now analyse the full data set of patients diagnosed with localised skin melanoma. We start by reading the data selecting those with a localised stage and then define a 1/0 varible for the events that we are interested in.

    melanoma <- biostat3::melanoma %>%
        filter(stage=="Localised") %>% # subset those with localised cancer
        mutate(death_cancer = ifelse( status == "Dead: cancer", 1, 0),
               death_all = ifelse( status == "Dead: cancer" |
                                   status == "Dead: other", 1, 0))

## (a)

Estimate the cause-specific survivor function, using the Kaplan-Meier method with survival time in months, separately for each of the two calendar periods 1975–1984 and 1985–1994. The variable year8594 indicates whether a patient was diagnosed 1985–1994 or 1975–1984. Without making reference to any formal statistical tests, does it appear that patient survival is superior during the most recent period?

    mfityear8594 <- survfit(Surv(surv_mm, death_cancer==1) ~ year8594, data = melanoma)

    plot(mfityear8594, col = 1:2,
         xlab = "Follow-up Time",
         ylab = "Survival",
         main = "Kaplan-Meier survival estimates")
    legend("bottomleft", levels(melanoma$year8594), col=1:2, lty = 1)

There seems to be a clear difference in survival between the two periods. Patients diagnosed during 1985–94 have superior survival to those diagnosed 1975–84.

## (b)

The following commands can be used to plot the hazard function (instantaneous mortality rate): i. At what point in the follow-up is mortality highest? ii. Does this pattern seem reasonable from a clinicial/biological perspective? [HINT:Consider the disease with which these patients were classified as being diagnosed along with the expected fatality of the disease as a function of time since diagnosis.]

    plot(muhaz2(Surv(surv_mm,death_cancer)~year8594, data=melanoma))

## (c)

Use the log rank and the Wilcoxon test to determine whether there is a statistically significant difference in patient survival between the two periods.

    ## Log-rank test for equality of survivor functions
    survdiff(Surv(surv_mm, death_cancer) ~ year8594, data=melanoma)
    ## Equivalent to the Peto & Peto modfication of the Gehan-Wilcoxon test
    survdiff(Surv(surv_mm, death_cancer) ~ year8594, data=melanoma, rho=1)

Haven’t heard of the log rank test? It’s possible you may reach this exercise before we cover the details of this test during lectures. You should nevertheless do the exercise and try and interpret the results. Both of these tests (the log rank and the generalised Wilcoxon) are used to test for differences between the survivor functions. The null hypothesis is that the survivor functions are equivalent for the two calendar periods (i.e., patient survival does not depend on calendar period of diagnosis).

## (d)

Estimate cause-specific mortality rates for each age group, and graph Kaplan-Meier estimates of the cause-specific survivor function for each age group. Are there differences between the age groups? Is the interpretation consistent between the mortality rates and the survival proportions?

    survRate(Surv(surv_mm,death_cancer)~year8594, data=melanoma)
    melanoma %>%
        select(death_cancer, surv_mm, agegrp) %>%
        group_by(agegrp) %>%
        summarise(D = sum(death_cancer), Y = sum(surv_mm)/1000, Rate = D/Y,
                  CI_low = stats::poisson.test(D,Y)$conf.int[1],
                  CI_high = stats::poisson.test(D,Y)$conf.int[2])

    mfit_agegrp <- survfit(Surv(surv_mm, death_cancer) ~ agegrp, data = melanoma)
    plot(mfit_agegrp, col = 1:4,
         xlab = "Months since diagnosis",
         ylab = "Survival",
         main = "Kaplan-Meier survival estimates")
    legend("bottomleft", levels(melanoma$agegrp), col=1:4, lty = 1)

What are the units of the estimated hazard rates? HINT: look at how you defined time.

## (e)

Repeat some of the previous analyses using years instead of months. This is equivalent to dividing the time variable by 12 so all analyses will be the same except the units of time will be different (e.g., the graphs will have different labels).

    mfit_agegrp_year <- survfit(Surv(surv_mm/12, death_cancer) ~ agegrp, data = melanoma)
    plot(mfit_agegrp_year, col = 1:4,
         xlab = "Years since diagnosis",
         ylab = "Survival",
         main = "Kaplan-Meier survival estimates")
    legend("bottomleft", levels(melanoma$agegrp), col=1:4, lty = 1)

    survRate(Surv(surv_mm/12/1000,death_cancer)~year8594, data=melanoma)

## (f)

Study whether there is evidence of a difference in patient survival between males and females. Estimate both the hazard and survival function and use the log rank test to test for a difference.

    par(mfrow=c(1, 2))
    mfit_sex <- survfit(Surv(surv_mm, death_cancer) ~ sex, data = melanoma)
    plot(mfit_sex, col = 1:2,
         xlab = "Follow-up Time",
         ylab = "Survival",
         main = "Kaplan-Meier survival estimates")
    plot(muhaz2(Surv(surv_mm,death_cancer)~sex, data=melanoma))

    ## Log-rank test for equality of survivor functions
    survdiff(Surv(surv_mm, death_cancer==1) ~ sex, data=melanoma)