NAG Library Routine Document
g02dkf (linregm_constrain)
1
Purpose
g02dkf calculates the estimates of the arguments of a general linear regression model for given constraints from the singular value decomposition results.
2
Specification
Fortran Interface
Subroutine g02dkf ( 
ip, iconst, p, c, ldc, b, rss, idf, se, cov, wk, ifail) 
Integer, Intent (In)  ::  ip, iconst, ldc, idf  Integer, Intent (Inout)  ::  ifail  Real (Kind=nag_wp), Intent (In)  ::  p(ip*ip+2*ip), c(ldc,iconst), rss  Real (Kind=nag_wp), Intent (Inout)  ::  b(ip)  Real (Kind=nag_wp), Intent (Out)  ::  se(ip), cov(ip*(ip+1)/2), wk(2*ip*ip+ip*iconst+2*iconst*iconst+4*iconst) 

C Header Interface
#include nagmk26.h
void 
g02dkf_ (const Integer *ip, const Integer *iconst, const double p[], const double c[], const Integer *ldc, double b[], const double *rss, const Integer *idf, double se[], double cov[], double wk[], Integer *ifail) 

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,
${\hat{\beta}}_{\text{svd}}$, and their variancecovariance matrix. Details of the SVD are made available in the form of the matrix
${P}^{*}$:
as described by
g02daf and
g02ddf.
Alternative solutions can be formed by imposing constraints on the arguments. If there are $p$ arguments and the rank of the model is $k$, then ${n}_{c}=pk$ constraints will have to be imposed to obtain a unique solution.
Let
$C$ be a
$p$ by
${n}_{c}$ matrix of constraints, such that
then the new parameter estimates
${\hat{\beta}}_{c}$ are given by
where
$I$ is the identity matrix, and the variancecovariance matrix is given by
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
Arguments
 1: $\mathbf{ip}$ – IntegerInput

On entry: $p$, the number of terms in the linear model.
Constraint:
${\mathbf{ip}}\ge 1$.
 2: $\mathbf{iconst}$ – IntegerInput

On entry: the number of constraints to be imposed on the arguments, ${n}_{\mathrm{c}}$.
Constraint:
$0<{\mathbf{iconst}}<{\mathbf{ip}}$.
 3: $\mathbf{p}\left({\mathbf{ip}}\times {\mathbf{ip}}+2\times {\mathbf{ip}}\right)$ – Real (Kind=nag_wp) arrayInput

On entry: as returned by
g02daf and
g02ddf.
 4: $\mathbf{c}\left({\mathbf{ldc}},{\mathbf{iconst}}\right)$ – 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: $\mathbf{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: $\mathbf{b}\left({\mathbf{ip}}\right)$ – Real (Kind=nag_wp) arrayInput/Output

On entry: the parameter estimates computed by using the singular value decomposition, ${\hat{\beta}}_{\text{svd}}$.
On exit: the parameter estimates of the arguments with the constraints imposed, ${\hat{\beta}}_{\mathrm{c}}$.

On entry: the residual sum of squares as returned by
g02daf or
g02ddf.
Constraint:
${\mathbf{rss}}>0.0$.
 8: $\mathbf{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: $\mathbf{se}\left({\mathbf{ip}}\right)$ – Real (Kind=nag_wp) arrayOutput

On exit: the standard error of the parameter estimates in
b.
 10: $\mathbf{cov}\left({\mathbf{ip}}\times \left({\mathbf{ip}}+1\right)/2\right)$ – Real (Kind=nag_wp) arrayOutput

On exit: the upper triangular part of the variancecovariance 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\times \left(j1\right)/2+i\right)\right)$.
 11: $\mathbf{wk}\left(2\times {\mathbf{ip}}\times {\mathbf{ip}}+{\mathbf{ip}}\times {\mathbf{iconst}}+2\times {\mathbf{iconst}}\times {\mathbf{iconst}}+4\times {\mathbf{iconst}}\right)$ – Real (Kind=nag_wp) arrayWorkspace

Note that a simple upper bound for the size of the workspace is $5\times {\mathbf{ip}}\times {\mathbf{ip}}$.
 12: $\mathbf{ifail}$ – IntegerInput/Output

On entry:
ifail must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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}}=0$ or
$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{iconst}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{iconst}}>0$.
On entry, ${\mathbf{iconst}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{ip}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{iconst}}<{\mathbf{ip}}$.
On entry, ${\mathbf{idf}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{idf}}>0$.
On entry, ${\mathbf{ip}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{ip}}\ge 1$.
On entry, ${\mathbf{ldc}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{ip}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{ldc}}\ge {\mathbf{ip}}$.
On entry, ${\mathbf{rss}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{rss}}>0.0$.
 ${\mathbf{ifail}}=2$

c does not give a model of full rank.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
It should be noted that due to rounding errors an argument that should be zero when the constraints have been imposed may be returned as a value of order machine precision.
8
Parallelism and Performance
g02dkf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02dkf 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 implementationspecific information.
g02dkf is intended for use in situations in which dummy ($0\u20131$) variables have been used such as in the analysis of designed experiments when you do not wish to change the arguments 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.
10
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.
10.1
Program Text
Program Text (g02dkfe.f90)
10.2
Program Data
Program Data (g02dkfe.d)
10.3
Program Results
Program Results (g02dkfe.r)