Create objects of the class SURVIVAL
Details
The objects of the class SURVIVAL define different distributions of survival times. Each class has its own set of parameters but once the SURVIVAL object is defined, they have access to the same functions to calculate:
survival time function:
sfx()
,hazard time function:
hfx()
,cumulative hazard function:
Cum_Hfx()
the inverse of the cumulative hazard function:
invCum_Hfx()
.generate random survival times:
rsurv()
generate random survival times under proportional hazard ratio:
rsurvhr()
.
There several functions to plot the distributions
generic S3:
plot.SURVIVAL()
plot_survival()
: to plot the functionsggplot_survival_random()
: to ggplot random draws from the distributioncompare_survival()
: to compare the functions of two SURVIVAL objects
Distributions
The current factories are implemented:
s_exponential()
: for Exponential distributionss_weibull()
: for Weibull distributionss_gompertz()
: for Gompertz distributionss_picewise()
: for Piecewise exponential distributions
Examples
# Define a SURVIVAL object
obj <- s_factory(s_exponential, lambda = 2)
# Survival, Hazard and Cumulative hazard at time 0.4
sfx(SURVIVAL = obj, t= 0.4)
#> [1] 0.449329
hfx(SURVIVAL = obj, t = 0.4)
#> [1] 2
Cum_Hfx(SURVIVAL = obj, t = 0.4)
#> [1] 0.8
# Time when the Cumulative hazard is 0.8
invCum_Hfx(SURVIVAL = obj, H = 0.8)
#> [1] 0.4
# Draw one random survival time from the distribution
rsurv(SURVIVAL = obj, n = 1)
#> [1] 0.1737629
# Draw one random survival time from the distribution, with hazard ratio 0.5
rsurvhr(SURVIVAL = obj, hr = 0.5)
#> [1] 0.05279276
# Plot the survival functions
plot(obj)