Convert an event-time vector to a Surv response.
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.
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)| time1 | time2 | status |
|---|
| f64 | f64 | f64 |
| 7.0 | 1.0 | 1.0 |
| 5.0 | 1.0 | 0.0 |
| 3.0 | 1.0 | 2.0 |
| 2.0 | 4.0 | 3.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)