NAG Library Routine Document
g07bbf (estim_normal)
1
Purpose
g07bbf computes maximum likelihood estimates and their standard errors for parameters of the Normal distribution from grouped and/or censored data.
2
Specification
Fortran Interface
Subroutine g07bbf ( |
method, n, x, xc, ic, xmu, xsig, tol, maxit, sexmu, sexsig, corr, dev, nobs, nit, wk, ifail) |
Integer, Intent (In) | :: | n, ic(n), maxit | Integer, Intent (Inout) | :: | ifail | Integer, Intent (Out) | :: | nobs(4), nit | Real (Kind=nag_wp), Intent (In) | :: | x(n), xc(n), tol | Real (Kind=nag_wp), Intent (Inout) | :: | xmu, xsig | Real (Kind=nag_wp), Intent (Out) | :: | sexmu, sexsig, corr, dev, wk(2*n) | Character (1), Intent (In) | :: | method |
|
C Header Interface
#include <nagmk26.h>
void |
g07bbf_ (const char *method, const Integer *n, const double x[], const double xc[], const Integer ic[], double *xmu, double *xsig, const double *tol, const Integer *maxit, double *sexmu, double *sexsig, double *corr, double *dev, Integer nobs[], Integer *nit, double wk[], Integer *ifail, const Charlen length_method) |
|
3
Description
A sample of size
is taken from a Normal distribution with mean
and variance
and consists of grouped and/or censored data. Each of the
observations is known by a pair of values
such that:
The data is represented as particular cases of this form:
- exactly specified observations occur when ,
- right-censored observations, known only by a lower bound, occur when ,
- left-censored observations, known only by a upper bound, occur when ,
- and interval-censored observations when .
Let the set
identify the exactly specified observations, sets
and
identify the observations censored on the right and left respectively, and set
identify the observations confined between two finite limits. Also let there be
exactly specified observations, i.e., the number in
. The probability density function for the standard Normal distribution is
and the cumulative distribution function is
The log-likelihood of the sample can be written as:
where
and
.
Let
and
then the first derivatives of the log-likelihood can be written as:
and
The maximum likelihood estimates,
and
, are the solution to the equations:
and
and if the second derivatives
,
and
are denoted by
,
and
respectively, then estimates of the standard errors of
and
are given by:
and an estimate of the correlation of
and
is given by:
To obtain the maximum likelihood estimates the equations
(1) and
(2) can be solved using either the Newton–Raphson method or the Expectation-maximization
algorithm of
Dempster et al. (1977).
Newton–Raphson Method
This consists of using approximate estimates
and
to obtain improved estimates
and
by solving
for the corrections
and
.
EM Algorithm
The expectation step consists of constructing the variable
as follows:
the maximization step consists of substituting
(3),
(4),
(5) and
(6) into
(1) and
(2) giving:
and
where
and where
,
and
are
,
and
evaluated at
and
. Equations
(3) to
(8) are the basis of the
iterative procedure for finding
and
. The procedure consists of alternately estimating
and
using
(7) and
(8) and estimating
using
(3) to
(6).
In choosing between the two methods a general rule is that the Newton–Raphson method converges more quickly but requires good initial estimates whereas the algorithm converges slowly but is robust to the initial values. In the case of the censored Normal distribution, if only a small proportion of the observations are censored then estimates based on the exact observations should give good enough initial estimates for the Newton–Raphson method to be used. If there are a high proportion of censored observations then the algorithm should be used and if high accuracy is required the subsequent use of the Newton–Raphson method to refine the estimates obtained from the algorithm should be considered.
4
References
Dempster A P, Laird N M and Rubin D B (1977) Maximum likelihood from incomplete data via the algorithm (with discussion) J. Roy. Statist. Soc. Ser. B 39 1–38
Swan A V (1969) Algorithm AS 16. Maximum likelihood estimation from grouped and censored normal data Appl. Statist. 18 110–114
Wolynetz M S (1979) Maximum likelihood estimation from confined and censored normal data Appl. Statist. 28 185–195
5
Arguments
- 1: – Character(1)Input
-
On entry: indicates whether the Newton–Raphson or
algorithm should be used.
If , the Newton–Raphson algorithm is used.
If , the algorithm is used.
Constraint:
or .
- 2: – IntegerInput
-
On entry: , the number of observations.
Constraint:
.
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: the observations
,
or
, for
.
If the observation is exactly specified – the exact value, .
If the observation is right-censored – the lower value, .
If the observation is left-censored – the upper value, .
If the observation is interval-censored – the lower or upper value,
or
, (see
xc).
- 4: – Real (Kind=nag_wp) arrayInput
-
On entry: if the
th observation, for is an interval-censored observation then should contain the complementary value to , that is, if , then contains upper value, , and if , then contains lower value, . Otherwise if the th observation is exact or right- or left-censored need not be set.
Note: if then the observation is ignored.
- 5: – Integer arrayInput
-
On entry:
contains the censoring codes for the
th observation, for
.
If , the observation is exactly specified.
If , the observation is right-censored.
If , the observation is left-censored.
If , the observation is interval-censored.
Constraint:
, , or , for .
- 6: – Real (Kind=nag_wp)Input/Output
-
On entry: if
the initial estimate of the mean,
; otherwise
xmu need not be set.
On exit: the maximum likelihood estimate, , of .
- 7: – Real (Kind=nag_wp)Input/Output
-
On entry: specifies whether an initial estimate of
and
are to be supplied.
- xsig is the initial estimate of and xmu must contain an initial estimate of .
- Initial estimates of xmu and xsig are calculated internally from:
(a) |
the exact observations, if the number of exactly specified observations is ; or |
(b) |
the interval-censored observations; if the number of interval-censored observations is ; or |
(c) |
they are set to and respectively. |
On exit: the maximum likelihood estimate, , of .
- 8: – 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 , a relative precision of is used.
Constraint:
or .
- 9: – IntegerInput
-
On entry: the maximum number of iterations.
If , a value of is used.
- 10: – Real (Kind=nag_wp)Output
-
On exit: the estimate of the standard error of .
- 11: – Real (Kind=nag_wp)Output
-
On exit: the estimate of the standard error of .
- 12: – Real (Kind=nag_wp)Output
-
On exit: the estimate of the correlation between and .
- 13: – Real (Kind=nag_wp)Output
-
On exit: the maximized log-likelihood, .
- 14: – Integer arrayOutput
-
On exit: the number of the different types of each observation;
contains number of right-censored observations.
contains number of left-censored observations.
contains number of interval-censored observations.
contains number of exactly specified observations.
- 15: – IntegerOutput
-
On exit: the number of iterations performed.
- 16: – Real (Kind=nag_wp) arrayWorkspace
-
- 17: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, effective number of observations .
On entry, and .
Constraint: , , or .
On entry, .
Constraint: or .
On entry, .
Constraint: .
On entry, .
Constraint: or .
-
The chosen method has not converged in
iterations. You should either increase
tol or
maxit or, if using the
algorithm try using the Newton–Raphson method with initial values those returned by the current call to
g07bbf. All returned values will be reasonable approximations to the correct results if
maxit is not very small.
-
The EM process has failed. Different initial values should be tried.
The process has diverged. Different initial values should be tried.
-
Standard errors cannot be computed. This can be caused by the method starting to diverge when the maximum number of iterations was reached.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The accuracy is controlled by the argument
tol.
If high precision is requested with the
algorithm then there is a possibility that, due to the slow convergence, before the correct solution has been reached the increments of
and
may be smaller than
tol and the process will prematurely assume convergence.
8
Parallelism and Performance
g07bbf is not threaded in any implementation.
The process is deemed divergent if three successive increments of or increase.
10
Example
A sample of observations and their censoring codes are read in and the Newton–Raphson method used to compute the estimates.
10.1
Program Text
Program Text (g07bbfe.f90)
10.2
Program Data
Program Data (g07bbfe.d)
10.3
Program Results
Program Results (g07bbfe.r)