hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_univar_estim_weibull (g07be)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_univar_estim_weibull (g07be) computes maximum likelihood estimates for arguments of the Weibull distribution from data which may be right-censored.


[beta, gamma, sebeta, segam, corr, dev, nit, ifail] = g07be(cens, x, ic, gamma, tol, maxit, 'n', n)
[beta, gamma, sebeta, segam, corr, dev, nit, ifail] = nag_univar_estim_weibull(cens, x, ic, gamma, tol, maxit, 'n', n)


nag_univar_estim_weibull (g07be) computes maximum likelihood estimates of the arguments 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
There are two situations:
(a) exactly specified observations, when xi=yi
(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:
fx;λ,γ=λγ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:
Sx;λ,γ=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:
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)
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 argument λ 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.


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


Compulsory Input Parameters

1:     cens – string (length ≥ 1)
Indicates whether the data is censored or non-censored.
Each observation is assumed to be exactly specified. ic is not referenced.
Each observation is censored according to the value contained in ici, for i=1,2,,n.
Constraint: cens='N' or 'C'.
2:     xn – double array
xi contains the ith observation, xi, for i=1,2,,n.
Constraint: xi>0.0, for i=1,2,,n.
3:     ic: int64int32nag_int array
The dimension of the array ic must be at least n if cens='C', and at least 1 otherwise
If cens='C', then ici contains the censoring codes for the ith observation, for i=1,2,,n.
If ici=0, the ith observation is exactly specified.
If ici=1, the ith observation is right-censored.
If cens='N', then ic is not referenced.
Constraint: if cens='C', then ici=0 or 1, for i=1,2,,n.
4:     gamma – double scalar
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, then 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, then the largest observation must not be exactly specified.) See Further Comments for further details.
5:     tol – double scalar
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, then a relative precision of 0.000005 is used.
Constraint: machine precisiontol1.0 or tol=0.0.
6:     maxit int64int32nag_int scalar
The maximum number of iterations allowed.
If maxit0, then a value of 25 is used.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array x.
n, the number of observations.
Constraint: n1.

Output Parameters

1:     beta – double scalar
The maximum likelihood estimate, β^, of β.
2:     gamma – double scalar
Contains the maximum likelihood estimate, γ^, of γ.
3:     sebeta – double scalar
An estimate of the standard error of β^.
4:     segam – double scalar
An estimate of the standard error of γ^.
5:     corr – double scalar
An estimate of the correlation between β^ and γ^.
6:     dev – double scalar
The maximized kernel log-likelihood, Lβ^,γ^.
7:     nit int64int32nag_int scalar
The number of iterations performed.
8:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,cens'N' or 'C',
or0.0<tol<machine precision,
On entry,the ith observation, xi0.0, for some i=1,2,,n,
orthe ith censoring code, ici0 or 1, for some i=1,2,,n and cens='C'.
On entry, there are no exactly specified observations, or the function was requested to calculate initial values and there are either less than two distinct exactly specified observations or there are exactly two and the largest observation is one of the exact observations.
The method has failed to converge in maxit iterations. You should increase tol or maxit.
Process has diverged. The process is deemed divergent if three successive increments of β or γ increase or if the 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.
A potential overflow has been detected. This is an unlikely exit usually caused by a large input estimate of γ.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


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.

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-logS^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
β^=logdi=1nxiγ^ .  


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.
function g07be_example

fprintf('g07be example results\n\n');

x = [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];

% Control parameters and initial estimate for gamma
cens  = 'No censor';
ic    = [int64(0)];
gamma = 0;
tol   = 0;
maxit = int64(0);

% Calculate estimates
[beta, gamma, sebeta, segam, corr, dev, nit, ifail] = ...
  g07be( ...
         cens, x, ic, gamma, tol, maxit);

fprintf('  Beta  = %10.4f Standard error = %10.4f\n', beta, sebeta);
fprintf('  Gamma = %10.4f Standard error = %10.4f\n', gamma, segam);

g07be example results

  Beta  =    -2.1073 Standard error =     0.4627
  Gamma =     2.7870 Standard error =     0.4273

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015