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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_correg_glm_constrain (g02gk)

## Purpose

nag_correg_glm_constrain (g02gk) calculates the estimates of the arguments of a generalized linear model for given constraints from the singular value decomposition results.

## Syntax

[b, se, covar, ifail] = g02gk(v, c, b, s, 'ip', ip, 'iconst', iconst)
[b, se, covar, ifail] = nag_correg_glm_constrain(v, c, b, s, 'ip', ip, 'iconst', iconst)

## Description

nag_correg_glm_constrain (g02gk) computes the estimates given a set of linear constraints for a generalized linear model which is not of full rank. It is intended for use after a call to nag_correg_glm_normal (g02ga), nag_correg_glm_binomial (g02gb), nag_correg_glm_poisson (g02gc) or nag_correg_glm_gamma (g02gd).
In the case of a model not of full rank the functions use a singular value decomposition 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_glm_normal (g02ga), nag_correg_glm_binomial (g02gb), nag_correg_glm_poisson (g02gc) and nag_correg_glm_gamma (g02gd). 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}_{\mathrm{c}}=p-k$ constraints will have to be imposed to obtain a unique solution.
Let $C$ be a $p$ by ${n}_{\mathrm{c}}$ matrix of constraints, such that
 $CTβ=0,$
then the new parameter estimates ${\stackrel{^}{\beta }}_{\mathrm{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-2 P1T AT$
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
McCullagh P and Nelder J A (1983) Generalized Linear Models Chapman and Hall
Searle S R (1971) Linear Models Wiley

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{v}\left(\mathit{ldv},{\mathbf{ip}}+7\right)$ – double array
ldv, the first dimension of the array, must satisfy the constraint $\mathit{ldv}\ge {\mathbf{ip}}$..
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}}$.
Contains 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{s}$ – double scalar
The estimate of the scale argument.
For results from nag_correg_glm_normal (g02ga) and nag_correg_glm_gamma (g02gd) then s is the scale argument for the model.
For results from nag_correg_glm_binomial (g02gb) and nag_correg_glm_poisson (g02gc) then s should be set to $1.0$.
Constraint: ${\mathbf{s}}>0.0$.

### Optional Input Parameters

1:     $\mathrm{ip}$int64int32nag_int scalar
Default: the dimension of the array b and the first dimension of the arrays c, v. (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}}\ge {\mathbf{ip}}$, or ${\mathbf{iconst}}\le 0$, or $\mathit{ldv}<{\mathbf{ip}}$, or $\mathit{ldc}<{\mathbf{ip}}$, or ${\mathbf{s}}\le 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.
${\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_glm_constrain (g02gk) 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

A loglinear model is fitted to a $3$ by $5$ contingency table by nag_correg_glm_poisson (g02gc). The model consists of terms for rows and columns. The table is
 $141 67 114 79 39 131 66 143 72 35 36 14 38 28 16 .$
The constraints that the sum of row effects and the sum of column effects are zero are then read in and the parameter estimates with these constraints imposed are computed by nag_correg_glm_constrain (g02gk) and printed.
```function g02gk_example

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

x = [
1  0  0  1  0  0  0  0;
1  0  0  0  1  0  0  0;
1  0  0  0  0  1  0  0;
1  0  0  0  0  0  1  0;
1  0  0  0  0  0  0  1;
0  1  0  1  0  0  0  0;
0  1  0  0  1  0  0  0;
0  1  0  0  0  1  0  0;
0  1  0  0  0  0  1  0;
0  1  0  0  0  0  0  1;
0  0  1  1  0  0  0  0;
0  0  1  0  1  0  0  0;
0  0  1  0  0  1  0  0;
0  0  1  0  0  0  1  0;
0  0  1  0  0  0  0  1];

y = [141  67 114  79  39 131  66 143  72  35  36  14  38  28  16];

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

mean_p = 'M';
eps = 1e-6;
tol = 5e-5;

% Fit generalized linear model with Poisson errors
[dev, idf, b, irank, se, covar, v, ifail] = ...
g02gc( ...
link, mean_p, x, isx, ip, y, 'eps', eps, 'tol', tol);

% Display initial results
fprintf('Deviance           = %12.4e\n', dev);
fprintf('Degrees of freedom = %2d\n', idf);

% Constraints
c = [0  0;
1  0;
1  0;
1  0;
0  1;
0  1;
0  1;
0  1;
0  1];

% Re-estimate the model given the constraints
s = 1;
[b, se, covar, ifail] = g02gk( ...
v, c, b, s, 'ip', ip);

% Display the constrained parameter estimates
fprintf('\nVariable   Parameter estimate   Standard error\n\n');
ivar = double([1:ip]');
fprintf('%6d%16.4f%20.4f\n',[ivar b se]');

```
```g02gk example results

Deviance           =   9.0379e+00
Degrees of freedom =  8

Variable   Parameter estimate   Standard error

1          3.9831              0.0396
2          0.3961              0.0458
3          0.4118              0.0457
4         -0.8079              0.0622
5          0.5112              0.0562
6         -0.2285              0.0727
7          0.4680              0.0569
8         -0.0316              0.0675
9         -0.7191              0.0887
```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015