NAG FL Interface
g07bef (estim_​weibull)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

g07bef computes maximum likelihood estimates for parameters of the Weibull distribution from data which may be right-censored.

2 Specification

Fortran Interface
Subroutine g07bef ( cens, n, x, ic, beta, gamma, tol, maxit, sebeta, segam, corr, dev, nit, wk, ifail)
Integer, Intent (In) :: n, ic(*), maxit
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: nit
Real (Kind=nag_wp), Intent (In) :: x(n), tol
Real (Kind=nag_wp), Intent (Inout) :: gamma
Real (Kind=nag_wp), Intent (Out) :: beta, sebeta, segam, corr, dev, wk(n)
Character (1), Intent (In) :: cens
C Header Interface
#include <nag.h>
void  g07bef_ (const char *cens, const Integer *n, const double x[], const Integer ic[], double *beta, double *gamma, const double *tol, const Integer *maxit, double *sebeta, double *segam, double *corr, double *dev, Integer *nit, double wk[], Integer *ifail, const Charlen length_cens)
The routine may be called by the names g07bef or nagf_univar_estim_weibull.

3 Description

g07bef computes maximum likelihood estimates of the parameters of the Weibull distribution from exact or right-censored data.
For n realizations, yi, from a Weibull distribution a value xi is observed such that
xiyi.  
There are two situations:
  1. (a)exactly specified observations, when xi=yi
  2. (b)right-censored observations, known by a lower bound, when xi<yi.
The probability density function of the Weibull distribution, and hence the contribution of an exactly specified observation to the likelihood, is given by:
f(x;λ,γ)=λγxγ-1exp(-λxγ),  x>0,   for ​λ,γ>0;  
while the survival function of the Weibull distribution, and hence the contribution of a right-censored observation to the likelihood, is given by:
S(x;λ,γ)=exp(-λxγ),   x> 0,   for ​ λ ,γ> 0.  
If d of the n observations are exactly specified and indicated by iD and the remaining (n-d) are right-censored, then the likelihood function, Like ​(λ,γ) is given by
Like(λ,γ)(λγ)d (iDxiγ-1) exp(-λi=1nxiγ) .  
To avoid possible numerical instability a different parameterisation β,γ is used, with β=log(λ). The kernel log-likelihood function, L(β,γ), is then:
L(β,γ)=dlog(γ)+dβ+(γ-1)iDlog(xi)-eβi=1nxiγ.  
If the derivatives L β , L γ , 2L β2 , 2L β γ and 2L γ2 are denoted by L1, L2, L11, L12 and L22, respectively, then the maximum likelihood estimates, β^ and γ^, are the solution to the equations:
L1(β^,γ^)=0 (1)
and
L2(β^,γ^)=0 (2)
Estimates of the asymptotic standard errors of β^ and γ^ are given by:
se(β^)=-L22 L11L22-L122 ,  se(γ^)=-L11 L11L22-L122 .  
An estimate of the correlation coefficient of β^ and γ^ is given by:
L12L12L22 .  
Note:  if an estimate of the original parameter λ is required, then
λ^=exp(β^)  and  se(λ^)=λ^se(β^).  
The equations (1) and (2) are solved by the Newton–Raphson iterative method with adjustments made to ensure that γ^>0.0.

4 References

Gross A J and Clark V A (1975) Survival Distributions: Reliability Applications in the Biomedical Sciences Wiley
Kalbfleisch J D and Prentice R L (1980) The Statistical Analysis of Failure Time Data Wiley

5 Arguments

1: cens Character(1) Input
On entry: indicates whether the data is censored or non-censored.
cens='N'
Each observation is assumed to be exactly specified. ic is not referenced.
cens='C'
Each observation is censored according to the value contained in ic(i), for i=1,2,,n.
Constraint: cens='N' or 'C'.
2: n Integer Input
On entry: n, the number of observations.
Constraint: n1.
3: x(n) Real (Kind=nag_wp) array Input
On entry: x(i) contains the ith observation, xi, for i=1,2,,n.
Constraint: x(i)>0.0, for i=1,2,,n.
4: ic(*) Integer array Input
Note: the dimension of the array ic must be at least n if cens='C', and at least 1 otherwise.
On entry: if cens='C', ic(i) contains the censoring codes for the ith observation, for i=1,2,,n.
If ic(i)=0, the ith observation is exactly specified.
If ic(i)=1, the ith observation is right-censored.
If cens='N', ic is not referenced.
Constraint: if cens='C', then ic(i)=0 or 1, for i=1,2,,n.
5: beta Real (Kind=nag_wp) Output
On exit: the maximum likelihood estimate, β^, of β.
6: gamma Real (Kind=nag_wp) Input/Output
On entry: indicates whether an initial estimate of γ is provided.
If gamma>0.0, it is taken as the initial estimate of γ and an initial estimate of β is calculated from this value of γ.
If gamma0.0, initial estimates of γ and β are calculated, internally, providing the data contains at least two distinct exact observations. (If there are only two distinct exact observations, the largest observation must not be exactly specified.) See Section 9 for further details.
On exit: contains the maximum likelihood estimate, γ^, of γ.
7: tol Real (Kind=nag_wp) Input
On entry: the relative precision required for the final estimates of β and γ. Convergence is assumed when the absolute relative changes in the estimates of both β and γ are less than tol.
If tol=0.0, a relative precision of 0.000005 is used.
Constraint: machine precisiontol1.0 or tol=0.0.
8: maxit Integer Input
On entry: the maximum number of iterations allowed.
If maxit0, a value of 25 is used.
9: sebeta Real (Kind=nag_wp) Output
On exit: an estimate of the standard error of β^.
10: segam Real (Kind=nag_wp) Output
On exit: an estimate of the standard error of γ^.
11: corr Real (Kind=nag_wp) Output
On exit: an estimate of the correlation between β^ and γ^.
12: dev Real (Kind=nag_wp) Output
On exit: the maximized kernel log-likelihood, L(β^,γ^).
13: nit Integer Output
On exit: the number of iterations performed.
14: wk(n) Real (Kind=nag_wp) array Workspace
15: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, cens=value.
Constraint: cens='N' or 'C'.
On entry, n=value.
Constraint: n1.
On entry, tol=value.
Constraint: machine precision<tol1.0 or tol=0.0.
ifail=2
On entry, i=value and ic(i)=value.
Constraint: ic(i)=0 or 1.
On entry, i=value and x(i)=value.
Constraint: x(i)>0.0.
ifail=3
On entry, there are no exactly specified observations.
Unable to calculate initial values. This is due to there being either less than two distinct exactly specified observations or exactly two and the largest observation is one of the exact observations.
ifail=4
The chosen method has not converged in value iterations. You should either increase tol or maxit.
ifail=5
Hessian matrix of the Newton–Raphson process is singular. Either different initial estimates should be provided or the data should be checked to see if the Weibull distribution is appropriate.
The process has diverged. The process is deemed divergent if three successive increments of β or γ increase. Either different initial estimates should be provided or the data should be checked to see if the Weibull distribution is appropriate.
ifail=6
Potential overflow detected. This is an unlikely error exit usually caused by a large input estimate of γ.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Given that the Weibull distribution is a suitable model for the data and that the initial values are reasonable the convergence to the required accuracy, indicated by tol, should be achieved.

8 Parallelism and Performance

g07bef is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

The initial estimate of γ is found by calculating a Kaplan–Meier estimate of the survival function, S^(x), and estimating the gradient of the plot of log(-log(S^(x))) against x. This requires the Kaplan–Meier estimate to have at least two distinct points.
The initial estimate of β^, given a value of γ^, is calculated as
β^=log(di=1nxiγ^ ) .  

10 Example

In a study, 20 patients receiving an analgesic to relieve headache pain had the following recorded relief times (in hours):
1.1 1.4 1.3 1.7 1.9 1.8 1.6 2.2 1.7 2.7 4.1 1.8 1.5 1.2 1.4 3.0 1.7 2.3 1.6 2.0  
(See Gross and Clark (1975).) This data is read in and a Weibull distribution fitted assuming no censoring; the parameter estimates and their standard errors are printed.

10.1 Program Text

Program Text (g07befe.f90)

10.2 Program Data

Program Data (g07befe.d)

10.3 Program Results

Program Results (g07befe.r)