# Biostatistics III in R

#### Code by Xing-Rong Liu and Mark Clements

## Exercise 28. Flexible parametric survival models in R

    library(biostat3)
    library(rstpm2)  # for the flexible parametric model
    library(dplyr)   # for data manipulation

    data(melanoma)

    ## Extract subset and create 0/1 outcome variables
    melanoma0 <- melanoma %>% filter(stage=="Localised") %>%
                 mutate(event = ifelse(status=="Dead: cancer" & surv_mm<120, 1, 0),
                        time = pmin(120, surv_mm)/12,
                        agegrp1 = (agegrp=="0-44")+0,  # used by time-dependent effect
                        agegrp2 = (agegrp=="45-59")+0, # used by time-dependent effect
                        agegrp3 = (agegrp=="60-74")+0, # used by time-dependent effect
                        agegrp4 = (agegrp=="75+")+0)   # used by time-dependent effect

## (a)