Create a new object which stores user-specified survival distribution information in the format needed for the main function, RMSTpow. survdef is used when the user wishes to specify a piecewise expoenential survival distribution. Either the hazard on fixed intervals or survival probabilities at fixed times can be specified.

survdef(haz = NA, surv = NA, times = NA)

Arguments

haz

a vector of hazards of length<=10. If a single hazard is specified, the survival distribution is exponential with the specified hazard. If haz has length>2, the survival distribution has constant hazard equal to haz over the intervals [0, t_1), [t_1, t_2), …, [t_m, Inf) where t_i are the entries of times and times has length m. One of haz, surv must be specified.

surv

a vector of survival probabilities of length<=10 corresponding to times. If surv is specified, the survival distribution has constant hazard over the intervals [0, t_1), [t_1, t_2), …, [t_m, Inf) where t_i are the entries of times and times has length m+1. The hazards are calculated so that the curve passes through each entry in surv at the corresponding time from times. One of haz, surv must be specified.

times

a vector of the same length as surv (if surv is specified) or one element shorter than haz (if haz is specified). No times term is required if a single hazard is specified in haz.

Value

a list with components:

S

a vectorized function that takes time as input and returns the survival probability at that time

h

a vectorized function that takes time as input and returns the hazard at that time

Examples

survdef(times = 1:8, surv=c(.771, .523,.342,.236,.172,.130,.1,.078))
#> $S #> function (t) #> sapply(t, function(z) { #> width <- diff(c(0, times[times < z], z)) #> H <- sum(width * h(c(0, times[times < z]))) #> return(exp(-H)) #> }) #> <bytecode: 0x7fb666e41618> #> <environment: 0x7fb660a30720> #> #> $h #> function (x) #> { #> sapply(x, function(t) { #> if (0 <= t & t < times10[1]) #> myh[1] #> else if (times10[1] <= t & t < times10[2]) #> myh[2] #> else if (times10[2] <= t & t < times10[3]) #> myh[3] #> else if (times10[3] <= t & t < times10[4]) #> myh[4] #> else if (times10[4] <= t & t < times10[5]) #> myh[5] #> else if (times10[5] <= t & t < times10[6]) #> myh[6] #> else if (times10[6] <= t & t < times10[7]) #> myh[7] #> else if (times10[7] <= t & t < times10[8]) #> myh[8] #> else if (times10[8] <= t & t < times10[9]) #> myh[9] #> else if (times10[9] <= t) #> myh[10] #> }) #> } #> <bytecode: 0x7fb664eb3230> #> <environment: 0x7fb660a30720> #>