## R code for constructing likelihood based confidence intervals for the life time quantiles of a competing risks model

Competing risks model are employed when, for instance, a device has two different causes of failure (also referred to as failure modes). The R code below shows how to model the failure data of such a device with a competing risks model.
Furthermore, the R code demonstrates how to compute likelihood based confidence intervals for the life time quantiles of the competing risks model. In computing these confidence intervals the R code assumes that the observed failure times follow a Weibull distribution. However, it will also be demonstrated how to adapt the code in case the failure times follow a lognormal distribution.
It should be noted that the competing risks model in the R code focuses on a situation in which a device has two failure modes. Nevertheless, the code can easily be extended to include more than two failure modes. ## R code for fitting a two-failure mode model

A system or component can fail in different ways. For instance, a device may fail due to 1) an electrical surge, or 2) wearout. When a system fails due to two such failure modes, it may be better to model the failure times with a two-failure mode model (which is also known as a competing risks model).

The following R code fits a two-failure mode model. This R code assumes that the failure times of both failure modes follow a Weibull distribution. However, the code can be easily adapted to implement other distributions as well (such as the lognormal distribution). Furthermore, the R code can be extended to include more than two failure modes. The R code also demonstrates how to construct normal-approximation and likelihood based intervals for the failure probabilities of a two-failure mode model. In addition, the code computes the median and mean life time for a two-failure mode model.

## R code for constructing likelihood based confidence intervals for the median residual life

The following R-code may be used for computing likelihood based confidence intervals for the median residual life.

Definition of the median residual life
The median residual life (or median remaining lifetime) of a unit at time t is given by: $\frac{1}{2}*S(t) = S(t + mdrl)$

where mdrl is the median residual life, and S(·) the survival function of the failure times.

Computing likelihood based intervals for MDRL
The method for computing the likelihood based confidence interval for the median residual life is similar to the one I previously used for the mean residual life (this blog post explains the method for computing the likelihood based confidence intervals for the mean residual life). ## R code for constructing likelihood based confidence intervals for the mean residual life

The following R-code may be used for computing likelihood based confidence intervals for the mean (or expected) residual life.

Definition of the mean residual life
The mean residual life (or expected remaining lifetime) of a unit at time t is given by: $MRL(t) = \frac{\int^{\infty}_{t} (u-t)f(u)\ du}{S(t)} = \frac{\int^{\infty}_{t} S(u) \ du}{S(t)}$

where MRL(t) is the mean residual life at time t, f(·) the probability density function of the failure times, and S(·) the survival function. Continue reading R code for constructing likelihood based confidence intervals for the mean residual life

## R code for constructing likelihood based confidence intervals for the hazard function

The following R code may be used for computing likelihood based confidence intervals for the hazard function of an Accelerated Failure Time model. The code computes the likelihood based confidence intervals for failure times that follow either a Weibull or lognormal distribution.

Definition of the hazard function
The hazard function (or hazard rate) at time t is given by: $h(t)=\frac{f(t)}{S(t)}$

where f(·) is the probability density function of the failure times, and S(·) the survival function. Continue reading R code for constructing likelihood based confidence intervals for the hazard function