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.
The routine may be called by the names g02daf or nagf_correg_linregm_fit.
3Description
The general linear regression model is defined by
where
is a vector of observations on the dependent variable,
is an 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 upper triangular matrix and is an 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 diagonal matrix with nonzero diagonal elements, being the rank of , and and are 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 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 g02defandg02dff or estimating and testing an estimable function using g02dnf. For the same matrix of independent variables, a new set of parameter estimates can be quickly calculated from a new vector of dependent variables using g02dgf. The details of the factorizations held in q, p and wk are only for use by this suite of routines and cannot be used by other routines that use such factorizations, e.g., f08agf since these will expect a different storage scheme for the input factorization.
4References
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
5Arguments
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.
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 .
On entry: if wt must contain the weights to be used with the model.
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 .
11: – Real (Kind=nag_wp)Output
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 .
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 for details).
If , the first ip elements of p will contain the zeta values for the decomposition (see f08aef 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 , 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).
6Error 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, .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: or .
On entry, .
Constraint: or .
On entry, .
Constraint: , for .
On entry, .
Constraint: ip must be compatible with the number of nonzero elements in isx.
On entry, .
Constraint: , for .
The degrees of freedom for the residuals are zero, i.e., the designated number of arguments 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.
SVD solution failed to converge.
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.
7Accuracy
The accuracy of g02daf is closely related to the accuracy of f02wufandf08aef. These routine documents should be consulted.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
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.
9Further Comments
Standardized residuals and further measures of influence can be computed using g02faf. g02faf requires, in particular, the results stored in res and h.
10Example
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.