All event times are stopped at a given time point and corresponding events are censored
stopTime(object, stop.time)
Stopped event history object where all times are censored
at stop.time
. All observations with times greater than stop.time
are set to stop.time
and the event status is set to attr(object,"cens.code")
.
A new column "stop.time"
is equal to 1
for stopped observations
and equal to 0
for the other observations.
Hist
set.seed(29)
d <- SimSurv(10)
h <- with(d,Hist(time,status))
h
#>
#> Right-censored response of a survival model
#>
#> No.Observations: 10
#>
#> Pattern:
#> Freq
#> event 8
#> right.censored 2
stopTime(h,8)
#>
#> Right-censored response of a survival model stopped at time 8
#>
#> No.Observations: 10
#>
#> Pattern:
#> Freq
#> event 7
#> right.censored 3
stopTime(h,5)
#>
#> Right-censored response of a survival model stopped at time 5
#>
#> No.Observations: 10
#>
#> Pattern:
#> Freq
#> event 6
#> right.censored 4
## works also with Surv objects
library(survival)
s <- with(d,Surv(time,status))
stopTime(s,5)
#> [1] 5.0000000+ 5.0000000+ 0.6460462 2.3329159 5.0000000+ 1.3115992
#> [7] 2.6240141 5.0000000+ 3.5162939 3.7704429
## competing risks
set.seed(29)
dr <- SimCompRisk(10)
hr <- with(dr,Hist(time,event))
hr
#>
#> Right-censored response of a competing.risks model
#>
#> No.Observations: 10
#>
#> Pattern:
#>
#> Cause event right.censored
#> 1 5 0
#> 2 4 0
#> unknown 0 1
stopTime(hr,8)
#>
#> Right-censored response of a competing.risks model stopped at time 8
#>
#> No.Observations: 10
#>
#> Pattern:
#>
#> Cause event right.censored
#> 1 5 0
#> 2 4 0
#> unknown 0 1
stopTime(hr,5)
#>
#> Right-censored response of a competing.risks model stopped at time 5
#>
#> No.Observations: 10
#>
#> Pattern:
#>
#> Cause event right.censored
#> 1 4 0
#> 2 2 0
#> unknown 0 4