NAG Library Function Document
nag_robust_m_corr_user_fn (g02hlc)
1 Purpose
nag_robust_m_corr_user_fn (g02hlc) calculates a robust estimate of the covariance matrix for user-supplied weight functions and their derivatives.
2 Specification
#include <nag.h> |
#include <nagg02.h> |
void |
nag_robust_m_corr_user_fn (Nag_OrderType order,
void |
(*ucv)(double t,
double *u,
double *ud,
double *w,
double *wd,
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) |
|
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. |
nag_robust_m_corr_user_fn (g02hlc) 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)).
nag_robust_m_corr_user_fn (g02hlc) finds
using the iterative procedure as given by Huber.
and
where
, for
and
, is a lower triangular matrix such that:
where
- , for
- and and are suitable bounds.
nag_robust_m_corr_user_fn (g02hlc) 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_OrderTypeInput
-
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 2.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint:
or .
- 2:
– function, supplied by the userExternal Function
-
ucv must return the values of the functions
and
and their derivatives for a given value of its argument.
The specification of
ucv is:
void |
ucv (double t,
double *u,
double *ud,
double *w,
double *wd,
Nag_Comm *comm)
|
|
- 1:
– doubleInput
-
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 derivative of the
function at the point
t.
- 4:
– double *Output
-
On exit: the value of the
function at the point
t.
Constraint:
.
- 5:
– double *Output
-
On exit: the value of the derivative of the
function at the point
t.
- 6:
– 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 nag_robust_m_corr_user_fn (g02hlc) you may allocate memory and initialize these pointers with various quantities for use by
ucv when called from nag_robust_m_corr_user_fn (g02hlc) (see
Section 2.3.1.1 in How to Use the NAG Library and its Documentation).
- 3:
– IntegerInput
-
On entry: indicates which form of the function
will be used.
- .
- .
- 4:
– IntegerInput
-
On entry: , the number of observations.
Constraint:
.
- 5:
– IntegerInput
-
On entry: , the number of columns of the matrix , i.e., number of independent variables.
Constraint:
.
- 6:
– const doubleInput
-
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:
– IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
x.
Constraints:
- if ,
;
- if , .
- 8:
– doubleOutput
-
On exit: contains a robust estimate of the covariance matrix, . The upper triangular part of the matrix is stored packed by columns (lower triangular stored by rows), is returned in , .
- 9:
– doubleInput/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:
– doubleOutput
-
On exit: contains the weights, , for .
- 11:
– doubleInput/Output
-
On entry: an initial estimate of the location argument,
, for
.
In many cases an initial estimate of
, for
, will be adequate. Alternatively medians may be used as given by
nag_median_1var (g07dac).
On exit: contains the robust estimate of the location argument,
, for .
- 12:
– doubleInput
-
On entry: the magnitude of the bound for the off-diagonal elements of , .
Suggested value:
.
Constraint:
.
- 13:
– doubleInput
-
On entry: the magnitude of the bound for the diagonal elements of , .
Suggested value:
.
Constraint:
.
- 14:
– IntegerInput
-
On entry: the maximum number of iterations that will be used during the calculation of .
Suggested value:
.
Constraint:
.
- 15:
– IntegerInput
-
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:
– doubleInput
-
On entry: the relative precision for the final estimates 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 2.3.1.1 in How to Use the NAG Library and its Documentation).
- 20:
– NagError *Input/Output
-
The NAG error argument (see
Section 2.7 in How to Use the NAG Library and its Documentation).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_CONST_COL
-
Column
of
x has constant value.
- NE_CONVERGENCE
-
Iterations to calculate weights failed to converge.
- NE_FUN_RET_VAL
-
value returned by : .
value returned by : .
- 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.
An unexpected error has been triggered by this function. Please contact
NAG.
See
Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation 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, diagonal element
of
a is
.
- NE_ZERO_SUM
-
The sum is zero.
The sum is zero.
The sum is zero.
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
nag_robust_m_corr_user_fn (g02hlc) 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.
10 Example
A sample of
observations on three variables is read in along with initial values for
and
theta and argument values for the
and
functions,
and
. The covariance matrix computed by nag_robust_m_corr_user_fn (g02hlc) is printed along with the robust estimate of
.
ucv computes the Huber's weight functions:
and
and their derivatives.
10.1 Program Text
Program Text (g02hlce.c)
10.2 Program Data
Program Data (g02hlce.d)
10.3 Program Results
Program Results (g02hlce.r)