Overview

Population time plots can be extremely informative graphical displays of survival data. They should be the first step in your exploratory data analyses. We facilitate this task in the casebase package by providing a plot method for objects returned by the popTime function. This is done in two steps:

  1. Pass your dataset to the casebase::popTime function and specify the column names corresponding to
  • the time of event
  • the event status
  • exposure (optional)

This will create an object of class popTime (or popTimeExposure if you specify a value for the exposure argument)

  1. Pass the object of class popTime (or popTimeExposure) to the plot function

In this vignette we show how to create population-time plots for the two datasets that ship with the casebase package, as well as several well known survival datasets from the survival package.

Load Required Packages

library(survival)
library(casebase)
library(data.table)

European Randomized Study of Prostate Cancer Screening Data

For our first example, we make use of the European Randomized Study of Prostate Cancer Screening (ERSPC) data which ships with the casebase package (see help("ERSPC", package = "casebase") for details about this data).

data("ERSPC")
head(ERSPC)
##   ScrArm Follow.Up.Time DeadOfPrCa
## 1      1         0.0027          0
## 2      1         0.0027          0
## 3      1         0.0027          0
## 4      0         0.0027          0
## 5      0         0.0027          0
## 6      0         0.0027          0
# Appropriately label the factor variable so that these labels appear in the 
# stratified population time plot
ERSPC$ScrArm <- factor(ERSPC$ScrArm, 
                       levels = c(0,1), 
                       labels = c("Control group", "Screening group"))

We first pass this dataset to the popTime function. If you do not specify the time and event arguments, this function will try to guess them using regular expressions. See the Details section of help("popTime", package = "casebase") for how we try to guess these inputs.

pt_object <- casebase::popTime(ERSPC, event = "DeadOfPrCa")
## 'Follow.Up.Time' will be used as the time variable

We can see its contents and its class:

head(pt_object)
##             ScrArm   time event original.time original.event event status
## 1: Screening group 0.0027     0        0.0027              0     censored
## 2: Screening group 0.0027     0        0.0027              0     censored
## 3: Screening group 0.0027     0        0.0027              0     censored
## 4:   Control group 0.0027     0        0.0027              0     censored
## 5:   Control group 0.0027     0        0.0027              0     censored
## 6:   Control group 0.0027     0        0.0027              0     censored
##    ycoord yc n_available
## 1: 159893  0           0
## 2: 159892  0           0
## 3: 159891  0           0
## 4: 159890  0           0
## 5: 159889  0           0
## 6: 159888  0           0
class(pt_object)
## [1] "popTime"    "data.table" "data.frame"

The casebase package has a plot method for objects of class popTime:

# plot method for objects of class 'popTime'
plot(pt_object)