Skip to contents

piecewise_exponential() fits a proportional hazards model whose baseline hazard is constant between break points: $$h(t \mid x) = \lambda_j \exp(x^\top \beta) \quad \textrm{for } t \in (b_{j-1}, b_j],$$ with \(b_0 = 0\) and the last interval open-ended. Unlike cox_ph(), the baseline hazard is estimated along with \(\beta\), as a step function, so the model gives smooth predictions beyond the event times. More intervals give a more flexible hazard.

Usage

piecewise_exponential(
  formula,
  data,
  weights,
  subset,
  na.action = stats::na.omit,
  breaks = NULL,
  knot_strategy = c("aic", "bic"),
  max_knots = 10,
  conf_level = 0.95,
  max_iter = 50,
  tol = 1e-09
)

Arguments

formula

A formula with a right-censored or counting-process Surv() response on the left and the covariates on the right, such as Surv(time, status) ~ age + sex. Factors are coded with treatment contrasts.

data

A data frame holding the variables in formula.

weights

Optional case weights, a column of data or a numeric vector.

subset

An optional expression selecting the rows of data to use.

na.action

What to do with rows that have missing values. The default drops them.

breaks

The times at which the hazard can change, such as c(180, 365) for the intervals \((0, 180]\), \((180, 365]\), and \((365, \infty)\). Every interval needs some follow-up time. The default, NULL, chooses them from the data.

knot_strategy

How to choose the breaks when breaks = NULL: "aic" (the default) or "bic".

max_knots

The largest number of breaks to consider when breaks = NULL. The default is 10.

conf_level

The confidence level, between 0 and 1. The default is 0.95.

max_iter

The largest number of Newton-Raphson iterations. The default is 50.

tol

The convergence tolerance on the largest change in a parameter. The default is 1e-9.

Value

A piecewise_exponential object. Use coef() or as.data.frame() for the covariates' log hazard ratios, baseline_hazard() for the hazard in each interval, and predict() for survival curves. logLik(), AIC(), BIC(), vcov(), and nobs() work as usual. The object also holds breaks, lr_test (the likelihood ratio test of all the covariates), n, and n_event.

Details

The model is fit by maximum likelihood. Each subject's follow-up is split at the breaks, and the events in each piece are modeled as Poisson counts with the piece's length as the exposure, which gives the same estimates as the survival likelihood. The log-likelihood reported is the survival one, \(\sum_i \delta_i \log h(T_i \mid x_i) - H(T_i \mid x_i)\), so with no breaks it is that of the exponential aft().

With breaks = NULL (the default), the breaks are chosen from the data. Each candidate places \(k = 0, 1, \ldots,\) max_knots breaks at equally spaced quantiles of the distinct event times, and the one with the lowest AIC (or BIC, with knot_strategy = "bic") is kept. With fewer than 3 distinct event times, there are no breaks.

Examples

lung <- data.frame(
  time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567, 144,
    613, 707, 61, 88),
  status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2),
  age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68, 68, 60, 57, 67, 70, 63, 56, 57),
  sex = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1)
)

fit <- piecewise_exponential(Surv(time, status) ~ age + sex, data = lung, breaks = c(180, 365))
fit
#> <piecewise_exponential> Surv(time, status) ~ age + sex
#> 3 intervals. n = 20, events = 16
#> 
#>     estimate hazard_ratio std_error statistic p_value
#> age -0.05500       0.9465   0.04466   -1.2317  0.2181
#> sex  0.01385       1.0139   0.72114    0.0192  0.9847
#> 
#> Baseline hazard:
#>             hazard std_error
#> (0, 180]   0.04791    0.1211
#> (180, 365] 0.07967    0.2077
#> (365, Inf) 0.05770    0.1475
#> 
#> Log-likelihood: -115.696, AIC: 241.392
#> Likelihood ratio test: 1.93 on 2 df, p = 0.381
baseline_hazard(fit)
#>   start stop     hazard log_hazard std_error     conf_low conf_high
#> 1     0  180 0.04790904  -3.038451  2.528001 0.0003377376  6.796034
#> 2   180  365 0.07967294  -2.529825  2.607264 0.0004808438 13.201329
#> 3   365  Inf 0.05770242  -2.852456  2.556272 0.0003848498  8.651607

# Breaks chosen by AIC
piecewise_exponential(Surv(time, status) ~ age + sex, data = lung)
#> <piecewise_exponential> Surv(time, status) ~ age + sex
#> 1 interval, breaks chosen by AIC. n = 20, events = 16
#> 
#>     estimate hazard_ratio std_error statistic p_value
#> age -0.05154       0.9498   0.04427  -1.16432  0.2443
#> sex  0.03853       1.0393   0.71821   0.05365  0.9572
#> 
#> Baseline hazard:
#>           hazard std_error
#> (0, Inf) 0.04618     0.116
#> 
#> Log-likelihood: -116.012, AIC: 238.024
#> Likelihood ratio test: 1.69 on 2 df, p = 0.43