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 parameters of a general linear regression model for given constraints from the singular value decomposition results.

## Syntax

[b, se, cov, ifail] = g02dk(p, c, b, rss, idf, 'ip', ip, 'iconst', iconst)
[b, se, cov, 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, β̂svd${\stackrel{^}{\beta }}_{\text{svd}}$, and their variance-covariance matrix. Details of the SVD are made available in the form of the matrix P*${P}^{*}$:
P* =
 ( D − 1 P1T ) P0T
,
$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 parameters. If there are p$p$ parameters and the rank of the model is k$k$, then nc = pk${n}_{c}=p-k$ constraints will have to be imposed to obtain a unique solution.
Let C$C$ be a p$p$ by nc${n}_{c}$ matrix of constraints, such that
 CTβ = 0 $CTβ=0$
then the new parameter estimates β̂c${\stackrel{^}{\beta }}_{c}$ are given by
 β̂c = Aβ̂svd; = (I − P0(CTP0) − 1)β̂svd,
$β^c =Aβ^svd; =(I-P0(CTP0)-1)β^svd,$
where I$I$ is the identity matrix, and the variance-covariance matrix is given by
 AP1D − 2P1TAT, $AP1D-2P1TAT,$
provided (CTP0)1${\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:     p(ip × ip + 2 × ip${\mathbf{ip}}×{\mathbf{ip}}+2×{\mathbf{ip}}$) – double array
2:     c(ldc,iconst) – double array
ldc, the first dimension of the array, must satisfy the constraint ldcip$\mathit{ldc}\ge {\mathbf{ip}}$.
The iconst constraints stored by column, i.e., the i$i$th constraint is stored in the i$i$th column of c.
3:     b(ip) – double array
ip, the dimension of the array, must satisfy the constraint ip1${\mathbf{ip}}\ge 1$.
The parameter estimates computed by using the singular value decomposition, β̂svd${\stackrel{^}{\beta }}_{\text{svd}}$.
The residual sum of squares as returned by nag_correg_linregm_fit (g02da) or nag_correg_linregm_update (g02dd).
Constraint: rss > 0.0${\mathbf{rss}}>0.0$.
5:     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: idf > 0${\mathbf{idf}}>0$.

### Optional Input Parameters

1:     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$p$, the number of terms in the linear model.
Constraint: ip1${\mathbf{ip}}\ge 1$.
2:     iconst – int64int32nag_int scalar
Default: The second dimension of the array c.
The number of constraints to be imposed on the parameters, nc${n}_{\mathrm{c}}$.
Constraint: 0 < iconst < ip$0<{\mathbf{iconst}}<{\mathbf{ip}}$.

ldc wk

### Output Parameters

1:     b(ip) – double array
The parameter estimates of the parameters with the constraints imposed, β̂c${\stackrel{^}{\beta }}_{\mathrm{c}}$.
2:     se(ip) – double array
The standard error of the parameter estimates in b.
3:     cov(ip × (ip + 1) / 2${\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2$) – 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 b(i)${\mathbf{b}}\left(i\right)$ and the parameter estimate given in b(j)${\mathbf{b}}\left(j\right)$, ji$j\ge i$, is stored in cov((j × (j1) / 2 + i))${\mathbf{cov}}\left(\left(j×\left(j-1\right)/2+i\right)\right)$.
4:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, ip < 1${\mathbf{ip}}<1$, or iconst ≤ 0${\mathbf{iconst}}\le 0$, or ${\mathbf{iconst}}\ge {\mathbf{ip}}$, or ldc < ip$\mathit{ldc}<{\mathbf{ip}}$, or rss ≤ 0.0${\mathbf{rss}}\le 0.0$, or idf ≤ 0${\mathbf{idf}}\le 0$.
ifail = 2${\mathbf{ifail}}=2$
c does not give a model of full rank.

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

nag_correg_linregm_constrain (g02dk) is intended for use in situations in which dummy (01$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 function is not intended for situations in which the relationships between the independent variables are only approximate.

## Example

```function nag_correg_linregm_constrain_example
p = [1.135198279858991;
1.13078348304906;
1.234006904805161;
1.228003039942231;
1.263332232672042;
3.872983346207417;
1.732050807568878;
1.732050807568878;
1.732050807568877;
1.64780261914309e-16;
0.2309401076758503;
8.35089227579159e-18;
-1.238223776129407e-17;
7.900875770685859e-17;
-0.447213595499958;
0.0577350269189626;
0.2871305767251709;
0.2022129403845741;
-0.3559016137228031;
0.447213595499958;
0.05773502691896256;
0.03726461792122844;
0.271286303307133;
0.4183480487454616;
0.447213595499958;
0.05773502691896257;
0.1515575558927682;
-0.4677758485215264;
0.0906424999201606;
0.447213595499958;
0.05773502691896258;
-0.4759527505391677;
-0.005723395170180857;
-0.153088934942819;
0.4472135954999578];
c = [0;
1;
1;
1;
1];
b = [30.55666666666667;
5.446666666666673;
6.743333333333336;
11.04666666666667;
7.32];
idf = int64(8);
[bOut, se, covar, ifail] = nag_correg_linregm_constrain(p, c, b, rss, idf)
```
```

bOut =

38.1958
-2.1925
-0.8958
3.4075
-0.3192

se =

0.4812
0.8334
0.8334
0.8334
0.8334

covar =

0.2315
-0.0000
0.6946
0.0000
-0.2315
0.6946
0.0000
-0.2315
-0.2315
0.6946
0.0000
-0.2315
-0.2315
-0.2315
0.6946

ifail =

0

```
```function g02dk_example
p = [1.135198279858991;
1.13078348304906;
1.234006904805161;
1.228003039942231;
1.263332232672042;
3.872983346207417;
1.732050807568878;
1.732050807568878;
1.732050807568877;
1.64780261914309e-16;
0.2309401076758503;
8.35089227579159e-18;
-1.238223776129407e-17;
7.900875770685859e-17;
-0.447213595499958;
0.0577350269189626;
0.2871305767251709;
0.2022129403845741;
-0.3559016137228031;
0.447213595499958;
0.05773502691896256;
0.03726461792122844;
0.271286303307133;
0.4183480487454616;
0.447213595499958;
0.05773502691896257;
0.1515575558927682;
-0.4677758485215264;
0.0906424999201606;
0.447213595499958;
0.05773502691896258;
-0.4759527505391677;
-0.005723395170180857;
-0.153088934942819;
0.4472135954999578];
c = [0;
1;
1;
1;
1];
b = [30.55666666666667;
5.446666666666673;
6.743333333333336;
11.04666666666667;
7.32];
idf = int64(8);
[bOut, se, covar, ifail] = g02dk(p, c, b, rss, idf)
```
```

bOut =

38.1958
-2.1925
-0.8958
3.4075
-0.3192

se =

0.4812
0.8334
0.8334
0.8334
0.8334

covar =

0.2315
-0.0000
0.6946
0.0000
-0.2315
0.6946
0.0000
-0.2315
-0.2315
0.6946
0.0000
-0.2315
-0.2315
-0.2315
0.6946

ifail =

0

```