<- requireNamespace("eha", quietly = TRUE) &&
evaluate_vignette requireNamespace("visreg", quietly = TRUE) &&
requireNamespace("splines", quietly = TRUE)
::opts_chunk$set(eval = evaluate_vignette) knitr
Case-base sampling was proposed by Hanley and Miettinen, 2009 as a way to fit smooth-in-time parametric hazard functions via logistic regression. The main idea, which was first proposed by Mantel, 1973 and then later developed by Efron, 1977, is to sample person-moments, i.e. discrete time points along an subject’s follow-up time, in order to construct a base series against which the case series can be compared.
This approach allows the explicit inclusion of the time variable into the model, which enables the user to fit a wide class of parametric hazard functions. For example, including time linearly recovers the Gompertz hazard, whereas including time logarithmically recovers the Weibull hazard; not including time at all corresponds to the exponential hazard.
The theoretical properties of this approach have been studied in Saarela and Arjas, 2015 and Saarela, 2015.
veteran
datasetThe first example we discuss uses the well-known veteran
dataset, which is part of the survival
package. As we can
see below, there is almost no censoring, and therefore we can get a good
visual representation of the survival function:
set.seed(12345)
library(casebase)
library(survival)
data(veteran)
table(veteran$status)
<- veteran$time[veteran$status == 1]
evtimes hist(evtimes, nclass = 30, main = '', xlab = 'Survival time (days)',
col = 'gray90', probability = TRUE)
<- seq(0, 1000, by = 10)
tgrid lines(tgrid, dexp(tgrid, rate = 1.0/mean(evtimes)),
lwd = 2, lty = 2, col = 'red')
As we can see, the empirical survival function resembles an exponential distribution.
We will first try to estimate the hazard function parametrically using some well-known regression routines. But first, we will reformat the data slightly.
$prior <- factor(veteran$prior, levels = c(0, 10), labels = c("no","yes"))
veteran$celltype <- factor(veteran$celltype,
veteranlevels = c('large', 'squamous', 'smallcell', 'adeno'))
$trt <- factor(veteran$trt, levels = c(1, 2), labels = c("standard", "test")) veteran
Using the eha
package, we can fit a Weibull form, with
different values of the shape parameter. For shape = 1
, we
get an exponential distribution:
library(eha)
<- with(veteran, Surv(time, status))
y
<- weibreg(y ~ karno + diagtime + age + prior + celltype + trt,
model1 data = veteran, shape = 1)
summary(model1)
If we take shape = 0
, the shape parameter is estimated
along with the regression coefficients:
<- weibreg(y ~ karno + diagtime + age + prior + celltype + trt,
model2 data = veteran, shape = 0)
summary(model2)
Finally, we can also fit a Cox proportional hazard:
<- coxph(y ~ karno + diagtime + age + prior + celltype + trt,
model3 data = veteran)
summary(model3)
As we can see, all three models are significant, and they give
similar information: karno
and celltype
are
significant predictors, both treatment is not.
The method available in this package makes use of case-base sampling. That is, person-moments are randomly sampled across the entire follow-up time, with some moments corresponding to cases and others to controls. By sampling person-moments instead of individuals, we can then use logistic regression to fit smooth-in-time parametric hazard functions. See the previous section for more details.
First, we will look at the follow-up time by using population-time plots:
# create popTime object
<- popTime(data = veteran)
pt_veteran
class(pt_veteran)
# plot method for objects of class 'popTime'
plot(pt_veteran)
Population-time plots are a useful way of visualizing the total follow-up experience, where individuals appear on the y-axis, and follow-up time on the x-axis; each individual’s follow-up time is represented by a gray line segment. For convenience, we have ordered the patients according to their time-to-event, and each event is represented by a red dot. The censored observations (of which there is only a few) correspond to the grey lines which do not end with a red dot.
Next, we use case-base sampling to fit a parametric hazard function via logistic regression. First, we will include time as a linear term; as noted above, this corresponds to an Gompertz hazard.
<- fitSmoothHazard(status ~ time + karno + diagtime + age + prior +
model4 + trt, data = veteran, ratio = 100)
celltype summary(model4)
Since the output object from fitSmoothHazard
inherits
from the glm
class, we see a familiar result when using the
function summary
. We can quickly visualize the conditional
association between each predictor and the hazard function using the
plot
method for objects that are fit with
fitSmoothHazard
. Specifically, if \(x\) is the predictor of interest, \(h\) is the hazard function, and \(\mathbf{x_{-j}}\) the other predictors in
the model, the conditional association plot represents the relationship
\(f(x) = \mathbb{E}(h|x,
\mathbf{x_{-j}})\). By default, the other terms in the model
(\(\mathbf{x_{-j}}\)) are set to their
median if the term is numeric or the most common category if the term is
a factor. Further details of customizing these plots are given in the
Plot Hazards and Hazard Ratios
vignette.
library(visreg)
plot(model4,
hazard.params = list(alpha = 0.05))
The main purpose of fitting smooth hazard functions is that it is
then relatively easy to compute absolute risks. For example, we can use
the function absoluteRisk
to compute the mean absolute risk
at 90 days, which can then be compared to the empirical measure.
<- absoluteRisk(object = model4, time = 90)
absRisk4 mean(absRisk4)
<- veteran$time
ftime mean(ftime <= 90)
We can also fit a Weibull hazard by using a logarithmic term for time:
<- fitSmoothHazard(status ~ log(time) + karno + diagtime + age + prior +
model5 + trt, data = veteran, ratio = 100)
celltype summary(model5)
With case-base sampling, it is straightforward to fit a semi-parametric hazard function using splines, which can then be used to estimate the mean absolute risk.
# Fit a spline for time
library(splines)
<- fitSmoothHazard(status ~ bs(time) + karno + diagtime + age + prior +
model6 + trt, data = veteran, ratio = 100)
celltype summary(model6)
str(absoluteRisk(object = model6, time = 90))
As we can see from the summary, there is little evidence that splines actually improve the fit. Moreover, we can see that estimated individual absolute risks are essentially the same when using either a linear term or splines:
<- absoluteRisk(object = model4, time = 90, newdata = veteran)
linearRisk <- absoluteRisk(object = model6, time = 90, newdata = veteran)
splineRisk
plot.default(linearRisk, splineRisk,
xlab = "Linear", ylab = "Splines", pch = 19)
abline(a = 0, b = 1, lty = 2, lwd = 2, col = 'red')
These last three models give similar information as the first three,
i.e. the main predictors for the hazard are karno
and
celltype
, with treatment being non-significant. Moreover,
by explicitly including the time variable in the formula, we see that it
is not significant; this is evidence that the true hazard is
exponential.
Finally, we can look at the estimates of the coefficients for the Cox model, as well as the last three models (CB stands for “case-base”):
Here we show how to calculate the cumulative incidence curves for a specific risk profile using the following equation:
\[ CI(x, t) = 1 - exp\left[ - \int_0^t h(x, u) \textrm{d}u \right] \] where \( h(x, t) \) is the hazard function, \( t \) denotes the numerical value (number of units) of a point in prognostic/prospective time and \( x \) is the realization of the vector \( X \) of variates based on the patient’s profile and intervention (if any).
We compare the cumulative incidence functions from the fully-parametric fit using case base sampling, with those from the Cox model:
# define a specific covariate profile
<- data.frame(trt = "test",
new_data celltype = "adeno",
karno = median(veteran$karno),
diagtime = median(veteran$diagtime),
age = median(veteran$age),
prior = "no")
# calculate cumulative incidence using casebase model
<- absoluteRisk(object = model4,
smooth_risk time = seq(0,300, 1),
newdata = new_data)
<- c("#8E063B","#023FA5")
cols
# cumulative incidence function for the Cox model
plot(survfit(model3, newdata = new_data),
xlab = "Days", ylab = "Cumulative Incidence (%)", fun = "event",
xlim = c(0,300), conf.int = F, col = cols[1],
main = sprintf("Estimated Cumulative Incidence (risk) of Lung Cancer\ntrt = test, celltype = adeno, karno = %g,\ndiagtime = %g, age = %g, prior = no", median(veteran$karno), median(veteran$diagtime),
median(veteran$age)))
# add casebase curve with legend
plot(smooth_risk, add = TRUE, col = cols[2], gg = FALSE)
legend("bottomright",
legend = c("semi-parametric (Cox)", "parametric (casebase)"),
col = cols,
lty = c(1, 1),
bg = "gray90")
Note that by default, absoulteRisk
calculated the
cumulative incidence. Alternatively, you can calculate the survival
curve by specifying type = 'survival'
in the call to
absoulteRisk
:
<- absoluteRisk(object = model4,
smooth_risk time = seq(0,300, 1),
newdata = new_data,
type = "survival")
plot(survfit(model3, newdata = new_data),
xlab = "Days", ylab = "Survival Probability (%)",
xlim = c(0,300), conf.int = F, col = cols[1],
main = sprintf("Estimated Survival Probability of Lung Cancer\ntrt = test, celltype = adeno, karno = %g,\ndiagtime = %g, age = %g, prior = no", median(veteran$karno), median(veteran$diagtime),
median(veteran$age)))
# add casebase curve with legend
plot(smooth_risk, add = TRUE, col = cols[2], gg = FALSE)
legend("topright",
legend = c("semi-parametric (Cox)", "parametric (casebase)"),
col = cols,
lty = c(1, 1),
bg = "gray90")
## R version 4.2.0 (2022-04-22)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Monterey 12.4
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
##
## attached base packages:
## [1] splines stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] visreg_2.7.0 colorspace_2.0-3 data.table_1.14.2 ggplot2_3.3.6
## [5] survival_3.3-1 casebase_0.10.3
##
## loaded via a namespace (and not attached):
## [1] shape_1.4.6 tidyselect_1.1.2 xfun_0.31 bslib_0.3.1
## [5] purrr_0.3.4 lattice_0.20-45 vctrs_0.4.1 generics_0.1.2
## [9] htmltools_0.5.2 stats4_4.2.0 yaml_2.3.5 mgcv_1.8-40
## [13] utf8_1.2.2 rlang_1.0.6 jquerylib_0.1.4 pillar_1.7.0
## [17] glue_1.6.2 withr_2.5.0 DBI_1.1.2 foreach_1.5.2
## [21] lifecycle_1.0.1 stringr_1.4.0 munsell_0.5.0 gtable_0.3.0
## [25] codetools_0.2-18 VGAM_1.1-6 evaluate_0.15 labeling_0.4.2
## [29] knitr_1.39 fastmap_1.1.0 fansi_1.0.3 highr_0.9
## [33] Rcpp_1.0.9 scales_1.2.0 jsonlite_1.8.0 farver_2.1.1
## [37] digest_0.6.29 stringi_1.7.6 dplyr_1.0.9 grid_4.2.0
## [41] cli_3.4.1 tools_4.2.0 magrittr_2.0.3 sass_0.4.1
## [45] glmnet_4.1-4 tibble_3.1.7 crayon_1.5.1 pkgconfig_2.0.3
## [49] ellipsis_0.3.2 Matrix_1.4-1 iterators_1.0.14 assertthat_0.2.1
## [53] rmarkdown_2.14 R6_2.5.1 nlme_3.1-157 compiler_4.2.0
Efron, Bradley. 1977. “The Efficiency of Cox’s Likelihood Function for Censored Data.” Journal of the American Statistical Association 72 (359). Taylor & Francis Group: 557–65.
Hanley, James A, and Olli S Miettinen. 2009. “Fitting Smooth-in-Time Prognostic Risk Functions via Logistic Regression.” The International Journal of Biostatistics 5 (1).
Mantel, Nathan. 1973. “Synthetic Retrospective Studies and Related Topics.” Biometrics. JSTOR, 479–86.
Saarela, Olli. 2015. “A Case-Base Sampling Method for Estimating Recurrent Event Intensities.” Lifetime Data Analysis. Springer, 1–17.
Saarela, Olli, and Elja Arjas. 2015. “Non-Parametric Bayesian Hazard Regression for Chronic Disease Risk Assessment.” Scandinavian Journal of Statistics 42 (2). Wiley Online Library: 609–26.
Scrucca, L, A Santucci, and F Aversa. 2010. “Regression Modeling of Competing Risk Using R: An in Depth Guide for Clinicians.” Bone Marrow Transplantation 45 (9). Nature Publishing Group: 1388–95.
Kalbfleisch, John D., and Ross L. Prentice. The statistical analysis of failure time data. Vol. 360. John Wiley & Sons, 2011.
Cox, D. R. “Regression models and life tables.” Journal of the Royal Statistical Society 34 (1972): 187-220.