cum_hazard_fun: Cumulative hazard functions for any distribution

View source: R/hazard_fun.R

cum_hazard_funR Documentation

Cumulative hazard functions for any distribution

Description

[Experimental]

This function takes a maxlogL hazard function and computes the cumulative hazard function.

Usage

cum_hazard_fun(
  distr,
  support = NULL,
  method = c("log_sf", "integration"),
  routine = NULL
)

Arguments

distr

a length-one character vector with the name of density/mass function of interest.

support

a list with the following entries:

  • interval: a two dimensional atomic vector indicating the set of possible values of a random variable having the distribution specified in y_dist.

  • type: character indicating if distribution has a discrete or a continous random variable.

method

a character or function; if "log_sf", the cumulative hazard function (CHF) is computed using the expression H(t) = -\log (S(t)); if "integrate_hf", the CHF is computed with the integral of the hazard function.

routine

a character specifying the integration routine. integrate and gauss_quad are available for continuous distributions, and summate for discrete ones. Custom routines can be defined but they must be compatible with the integration API.

Value

A function with the following input arguments:

x

vector of (non-negative) quantiles.

...

Arguments of the probability density/mass function.

Author(s)

Jaime Mosquera GutiƩrrez, jmosquerag@unal.edu.co

See Also

Other distributions utilities: expected_value(), hazard_fun()

Examples

library(EstimationTools)

#----------------------------------------------------------------------------
# Example 1: Cumulative hazard function of the Weibull distribution.
support <- list(interval=c(0, Inf), type='continuous')

# Cumuative hazard function in the 'maxlogL' framework
Hweibull1 <- cum_hazard_fun(
  distr = 'dweibull',
  support = support,
  method = "integration"
 )

 Hweibull2 <- cum_hazard_fun(
  distr = 'dweibull',
  method = "log_sf"
 )

# Compute cumulative hazard function from scratch
# Recall h(x) = shape/scale * (x/scale)^(shape - 1), then
# H(x) = (x/scale)^shape

Hweibull3 <- function(x, scale, shape){
  (x/scale)^shape
}

# Comparison
Hweibull1(0.2, shape = 2, scale = 1)  # using H(t) = -log(S(t))
Hweibull2(0.2, shape = 2, scale = 1)  # integrating h(t)
Hweibull3(0.2, shape = 2, scale = 1)  # raw version


#----------------------------------------------------------------------------


Jaimemosg/EstimationTools documentation built on Oct. 23, 2023, 10 a.m.