Numerical hazard function
hazard_function.Rd
This function calculates the hazard function based on a given probability density function (pdf). The hazard function represents the instantaneous rate at which an event occurs at a specific time, given that the event has not occurred before that time.
Details
The hazard function is calculated as the ratio of the probability density function
to the survival function. The hazard function is useful for understanding the instantaneous
rate of occurrence of an event at a specific time. The hazard function is also used to model
the instantaneous rate of occurrence of an event in survival analysis. Just like
the function survival_function()
, the hazard_function()
function is
vectorized in \(t\), which allows the calculation of the hazard function
for a vector of times. The hazard function is defined by:
\(h(t) = \frac{f_T(t)}{S_T(t)},\) where \(f_T(t)\) is the probability density function and \(S_T(t)\) is the survival function at time \(t\).
References
NADARAJAH, Saralees; KOTZ, Samuel. The beta exponential distribution. Reliability engineering & system safety, v. 91, n. 6, p. 689-697, 2006.
Examples
# Saraless Nadarajah and Samnuel Kotz (2006)
beta_exponential <- function(x, a, b, lambda){
lambda / beta(a, b) * exp(-b * lambda * x) * (1 - exp(-lambda * x))^(a - 1)
}
hazard_beta_exponential <- hazard_function(beta_exponential)
hazard_beta_exponential(
t = seq(0.001, 1.5, length.out = 50L),
a = 1.5,
b = 1.8,
lambda = 1.5
)
#> [1] 0.1883102 0.9840887 1.3021254 1.5119839 1.6667616 1.7876074 1.8854069
#> [8] 1.9665682 2.0351987 2.0940896 2.1452239 2.1900584 2.2296930 2.2649769
#> [15] 2.2965791 2.3250336 2.3507737 2.3741547 2.3954716 2.4149712 2.4328620
#> [22] 2.4493213 2.4645012 2.4785329 2.4915300 2.5035918 2.5148037 2.5252451
#> [29] 2.5349825 2.5440758 2.5525787 2.5605390 2.5679998 2.5749997 2.5815736
#> [36] 2.5877530 2.5935667 2.5990406 2.6041986 2.6090622 2.6136515 2.6179844
#> [43] 2.6220779 2.6259472 2.6296067 2.6330693 2.6363472 2.6394517 2.6423931
#> [50] 2.6451811
#> attr(,"time")
#> [1] 0.00100000 0.03159184 0.06218367 0.09277551 0.12336735 0.15395918
#> [7] 0.18455102 0.21514286 0.24573469 0.27632653 0.30691837 0.33751020
#> [13] 0.36810204 0.39869388 0.42928571 0.45987755 0.49046939 0.52106122
#> [19] 0.55165306 0.58224490 0.61283673 0.64342857 0.67402041 0.70461224
#> [25] 0.73520408 0.76579592 0.79638776 0.82697959 0.85757143 0.88816327
#> [31] 0.91875510 0.94934694 0.97993878 1.01053061 1.04112245 1.07171429
#> [37] 1.10230612 1.13289796 1.16348980 1.19408163 1.22467347 1.25526531
#> [43] 1.28585714 1.31644898 1.34704082 1.37763265 1.40822449 1.43881633
#> [49] 1.46940816 1.50000000
#> attr(,"class")
#> [1] "hazard_function"