getsurvprob: Get survprob from pec packages

Description Usage Arguments Details Author(s) References Examples

View source: R/getsurvprob.R

Description

Get survprob from pec packages

Usage

1
getsurvprob(obj, times)

Arguments

obj

survfit object

times

Details

Get survprob from pec packages

Author(s)

pec

References

from pec packages

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (obj, times) 
{
    if (!inherits(obj, "survfit")) 
        stop("obj is not of class survfit")
    class(obj) <- NULL
    lt <- length(times)
    nsurv <- times
    if (length(times) == length(obj$time)) {
        if (all(times == obj$time)) 
            return(obj$surv)
    }
    inside <- times %in% obj$time
    for (i in (1:lt)) {
        if (inside[i]) 
            nsurv[i] <- obj$surv[obj$time == times[i]]
        else {
            less <- obj$time[obj$time < times[i]]
            if (length(less) == 0) 
                nsurv[i] <- 1
            else nsurv[i] <- obj$surv[obj$time == max(less)]
        }
    }
    nsurv
  }

whcsu/sfse documentation built on Dec. 4, 2019, 2:11 p.m.