NAG Library Function Document
nag_robust_m_corr_user_fn_no_derr (g02hmc)
1 Purpose
nag_robust_m_corr_user_fn_no_derr (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
| #include <nag.h> |
| #include <nagg02.h> |
| void |
nag_robust_m_corr_user_fn_no_derr (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) |
|
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_no_derr (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)).
nag_robust_m_corr_user_fn_no_derr (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.
nag_robust_m_corr_user_fn_no_derr (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:
order – 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 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint:
or Nag_ColMajor.
- 2:
ucv – function, supplied by the userExternal 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:
t – doubleInput
-
On entry: the argument for which the functions and must be evaluated.
- 2:
u – double *Output
-
On exit: the value of the
function at the point
t.
Constraint:
.
- 3:
w – double *Output
-
On exit: the value of the
function at the point
t.
Constraint:
.
- 4:
comm – 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_no_derr (g02hmc) you may allocate memory and initialize these pointers with various quantities for use by
ucv when called from nag_robust_m_corr_user_fn_no_derr (g02hmc) (see
Section 3.2.1 in the Essential Introduction).
- 3:
indm – IntegerInput
-
On entry: indicates which form of the function
will be used.
- .
- .
- 4:
n – IntegerInput
-
On entry:
, the number of observations.
Constraint:
.
- 5:
m – IntegerInput
-
On entry:
, the number of columns of the matrix , i.e., number of independent variables.
Constraint:
.
- 6:
x[] – 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:
pdx – IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
x.
Constraints:
- if ,
;
- if , .
- 8:
cov[] – doubleOutput
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:
a[] – 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:
wt[n] – doubleOutput
-
On exit: contains the weights, , for .
- 11:
theta[m] – 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:
bl – doubleInput
-
On entry: the magnitude of the bound for the off-diagonal elements of , .
Suggested value:
.
Constraint:
.
- 13:
bd – doubleInput
-
On entry: the magnitude of the bound for the diagonal elements of , .
Suggested value:
.
Constraint:
.
- 14:
maxit – IntegerInput
-
On entry: the maximum number of iterations that will be used during the calculation of .
Suggested value:
.
Constraint:
.
- 15:
nitmon – 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:
outfile – 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:
tol – doubleInput
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:
nit – Integer *Output
-
On exit: the number of iterations performed.
- 19:
comm – Nag_Comm *Communication Structure
-
The NAG communication argument (see
Section 3.2.1.1 in the Essential Introduction).
- 20:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
Dynamic memory allocation failed.
- 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: .
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.
- 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
Sum of 's () is zero.
Sum of 's () 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
.
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
nag_robust_m_corr_user_fn (g02hlc) will usually give much faster convergence.
9 Example
A sample of observations on three variables is read in along with initial values for and and argument values for the and functions, and . The covariance matrix computed by nag_robust_m_corr_user_fn_no_derr (g02hmc) is printed along with the robust estimate of .
ucv computes the Huber's weight functions:
and
9.1 Program Text
Program Text (g02hmce.c)
9.2 Program Data
Program Data (g02hmce.d)
9.3 Program Results
Program Results (g02hmce.r)