NAG CL Interface
g02hmc (robustm_corr_user)
1
Purpose
g02hmc computes a robust estimate of the covariance matrix for user-supplied weight functions. The derivatives of the weight functions are not required.
2
Specification
void |
g02hmc (Nag_OrderType order,
void |
(*ucv)(double t,
double *u,
double *w,
Nag_Comm *comm),
|
|
Integer indm,
Integer n,
Integer m,
const double x[],
Integer pdx,
double cov[],
double a[],
double wt[],
double theta[],
double bl,
double bd,
Integer maxit,
Integer nitmon,
const char *outfile,
double tol,
Integer *nit,
Nag_Comm *comm,
NagError *fail) |
|
The function may be called by the names: g02hmc, nag_correg_robustm_corr_user or nag_robust_m_corr_user_fn_no_derr.
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. |
g02hmc 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)).
g02hmc 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.
g02hmc 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:
– Nag_OrderType
Input
-
On entry: the
order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by
. See
Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint:
or .
-
2:
– function, supplied by the user
External Function
-
ucv must return the values of the functions
and
for a given value of its argument.
The specification of
ucv is:
void |
ucv (double t,
double *u,
double *w,
Nag_Comm *comm)
|
|
-
1:
– double
Input
-
On entry: the argument for which the functions and must be evaluated.
-
2:
– double *
Output
-
On exit: the value of the
function at the point
t.
Constraint:
.
-
3:
– double *
Output
-
On exit: the value of the
function at the point
t.
Constraint:
.
-
4:
– Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to
ucv.
- user – double *
- iuser – Integer *
- p – Pointer
The type Pointer will be
void *. Before calling
g02hmc you may allocate memory and initialize these pointers with various quantities for use by
ucv when called from
g02hmc (see
Section 3.1.1 in the Introduction to the NAG Library CL Interface).
Note: ucv should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
g02hmc. If your code inadvertently
does return any NaNs or infinities,
g02hmc is likely to produce unexpected results.
-
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:
– const double
Input
-
Note: the dimension,
dim, of the array
x
must be at least
-
when ;
-
when .
where
appears in this document, it refers to the array element
- when ;
- when .
On entry: must contain the th observation on the th variable, for and .
-
7:
– Integer
Input
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
x.
Constraints:
- if ,
;
- if , .
-
8:
– double
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:
– double
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:
– double
Output
-
On exit: contains the weights, , for .
-
11:
– double
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
g07dac.
On exit: contains the robust estimate of the location parameter,
, for .
-
12:
– double
Input
-
On entry: the magnitude of the bound for the off-diagonal elements of , .
Suggested value:
.
Constraint:
.
-
13:
– double
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.
-
16:
– const char *
Input
-
On entry: a null terminated character string giving the name of the file to which results should be printed. If or an empty string then the stdout stream is used. Note that the file will be opened in the append mode.
-
17:
– double
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:
.
-
18:
– Integer *
Output
-
On exit: the number of iterations performed.
-
19:
– Nag_Comm *
-
The NAG communication argument (see
Section 3.1.1 in the Introduction to the NAG Library CL Interface).
-
20:
– NagError *
Input/Output
-
The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
6
Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_CONST_COL
-
On entry, a variable has a constant value, i.e., all elements in column
of
x are identical.
- NE_CONVERGENCE
-
Iterations to calculate weights failed to converge.
- NE_FUN_RET_VAL
-
value returned by : .
Constraint: .
value returned by : .
Constraint: .
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
-
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
- NE_INTERNAL_ERROR
-
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
See
Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library CL Interface for further information.
- NE_NOT_CLOSE_FILE
-
Cannot close file .
- NE_NOT_WRITE_FILE
-
Cannot open file for writing.
- NE_REAL
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_ZERO_DIAGONAL
-
On entry, and the th diagonal element of is .
Constraint: all diagonal elements of must be non-zero.
- NE_ZERO_SUM
-
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.
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
g02hmc 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 function. 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
g02hlc 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 g02hmc 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