Skip to contents

event_table() tabulates the event history: at each distinct observed time, the number at risk, the number of events, and the number censored. It gives one block for the whole sample, or one block per group when the right-hand side of the formula names grouping variables.

Usage

event_table(formula, data, weights, subset, na.action = stats::na.omit)

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.

Value

A data frame with one row per group and observed time: strata, the grouping variables, time, n_risk, n_event, and n_censor. The layout is the same for one block (strata is "all") as for several.

Details

A subject is at risk at time \(t\) when its start time is before \(t\) and its stop time is at or after \(t\). For right-censored data there is no start time, so the number at risk at \(t\) is the number still under follow-up at \(t\). A subject censored at \(t\) counts as at risk for the events at \(t\). With weights, every count is a sum of weights.

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)
)
event_table(Surv(time, status) ~ 1, data = lung)
#>    strata time n_risk n_event n_censor
#> 1     all  166     10       1        0
#> 2     all  210      9       1        0
#> 3     all  218      8       1        0
#> 4     all  306      7       1        0
#> 5     all  310      6       1        0
#> 6     all  361      5       1        0
#> 7     all  455      4       1        0
#> 8     all  883      3       1        0
#> 9     all 1010      2       0        1
#> 10    all 1022      1       0        1
event_table(Surv(time, status) ~ sex, data = lung)
#>    strata sex time n_risk n_event n_censor
#> 1   sex=1   1  210      5       1        0
#> 2   sex=1   1  306      4       1        0
#> 3   sex=1   1  455      3       1        0
#> 4   sex=1   1  883      2       1        0
#> 5   sex=1   1 1010      1       0        1
#> 6   sex=2   2  166      5       1        0
#> 7   sex=2   2  218      4       1        0
#> 8   sex=2   2  310      3       1        0
#> 9   sex=2   2  361      2       1        0
#> 10  sex=2   2 1022      1       0        1