# Biostatistics III in R

#### Code by Johan Zetterqvist and Mark Clements

# Exercise 11. Cox regression with all-cause mortality as the outcome

Now fit a model to the localised melanoma data where the outcome is observed survival (i.e. all deaths are considered to be events).

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

Load the melanoma data and explore it.

    ## Read melanoma data
    ## and select subcohorts
    data(melanoma)
    melanoma.l <- melanoma %>%
      filter(stage=="Localised") %>%
      mutate(
        ## Create a death indicator
        death_cancer = as.numeric(status=="Dead: cancer"),
        death_any = as.numeric(status=="Dead: cancer" | status=="Dead: other") )

    ## Truncate follow-up time

    melanoma.l2 <-
      mutate(melanoma.l,
             ## Create new death indicators (only count deaths within 120 months)
             death_cancer = death_cancer * as.numeric( surv_mm <= 120),
             death_any = death_any * as.numeric( surv_mm <= 120),
             ## Create a new time variable
             surv_mm = pmin(surv_mm, 120))

## (a)

Interpret the estimated hazard ratio for the parameter labelled 2.agegrp, including a comment on statistical significance.

    summary( coxfit11a <- coxph(Surv(surv_mm, death_any) ~ sex + year8594 + agegrp,
                               data = melanoma.l2) )

## (b)

On comparing the estimates between the observed and cause-specific survival models it appears that only the parameters for age have changed substantially. Can you explain why the estimates for the effect of age would be expected to change more than the estimates of the effect of sex and period?

    summary( coxfit11b <- coxph(Surv(surv_mm, death_cancer) ~ sex + year8594 + agegrp,
                               data = melanoma.l2) )