NAG FL Interface
g02hmf (robustm_corr_user)
1
Purpose
g02hmf computes a robust estimate of the covariance matrix for user-supplied weight functions. The derivatives of the weight functions are not required.
2
Specification
Fortran Interface
Subroutine g02hmf ( |
ucv, ruser, indm, n, m, x, ldx, cov, a, wt, theta, bl, bd, maxit, nitmon, tol, nit, wk, ifail) |
Integer, Intent (In) |
:: |
indm, n, m, ldx, maxit, nitmon |
Integer, Intent (Inout) |
:: |
ifail |
Integer, Intent (Out) |
:: |
nit |
Real (Kind=nag_wp), Intent (In) |
:: |
x(ldx,m), bl, bd, tol |
Real (Kind=nag_wp), Intent (Inout) |
:: |
ruser(*), a(m*(m+1)/2), theta(m) |
Real (Kind=nag_wp), Intent (Out) |
:: |
cov(m*(m+1)/2), wt(n), wk(2*m) |
External |
:: |
ucv |
|
C Header Interface
#include <nag.h>
void |
g02hmf_ ( void (NAG_CALL *ucv)(const double *t, double ruser[], double *u, double *w), double ruser[], const Integer *indm, const Integer *n, const Integer *m, const double x[], const Integer *ldx, double cov[], double a[], double wt[], double theta[], const double *bl, const double *bd, const Integer *maxit, const Integer *nitmon, const double *tol, Integer *nit, double wk[], Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
g02hmf_ ( void (NAG_CALL *ucv)(const double &t, double ruser[], double &u, double &w), double ruser[], const Integer &indm, const Integer &n, const Integer &m, const double x[], const Integer &ldx, double cov[], double a[], double wt[], double theta[], const double &bl, const double &bd, const Integer &maxit, const Integer &nitmon, const double &tol, Integer &nit, double wk[], Integer &ifail) |
}
|
The routine may be called by the names g02hmf or nagf_correg_robustm_corr_user.
3
Description
For a set of
observations on
variables in a matrix
, a robust estimate of the covariance matrix,
, and a robust estimate of location,
, are given by
where
is a correction factor and
is a lower triangular matrix found as the solution to the following equations.
and
where |
is a vector of length containing the elements of the th row of , |
|
is a vector of length , |
|
is the identity matrix and is the zero matrix. |
and |
and are suitable functions. |
g02hmf covers two situations:
-
(i) for all ,
-
(ii).
The robust covariance matrix may be calculated from a weighted sum of squares and cross-products matrix about
using weights
. In case
(i) a divisor of
is used and in case
(ii) a divisor of
is used. If
, then the robust covariance matrix can be calculated by scaling each row of
by
and calculating an unweighted covariance matrix about
.
In order to make the estimate asymptotically unbiased under a Normal model a correction factor,
, is needed. The value of the correction factor will depend on the functions employed (see
Huber (1981) and
Marazzi (1987)).
g02hmf finds
using the iterative procedure as given by Huber; see
Huber (1981).
and
where
, for
and
is a lower triangular matrix such that
where
- , for
and
and
are suitable bounds.
The value of may be chosen so that is unbiased if the observations are from a given distribution.
g02hmf is based on routines in ROBETH; see
Marazzi (1987).
4
References
Huber P J (1981) Robust Statistics Wiley
Marazzi A (1987) Weights for bounded influence regression in ROBETH Cah. Rech. Doc. IUMSP, No. 3 ROB 3 Institut Universitaire de Médecine Sociale et Préventive, Lausanne
5
Arguments
-
1:
– Subroutine, supplied by the user.
External Procedure
-
ucv must return the values of the functions
and
for a given value of its argument.
The specification of
ucv is:
Fortran Interface
Real (Kind=nag_wp), Intent (In) |
:: |
t |
Real (Kind=nag_wp), Intent (Inout) |
:: |
ruser(*) |
Real (Kind=nag_wp), Intent (Out) |
:: |
u, w |
|
C Header Interface
void |
ucv_ (const double *t, double ruser[], double *u, double *w) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
ucv_ (const double &t, double ruser[], double &u, double &w) |
}
|
-
1:
– Real (Kind=nag_wp)
Input
-
On entry: the argument for which the functions and must be evaluated.
-
2:
– Real (Kind=nag_wp) array
User Workspace
-
ucv is called with the argument
ruser as supplied to
g02hmf. You should use the array
ruser to supply information to
ucv.
-
3:
– Real (Kind=nag_wp)
Output
-
On exit: the value of the
function at the point
t.
Constraint:
.
-
4:
– Real (Kind=nag_wp)
Output
-
On exit: the value of the
function at the point
t.
Constraint:
.
ucv must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
g02hmf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: ucv should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
g02hmf. If your code inadvertently
does return any NaNs or infinities,
g02hmf is likely to produce unexpected results.
-
2:
– Real (Kind=nag_wp) array
User Workspace
-
ruser is not used by
g02hmf, but is passed directly to
ucv and may be used to pass information to this routine.
-
3:
– Integer
Input
-
On entry: indicates which form of the function
will be used.
- .
- .
-
4:
– Integer
Input
-
On entry: , the number of observations.
Constraint:
.
-
5:
– Integer
Input
-
On entry: , the number of columns of the matrix , i.e., number of independent variables.
Constraint:
.
-
6:
– Real (Kind=nag_wp) array
Input
-
On entry: must contain the th observation on the th variable, for and .
-
7:
– Integer
Input
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
g02hmf is called.
Constraint:
.
-
8:
– Real (Kind=nag_wp) array
Output
-
On exit: a robust estimate of the covariance matrix, . The upper triangular part of the matrix is stored packed by columns (lower triangular stored by rows), that is is returned in , .
-
9:
– Real (Kind=nag_wp) array
Input/Output
-
On entry: an initial estimate of the lower triangular real matrix
. Only the lower triangular elements must be given and these should be stored row-wise in the array.
The diagonal elements must be , and in practice will usually be . If the magnitudes of the columns of are of the same order, the identity matrix will often provide a suitable initial value for . If the columns of are of different magnitudes, the diagonal elements of the initial value of should be approximately inversely proportional to the magnitude of the columns of .
Constraint:
, for .
On exit: the lower triangular elements of the inverse of the matrix , stored row-wise.
-
10:
– Real (Kind=nag_wp) array
Output
-
On exit: contains the weights, , for .
-
11:
– Real (Kind=nag_wp) array
Input/Output
-
On entry: an initial estimate of the location parameter,
, for
.
In many cases an initial estimate of
, for
, will be adequate. Alternatively medians may be used as given by
g07daf.
On exit: contains the robust estimate of the location parameter,
, for .
-
12:
– Real (Kind=nag_wp)
Input
-
On entry: the magnitude of the bound for the off-diagonal elements of , .
Suggested value:
.
Constraint:
.
-
13:
– Real (Kind=nag_wp)
Input
-
On entry: the magnitude of the bound for the diagonal elements of , .
Suggested value:
.
Constraint:
.
-
14:
– Integer
Input
-
On entry: the maximum number of iterations that will be used during the calculation of .
Suggested value:
.
Constraint:
.
-
15:
– Integer
Input
-
On entry: indicates the amount of information on the iteration that is printed.
- The value of , and (see Section 7) will be printed at the first and every nitmon iterations.
- No iteration monitoring is printed.
When printing occurs the output is directed to the current advisory message channel (See
x04abf.)
-
16:
– Real (Kind=nag_wp)
Input
-
On entry: the relative precision for the final estimate of the covariance matrix. Iteration will stop when maximum
(see
Section 7) is less than
tol.
Constraint:
.
-
17:
– Integer
Output
-
On exit: the number of iterations performed.
-
18:
– Real (Kind=nag_wp) array
Workspace
-
-
19:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or 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, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, and .
Constraint: .
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, and the th diagonal element of is .
Constraint: all diagonal elements of must be non-zero.
On entry, .
Constraint: .
On entry, .
Constraint: .
-
On entry, a variable has a constant value, i.e., all elements in column
of
x are identical.
-
value returned by : .
Constraint: .
value returned by : .
Constraint: .
-
Iterations to calculate weights failed to converge.
-
The sum is zero. Try either a larger initial estimate of or make and less strict.
The sum is zero. Try either a larger initial estimate of or make and less strict.
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.
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.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
On successful exit the accuracy of the results is related to the value of
tol; see
Section 5. At an iteration let
-
(i) the maximum value of
-
(ii) the maximum absolute change in
-
(iii) the maximum absolute relative change in
and let
. Then the iterative procedure is assumed to have converged when
.
8
Parallelism and Performance
g02hmf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
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.
The existence of
will depend upon the function
(see
Marazzi (1987)); also if
is not of full rank a value of
will not be found. If the columns of
are almost linearly related, then convergence will be slow.
If derivatives of the
and
functions are available then the method used in
g02hlf will usually give much faster convergence.
10
Example
A sample of observations on three variables is read in along with initial values for and and parameter values for the and functions, and . The covariance matrix computed by g02hmf is printed along with the robust estimate of .
ucv computes the Huber's weight functions:
and
10.1
Program Text
10.2
Program Data
10.3
Program Results