NAG Library Routine Document
G02DDF calculates the regression parameters for a general linear regression model. It is intended to be called after G02DCF
|SUBROUTINE G02DDF (
||N, IP, Q, LDQ, RSS, IDF, B, SE, COV, SVD, IRANK, P, TOL, WK, IFAIL)
||N, IP, LDQ, IDF, IRANK, IFAIL
||Q(LDQ,IP+1), RSS, B(IP), SE(IP), COV(IP*(IP+1)/2), P(IP*IP+2*IP), TOL, WK(IP*IP+(IP-1)*5)
A general linear regression model fitted by G02DAF
may be adjusted by adding or deleting an observation using G02DCF
, adding a new independent variable using G02DEF
or deleting an existing independent variable using G02DFF
. Alternatively a model may be constructed by a forward selection procedure using G02EEF
. These routines compute the vector
and the upper triangular matrix
. G02DDF takes these basic results and computes the regression coefficients,
, their standard errors and their variance-covariance matrix.
is of full rank, then
is the solution to
is the first
is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of
diagonal matrix with nonzero diagonal elements,
being the rank of
orthogonal matrices. This gives the solution
being the first
being the first
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 calling G02DKF
after calling G02DDF. Only certain linear combinations of the parameters will have unique estimates; these are known as estimable functions. These can be estimated using G02DNF
The residual sum of squares required to calculate the standard errors and the variance-covariance matrix can either be input or can be calculated if additional information on for the whole sample is provided.
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
Searle S R (1971) Linear Models Wiley
- 1: N – INTEGERInput
On entry: the number of observations.
- 2: IP – INTEGERInput
On entry: , the number of terms in the regression model.
- 3: Q(LDQ,) – REAL (KIND=nag_wp) arrayInput
: must be the array Q
as output by G02DCF
. If on entry
then all N
are needed. This is provided by routines G02DEF
- 4: LDQ – INTEGERInput
: the first dimension of the array Q
as declared in the (sub)program from which G02DDF is called.
- if , ;
- otherwise .
On entry: either the residual sum of squares or a value less than or equal to to indicate that the residual sum of squares is to be calculated by the routine.
on entry, then on exit RSS
will contain the residual sum of squares as calculated by G02DDF.
was positive on entry, it will be unchanged.
- 6: IDF – INTEGEROutput
On exit: the degrees of freedom associated with the residual sum of squares.
- 7: B(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the estimates of the parameters, .
- 8: SE(IP) – REAL (KIND=nag_wp) arrayOutput
: the standard errors of the
parameters given in B
- 9: COV() – REAL (KIND=nag_wp) arrayOutput
: the upper triangular part of the variance-covariance matrix of the
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
- 10: SVD – LOGICALOutput
On exit: if a singular value decomposition has been performed, , otherwise .
- 11: IRANK – INTEGEROutput
: the rank of the independent variables.
If , .
is an estimate of the rank of the independent variables.
is calculated as the number of singular values greater than
(largest singular value). It is possible for the SVD to be carried out but IRANK
to be returned as IP
- 12: P() – REAL (KIND=nag_wp) arrayOutput
: contains details of the singular value decomposition if used.
is not referenced.
, the first IP
elements of P
will not be referenced, the next IP
values contain the singular values. The following
values contain the matrix
stored by columns.
- 13: TOL – REAL (KIND=nag_wp)Input
: 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 inaccuracies if the independent variables are not of full rank.
- 14: WK() – REAL (KIND=nag_wp) arrayWorkspace
- 15: IFAIL – INTEGERInput/Output
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.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
The degrees of freedom for error are less than or equal to . In this case the estimates of are returned but not the standard errors or covariances.
The singular value decomposition, if used, has failed to converge, see F02WUF
. This is an unlikely error exit.
The accuracy of the results will depend on the accuracy of the input matrix, which may lose accuracy if a large number of observations or variables have been dropped.
A dataset consisting of
observations and four independent variables is input and a regression model fitted by calls to G02DEF
. The parameters are then calculated by G02DDF and the results printed.
9.1 Program Text
Program Text (g02ddfe.f90)
9.2 Program Data
Program Data (g02ddfe.d)
9.3 Program Results
Program Results (g02ddfe.r)