Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_correg_linregm_constrain (g02dk)

## Purpose

nag_correg_linregm_constrain (g02dk) calculates the estimates of the arguments of a general linear regression model for given constraints from the singular value decomposition results.

## Syntax

[b, se, covar, ifail] = g02dk(p, c, b, rss, idf, 'ip', ip, 'iconst', iconst)
[b, se, covar, ifail] = nag_correg_linregm_constrain(p, c, b, rss, idf, 'ip', ip, 'iconst', iconst)

## Description

nag_correg_linregm_constrain (g02dk) 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 nag_correg_linregm_fit (g02da) or nag_correg_linregm_update (g02dd).
In the case of a model not of full rank the functions 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 nag_correg_linregm_fit (g02da) and nag_correg_linregm_update (g02dd).
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}=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.

## 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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{p}\left({\mathbf{ip}}×{\mathbf{ip}}+2×{\mathbf{ip}}\right)$ – double array
2:     $\mathrm{c}\left(\mathit{ldc},{\mathbf{iconst}}\right)$ – double array
ldc, the first dimension of the array, must satisfy the constraint $\mathit{ldc}\ge {\mathbf{ip}}$.
The iconst constraints stored by column, i.e., the $i$th constraint is stored in the $i$th column of c.
3:     $\mathrm{b}\left({\mathbf{ip}}\right)$ – double array
The parameter estimates computed by using the singular value decomposition, ${\stackrel{^}{\beta }}_{\text{svd}}$.
4:     $\mathrm{rss}$ – double scalar
The residual sum of squares as returned by nag_correg_linregm_fit (g02da) or nag_correg_linregm_update (g02dd).
Constraint: ${\mathbf{rss}}>0.0$.
5:     $\mathrm{idf}$int64int32nag_int scalar
The degrees of freedom associated with the residual sum of squares as returned by nag_correg_linregm_fit (g02da) or nag_correg_linregm_update (g02dd).
Constraint: ${\mathbf{idf}}>0$.

### Optional Input Parameters

1:     $\mathrm{ip}$int64int32nag_int scalar
Default: the dimension of the array b and the first dimension of the array c. (An error is raised if these dimensions are not equal.)
$p$, the number of terms in the linear model.
Constraint: ${\mathbf{ip}}\ge 1$.
2:     $\mathrm{iconst}$int64int32nag_int scalar
Default: the second dimension of the array c.
The number of constraints to be imposed on the arguments, ${n}_{\mathrm{c}}$.
Constraint: $0<{\mathbf{iconst}}<{\mathbf{ip}}$.

### Output Parameters

1:     $\mathrm{b}\left({\mathbf{ip}}\right)$ – double array
The parameter estimates of the arguments with the constraints imposed, ${\stackrel{^}{\beta }}_{\mathrm{c}}$.
2:     $\mathrm{se}\left({\mathbf{ip}}\right)$ – double array
The standard error of the parameter estimates in b.
3:     $\mathrm{covar}\left({\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2\right)$ – double array
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{covar}}\left(\left(j×\left(j-1\right)/2+i\right)\right)$.
4:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ip}}<1$, or ${\mathbf{iconst}}\le 0$, or ${\mathbf{iconst}}\ge {\mathbf{ip}}$, or $\mathit{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.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

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

nag_correg_linregm_constrain (g02dk) 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 arguments of the model to give a full rank model. The function is not intended for situations in which the relationships between the independent variables are only approximate.

## 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 nag_correg_linregm_fit (g02da) 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 nag_correg_linregm_constrain (g02dk) and printed.
```function g02dk_example

fprintf('g02dk example results\n\n');

x = [1, 0, 0, 0;
0, 0, 0, 1;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1;
0, 1, 0, 0;
0, 0, 0, 1;
1, 0, 0, 0;
0, 0, 1, 0;
1, 0, 0, 0;
0, 0, 1, 0;
0, 1, 0, 0];
y = [33.63;     39.62;     38.18;     41.46;     38.02;     35.83;
35.99;     36.58;     42.92;     37.80;     40.43;     37.89];

[n,m]  = size(x);
isx    = ones(m,1,'int64');
mean_p = 'M';
ip     = int64(m+1);

% Fit general linear regression model
[rss, idf, b, se, covar, res, h, q, svd, irank, p, wk, ifail] = ...
g02da(mean_p, x, isx, ip, y);

% Display initial estimate results
fprintf('Initial estimates\n\n');
fprintf('Residual sum of squares = %12.4e\n', rss);
fprintf('Degrees of freedom      = %4d\n', idf);
fprintf('\nVariable   Parameter estimate   Standard error\n\n');
ivar = double([1:ip]');
fprintf('%6d%20.4e%20.4e\n',[ivar b se]');

% Constraints
c = ones(ip,ip-irank);
c(1,1) = 0;

% Re-estimate using constraints
[b, se, covar, ifail] = g02dk( ...

% Display constrined estimates
fprintf('\nEstimates using constraints\n\n');
fprintf('Variable   Parameter estimate   Standard error\n\n');
ivar = double([1:ip]');
fprintf('%6d%20.4e%20.4e\n',[ivar b se]');

```
```g02dk example results

Initial estimates

Residual sum of squares =   2.2227e+01
Degrees of freedom      =    8

Variable   Parameter estimate   Standard error

1          3.0557e+01          3.8494e-01
2          5.4467e+00          8.3896e-01
3          6.7433e+00          8.3896e-01
4          1.1047e+01          8.3896e-01
5          7.3200e+00          8.3896e-01

Estimates using constraints

Variable   Parameter estimate   Standard error

1          3.8196e+01          4.8117e-01
2         -2.1925e+00          8.3342e-01
3         -8.9583e-01          8.3342e-01
4          3.4075e+00          8.3342e-01
5         -3.1917e-01          8.3342e-01
```