NAG Library Routine Document
G02DAF
1 Purpose
G02DAF performs a general multiple linear regression when the independent variables may be linearly dependent. Parameter estimates, standard errors, residuals and influence statistics are computed. G02DAF may be used to perform a weighted regression.
2 Specification
SUBROUTINE G02DAF ( |
MEAN, WEIGHT, N, X, LDX, M, ISX, IP, Y, WT, RSS, IDF, B, SE, COV, RES, H, Q, LDQ, SVD, IRANK, P, TOL, WK, IFAIL) |
INTEGER |
N, LDX, M, ISX(M), IP, IDF, LDQ, IRANK, IFAIL |
REAL (KIND=nag_wp) |
X(LDX,M), Y(N), WT(*), RSS, B(IP), SE(IP), COV(IP*(IP+1)/2), RES(N), H(N), Q(LDQ,IP+1), P(2*IP+IP*IP), TOL, WK(max(2,5*(IP-1)+IP*IP)) |
LOGICAL |
SVD |
CHARACTER(1) |
MEAN, WEIGHT |
|
3 Description
The general linear regression model is defined by
where
- is a vector of observations on the dependent variable,
- is an by matrix of the independent variables of column rank ,
- is a vector of length of unknown parameters, and
- is a vector of length of unknown random errors such that , where is a known diagonal matrix.
If , the identity matrix, then least squares estimation is used. If , then for a given weight matrix , weighted least squares estimation is used.
The least squares estimates of the parameters minimize while the weighted least squares estimates minimize .
G02DAF finds a
decomposition of
(or
in weighted case), i.e.,
where
and
is a
by
upper triangular matrix and
is an
by
orthogonal matrix. If
is of full rank, then
is the solution to
where
(or
) and
is the first
elements of
. If
is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of
,
where
is a
by
diagonal matrix with nonzero diagonal elements,
being the rank of
, and
and
are
by
orthogonal matrices. This gives the solution
being the first
columns of
, i.e.,
, and
being the first
columns of
.
Details of the SVD, are made available, in the form of the matrix
:
This will be only one of the possible solutions. Other estimates may be obtained by applying constraints to the parameters. These solutions can be obtained by using
G02DKF after using G02DAF. Only certain linear combinations of the parameters will have unique estimates; these are known as estimable functions.
The fit of the model can be examined by considering the residuals, , where are the fitted values. The fitted values can be written as for an by matrix . The th diagonal elements of , , give a measure of the influence of the th values of the independent variables on the fitted regression model. The values are sometimes known as leverages. Both and are provided by G02DAF.
The output of G02DAF also includes , the residual sum of squares and associated degrees of freedom, , the standard errors of the parameter estimates and the variance-covariance matrix of the parameter estimates.
In many linear regression models the first term is taken as a mean term or an intercept, i.e., , for . This is provided as an option. Also only some of the possible independent variables are required to be included in a model, a facility to select variables to be included in the model is provided.
Details of the
decomposition and, if used, the SVD, are made available. These allow the regression to be updated by adding or deleting an observation using
G02DCF, adding or deleting a variable using
G02DEF and
G02DFF or estimating and testing an estimable function using
G02DNF.
4 References
Cook R D and Weisberg S (1982) Residuals and Influence in Regression Chapman and Hall
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Hammarling S (1985) The singular value decomposition in multivariate statistics SIGNUM Newsl. 20(3) 2–25
McCullagh P and Nelder J A (1983) Generalized Linear Models Chapman and Hall
Searle S R (1971) Linear Models Wiley
5 Parameters
- 1: – CHARACTER(1)Input
-
On entry: indicates if a mean term is to be included.
- A mean term, intercept, will be included in the model.
- The model will pass through the origin, zero-point.
Constraint:
or .
- 2: – CHARACTER(1)Input
-
On entry: indicates if weights are to be used.
- Least squares estimation is used.
- Weighted least squares is used and weights must be supplied in array WT.
Constraint:
or .
- 3: – INTEGERInput
-
On entry: , the number of observations.
Constraint:
.
- 4: – REAL (KIND=nag_wp) arrayInput
-
On entry: must contain the th observation for the th independent variable, for and .
- 5: – INTEGERInput
-
On entry: the first dimension of the array
X as declared in the (sub)program from which G02DAF is called.
Constraint:
.
- 6: – INTEGERInput
-
On entry: , the total number of independent variables in the dataset.
Constraint:
.
- 7: – INTEGER arrayInput
-
On entry: indicates which independent variables are to be included in the model.
- The variable contained in the th column of X is included in the regression model.
Constraints:
- , for ;
- if , exactly values of ISX must be ;
- if , exactly IP values of ISX must be .
- 8: – INTEGERInput
-
On entry: the number of independent variables in the model, including the mean or intercept if present.
Constraints:
- if , ;
- if , ;
- otherwise .
- 9: – REAL (KIND=nag_wp) arrayInput
-
On entry: , the observations on the dependent variable.
- 10: – REAL (KIND=nag_wp) arrayInput
-
Note: the dimension of the array
WT
must be at least
if
, and at least
otherwise.
On entry: if
,
WT must contain the weights to be used in the weighted regression.
If
, the
th observation is not included in the model, in which case the effective number of observations is the number of observations with nonzero weights. The values of
RES and
H will be set to zero for observations with zero weights.
If
,
WT is not referenced and the effective number of observations is
.
Constraint:
if , , for .
-
On exit: the residual sum of squares for the regression.
- 12: – INTEGEROutput
-
On exit: the degrees of freedom associated with the residual sum of squares.
- 13: – REAL (KIND=nag_wp) arrayOutput
-
On exit:
,
contains the least squares estimates of the parameters of the regression model,
.
If
,
will contain the estimate of the mean parameter and
will contain the coefficient of the variable contained in column
of
X, where
is the
th positive value in the array
ISX.
If
,
will contain the coefficient of the variable contained in column
of
X, where
is the
th positive value in the array
ISX.
- 14: – REAL (KIND=nag_wp) arrayOutput
-
On exit:
,
contains the standard errors of the
IP parameter estimates given in
B.
- 15: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the first
elements of
COV contain the upper triangular part of the variance-covariance matrix of the
IP parameter estimates given in
B. They are stored packed by column, i.e., the covariance between the parameter estimate given in
and the parameter estimate given in
,
, is stored in
.
- 16: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the (weighted) residuals,
, for .
- 17: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the diagonal elements of ,
, for .
- 18: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the results of the
decomposition:
- the first column of Q contains ;
- the upper triangular part of columns to contain the matrix;
- the strictly lower triangular part of columns to contain details of the matrix.
- 19: – INTEGERInput
-
On entry: the first dimension of the array
Q as declared in the (sub)program from which G02DAF is called.
Constraint:
.
- 20: – LOGICALOutput
-
On exit: if a singular value decomposition has been performed then
SVD will be .TRUE., otherwise
SVD will be .FALSE..
- 21: – INTEGEROutput
-
On exit: the rank of the independent variables.
If , .
If
,
IRANK is an estimate of the rank of the independent variables.
IRANK is calculated as the number of singular values greater that
(largest singular value). It is possible for the SVD to be carried out but
IRANK to be returned as
IP.
- 22: – REAL (KIND=nag_wp) arrayOutput
-
On exit: details of the
decomposition and SVD if used.
If
, only the first
IP elements of
P are used these will contain the zeta values for the
decomposition (see
F08AEF (DGEQRF) for details).
If
, the first
IP elements of
P will contain the zeta values for the
decomposition (see
F08AEF (DGEQRF) for details) and the next
IP elements of
P contain singular values. The following
IP by
IP elements contain the matrix
stored by columns.
- 23: – REAL (KIND=nag_wp)Input
-
On entry: the value of
TOL is used to decide if the independent variables are of full rank and if not what is the rank of the independent variables. The smaller the value of
TOL the stricter the criterion for selecting the singular value decomposition. If
, the singular value decomposition will never be used; this may cause run time errors or inaccurate results if the independent variables are not of full rank.
Suggested value:
.
Constraint:
.
- 24: – REAL (KIND=nag_wp) arrayOutput
-
On exit: if on exit
,
WK contains information which is needed by
G02DGF; otherwise
WK is used as workspace.
- 25: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction 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 parameter, 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, | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | . |
-
On entry, | or , |
or | or . |
-
On entry, | and a value of . |
-
On entry, | a value of , |
or | the value of IP is incompatible with the values of MEAN and ISX, |
or | IP is greater than the effective number of observations. |
-
The degrees of freedom for the residuals are zero, i.e., the designated number of parameters is equal to the effective number of observations. In this case the parameter estimates will be returned along with the diagonal elements of , but neither standard errors nor the variance-covariance matrix will be calculated.
-
The singular value decomposition has failed to converge, see
F02WUF. This is an unlikely error.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
The accuracy of G02DAF is closely related to the accuracy of
F02WUF and
F08AEF (DGEQRF). These routine documents should be consulted.
8 Parallelism and Performance
G02DAF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02DAF 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.
Standardized residuals and further measures of influence can be computed using
G02FAF.
G02FAF requires, in particular, the results stored in
RES and
H.
10 Example
Data from an experiment with four treatments and three observations per treatment are read in. The treatments are represented by dummy (
) variables. An unweighted model is fitted with a mean included in the model.
G02BUF is then called to calculate the total sums of squares and the coefficient of determination (
), adjusted
and Akaike's information criteria (AIC) are calculated.
G02BUF is then called to calculate the total sums of squares and the coefficient of determination (
), adjusted
and Akaike's information criteria (AIC) are calculated.
10.1 Program Text
Program Text (g02dafe.f90)
10.2 Program Data
Program Data (g02dafe.d)
10.3 Program Results
Program Results (g02dafe.r)