as_surv()

Convert an event-time vector to a Surv response.

Usage

Source

as_surv(x)

The type of the result depends on the status codes present, ignoring missing elements:

  • only "e" and "r": a right-censored response, with status 1 for events.
  • only "e" and "l": a left-censored response, with status 1 for events.
  • any other combination: an interval response, with R’s codes 0 (right), 1 (exact), 2 (left), and 3 (interval).

Missing elements are missing in the result.

Parameters

x: Any
An EventTime vector.

Returns

Surv
The response.

Raises

TypeError
If x isn’t an EventTime vector.

Examples

import greenwood as gw

x = gw.event_time(
    time=[7, 5, 3, 2],
    status=["e", "r", "l", "i"],
    time_max=[None, None, None, 4],
)
gw.as_surv(x).to_frame(format="polars")
shape: (4, 3)
time1time2status
f64f64f64
7.01.01.0
5.01.00.0
3.01.02.0
2.04.03.0

Exact and right-censored values give a right-censored response:

gw.as_surv(gw.event_time(time=[7, 5], status=["e", "r"]))
Surv(type=right, n=2, events=1)