G02DKF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02DKF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G02DKF calculates the estimates of the parameters of a general linear regression model for given constraints from the singular value decomposition results.

## 2  Specification

 SUBROUTINE G02DKF ( IP, ICONST, P, C, LDC, B, RSS, IDF, SE, COV, WK, IFAIL)
 INTEGER IP, ICONST, LDC, IDF, IFAIL REAL (KIND=nag_wp) P(IP*IP+2*IP), C(LDC,ICONST), B(IP), RSS, SE(IP), COV(IP*(IP+1)/2), WK(2*IP*IP+IP*ICONST+2*ICONST*ICONST+4*ICONST)

## 3  Description

G02DKF computes the estimates given a set of linear constraints for a general linear regression model which is not of full rank. It is intended for use after a call to G02DAF or G02DDF.
In the case of a model not of full rank the routines use a singular value decomposition (SVD) to find the parameter estimates, ${\stackrel{^}{\beta }}_{\text{svd}}$, and their variance-covariance matrix. Details of the SVD are made available in the form of the matrix ${P}^{*}$:
 $P*= D-1 P1T P0T ,$
as described by G02DAF and G02DDF.
Alternative solutions can be formed by imposing constraints on the parameters. If there are $p$ parameters and the rank of the model is $k$, then ${n}_{c}=p-k$ constraints will have to be imposed to obtain a unique solution.
Let $C$ be a $p$ by ${n}_{c}$ matrix of constraints, such that
 $CTβ=0$
then the new parameter estimates ${\stackrel{^}{\beta }}_{c}$ are given by
 $β^c =Aβ^svd; =I-P0CTP0-1β^svd,$
where $I$ is the identity matrix, and the variance-covariance matrix is given by
 $AP1D-2P1TAT,$
provided ${\left({C}^{\mathrm{T}}{P}_{0}\right)}^{-1}$ exists.

## 4  References

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

## 5  Parameters

1:     IP – INTEGERInput
On entry: $p$, the number of terms in the linear model.
Constraint: ${\mathbf{IP}}\ge 1$.
2:     ICONST – INTEGERInput
On entry: the number of constraints to be imposed on the parameters, ${n}_{\mathrm{c}}$.
Constraint: $0<{\mathbf{ICONST}}<{\mathbf{IP}}$.
3:     P(${\mathbf{IP}}×{\mathbf{IP}}+2×{\mathbf{IP}}$) – REAL (KIND=nag_wp) arrayInput
On entry: as returned by G02DAF and G02DDF.
4:     C(LDC,ICONST) – REAL (KIND=nag_wp) arrayInput
On entry: the ICONST constraints stored by column, i.e., the $i$th constraint is stored in the $i$th column of C.
5:     LDC – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which G02DKF is called.
Constraint: ${\mathbf{LDC}}\ge {\mathbf{IP}}$.
6:     B(IP) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the parameter estimates computed by using the singular value decomposition, ${\stackrel{^}{\beta }}_{\text{svd}}$.
On exit: the parameter estimates of the parameters with the constraints imposed, ${\stackrel{^}{\beta }}_{\mathrm{c}}$.
7:     RSS – REAL (KIND=nag_wp)Input
On entry: the residual sum of squares as returned by G02DAF or G02DDF.
Constraint: ${\mathbf{RSS}}>0.0$.
8:     IDF – INTEGERInput
On entry: the degrees of freedom associated with the residual sum of squares as returned by G02DAF or G02DDF.
Constraint: ${\mathbf{IDF}}>0$.
9:     SE(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the standard error of the parameter estimates in B.
10:   COV(${\mathbf{IP}}×\left({\mathbf{IP}}+1\right)/2$) – REAL (KIND=nag_wp) arrayOutput
On exit: 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 ${\mathbf{B}}\left(i\right)$ and the parameter estimate given in ${\mathbf{B}}\left(j\right)$, $j\ge i$, is stored in ${\mathbf{COV}}\left(\left(j×\left(j-1\right)/2+i\right)\right)$.
11:   WK($2×{\mathbf{IP}}×{\mathbf{IP}}+{\mathbf{IP}}×{\mathbf{ICONST}}+2×{\mathbf{ICONST}}×{\mathbf{ICONST}}+4×{\mathbf{ICONST}}$) – REAL (KIND=nag_wp) arrayWorkspace
Note that a simple upper bound for the size of the workspace is $5×{\mathbf{IP}}×{\mathbf{IP}}$.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. 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 $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{IP}}<1$, or ${\mathbf{ICONST}}\le 0$, or ${\mathbf{ICONST}}\ge {\mathbf{IP}}$, or ${\mathbf{LDC}}<{\mathbf{IP}}$, or ${\mathbf{RSS}}\le 0.0$, or ${\mathbf{IDF}}\le 0$.
${\mathbf{IFAIL}}=2$
C does not give a model of full rank.

## 7  Accuracy

It should be noted that due to rounding errors a parameter that should be zero when the constraints have been imposed may be returned as a value of order machine precision.

## 8  Further Comments

G02DKF is intended for use in situations in which dummy ($0–1$) variables have been used such as in the analysis of designed experiments when you do not wish to change the parameters of the model to give a full rank model. The routine is not intended for situations in which the relationships between the independent variables are only approximate.

## 9  Example

Data from an experiment with four treatments and three observations per treatment are read in. A model, including the mean term, is fitted by G02DAF and the results printed. The constraint that the sum of treatment effect is zero is then read in and the parameter estimates with this constraint imposed are computed by G02DKF and printed.

### 9.1  Program Text

Program Text (g02dkfe.f90)

### 9.2  Program Data

Program Data (g02dkfe.d)

### 9.3  Program Results

Program Results (g02dkfe.r)

G02DKF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual