Skip to contents

nelson_aalen() estimates the cumulative hazard function from censored event times. It gives one curve for the whole sample, or one curve per group when the right-hand side of the formula names grouping variables.

Usage

nelson_aalen(
  formula,
  data,
  weights,
  subset,
  na.action = stats::na.omit,
  conf_type = c("log", "plain"),
  conf_level = 0.95
)

Arguments

formula

A formula with a Surv() response on the left and either 1 (one curve) or one or more grouping variables on the right, such as Surv(time, status) ~ sex.

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.

conf_type

The scale for confidence intervals: "log" (the default) or "plain".

conf_level

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

Value

A nelson_aalen object. Use as.data.frame() for the estimate at every time and predict() for the estimate at given times. Printing it shows the number of subjects, the number of events, and the largest cumulative hazard reached in each group.

The table from as.data.frame() has the columns strata, the grouping variables, time, n_risk, n_event, estimate, std_error, conf_low, and conf_high. The layout is the same for one curve (strata is "all") as for several.

Details

The estimate at time \(t\) is the sum of \(d_i / n_i\) over the event times \(t_i \le t\), where \(n_i\) is the number at risk and \(d_i\) the number of events. Its variance is Aalen's estimator, the sum of \(d_i / n_i^2\). Confidence intervals are built on the log scale by default, or on the plain (identity) scale with the lower limit floored at 0. The survival function can be recovered as \(\exp(-H(t))\), though kaplan_meier() is the usual estimate of survival itself.

Right-censored data and counting-process data are supported. With counting-process data, Surv(start, stop, event), a subject is at risk only after its start time.

Examples

lung <- data.frame(
  time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166),
  status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2),
  sex = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)
)

fit <- nelson_aalen(Surv(time, status) ~ 1, data = lung)
fit
#> <nelson_aalen> Surv(time, status) ~ 1
#> 
#>      n events max_cumhaz
#> all 10      8   1.428968
as.data.frame(fit)
#>    strata time n_risk n_event  estimate std_error   conf_low conf_high
#> 1     all  166     10       1 0.1000000 0.1000000 0.01408635 0.7099071
#> 2     all  210      9       1 0.2111111 0.1494847 0.05269721 0.8457355
#> 3     all  218      8       1 0.3361111 0.1948607 0.10789421 1.0470504
#> 4     all  306      7       1 0.4789683 0.2416171 0.17820310 1.2873546
#> 5     all  310      6       1 0.6456349 0.2935245 0.26485364 1.5738672
#> 6     all  361      5       1 0.8456349 0.3551853 0.37124402 1.9262220
#> 7     all  455      4       1 1.0956349 0.4343462 0.50375713 2.3829258
#> 8     all  883      3       1 1.4289683 0.5475105 0.67434779 3.0280373
#> 9     all 1010      2       0 1.4289683 0.5475105 0.67434779 3.0280373
#> 10    all 1022      1       0 1.4289683 0.5475105 0.67434779 3.0280373

# One curve per group, read at given times
by_sex <- nelson_aalen(Surv(time, status) ~ sex, data = lung)
predict(by_sex, times = c(200, 400))
#>   strata sex time estimate std_error  conf_low conf_high
#> 1  sex=1   1  200 0.000000 0.0000000 0.0000000  0.000000
#> 2  sex=1   1  400 0.450000 0.3201562 0.1115882  1.814708
#> 3  sex=2   2  200 0.200000 0.2000000 0.0281727  1.419814
#> 4  sex=2   2  400 1.283333 0.6808899 0.4536521  3.630413