# NAG CL Interfaceg02gkc (glm_​constrain)

Settings help

CL Name Style:

## 1Purpose

g02gkc calculates the estimates of the arguments of a generalized linear model for given constraints from the singular value decomposition results.

## 2Specification

 #include
 void g02gkc (Integer ip, Integer nclin, const double v[], Integer tdv, const double c[], Integer tdc, double b[], double scale, double se[], double cov[], NagError *fail)
The function may be called by the names: g02gkc, nag_correg_glm_constrain or nag_glm_tran_model.

## 3Description

g02gkc 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 g02gac, g02gbc, g02gcc or g02gdc.
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 }}_{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 g02gac, g02gbc, g02gcc and g02gdc.
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×{n}_{c}$ matrix of constraints, such that
 $CT β = 0 ,$
then the new parameter estimates ${\stackrel{^}{\beta }}_{c}$ are given by:
 $β ^ c = A β ^ svd = ( I-P 0 (CT P 0 ) -1 ) β ^ svd ,$
where $I$ is the identity matrix, and the variance-covariance matrix is given by:
 $A P 1 D -2 P1T AT$
provided ${\left({C}^{\mathrm{T}}{P}_{0}\right)}^{-1}$ exists.

## 4References

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

## 5Arguments

1: $\mathbf{ip}$Integer Input
On entry: the number of terms in the linear model, $p$.
Constraint: ${\mathbf{ip}}\ge 1$.
2: $\mathbf{nclin}$Integer Input
On entry: the number of constraints to be imposed on the arguments, ${n}_{c}$.
Constraint: $0<{\mathbf{nclin}}<{\mathbf{ip}}$.
3: $\mathbf{v}\left[{\mathbf{ip}}×{\mathbf{tdv}}\right]$const double Input
Note: the $\left(i,j\right)$th element of the matrix $V$ is stored in ${\mathbf{v}}\left[\left(i-1\right)×{\mathbf{tdv}}+j-1\right]$.
On entry: v as returned by g02gac, g02gbc, g02gcc or g02gdc.
4: $\mathbf{tdv}$Integer Input
On entry: the stride separating matrix column elements in the array v.
Constraint: ${\mathbf{tdv}}\ge {\mathbf{ip}}+6$.
tdv should be as supplied to g02gac, g02gbc, g02gcc or g02gdc.
5: $\mathbf{c}\left[{\mathbf{ip}}×{\mathbf{tdc}}\right]$const double Input
Note: the $\left(i,j\right)$th element of the matrix $C$ is stored in ${\mathbf{c}}\left[\left(i-1\right)×{\mathbf{tdc}}+j-1\right]$.
On entry: the nclin constraints stored by column, i.e., the $i$th constraint is stored in the $i$th column of c.
6: $\mathbf{tdc}$Integer Input
On entry: the stride separating matrix column elements in the array c.
Constraint: ${\mathbf{tdc}}\ge {\mathbf{nclin}}$.
7: $\mathbf{b}\left[{\mathbf{ip}}\right]$double Input/Output
On entry: the parameter estimates computed by using the singular value decomposition, ${\stackrel{^}{\beta }}_{svd}$.
On exit: the parameter estimates of the arguments with the constraints imposed, ${\stackrel{^}{\beta }}_{c}$.
8: $\mathbf{scale}$double Input
On entry: the estimate of the scale argument.
For results from g02gac and g02gdc then scale is the scale argument, for the model ${\sigma }^{2}$ and ${\stackrel{^}{\nu }}^{-1}$ respectively.
For results from g02gbc and g02gcc then scale should be set to 1.0.
Constraint: ${\mathbf{scale}}>0.0$.
9: $\mathbf{se}\left[{\mathbf{ip}}\right]$double Output
On exit: the standard error of the parameter estimates in b.
10: $\mathbf{cov}\left[\left({\mathbf{ip}}\right)×\left({\mathbf{ip}}+1\right)/2\right]$double Output
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[\mathit{i}\right]$ and the parameter estimate given in ${\mathbf{b}}\left[\mathit{j}\right]$, $\mathit{j}\ge \mathit{i}$, is stored in ${\mathbf{cov}}\left[\mathit{j}\left(\mathit{j}+1\right)/2+\mathit{i}\right]$, for $\mathit{i}=0,1,\dots ,{\mathbf{ip}}-1$ and $\mathit{j}=\mathit{i},\dots ,{\mathbf{ip}}-1$.
11: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_2_INT_ARG_GE
On entry, ${\mathbf{nclin}}=⟨\mathit{\text{value}}⟩$ while ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$. These arguments must satisfy ${\mathbf{nclin}}<{\mathbf{ip}}$.
NE_2_INT_ARG_LT
On entry, ${\mathbf{tdc}}=⟨\mathit{\text{value}}⟩$ while ${\mathbf{nclin}}=⟨\mathit{\text{value}}⟩$. These arguments must satisfy ${\mathbf{tdc}}\ge {\mathbf{nclin}}$.
On entry, ${\mathbf{tdv}}=⟨\mathit{\text{value}}⟩$ while ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$. These arguments must satisfy ${\mathbf{tdv}}\ge {\mathbf{ip}}+6$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LE
On entry, ${\mathbf{nclin}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nclin}}>0$.
NE_INT_ARG_LT
On entry, ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ip}}\ge 1$.
NE_MAT_NOT_FULL_RANK
Matrix c does not give a model of full rank.
NE_REAL_ARG_LE
On entry, scale must not be less than or equal to 0.0: ${\mathbf{scale}}=⟨\mathit{\text{value}}⟩$.

## 7Accuracy

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.

## 8Parallelism and Performance

g02gkc is not threaded in any implementation.

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

## 10Example

A loglinear model is fitted to a 3 by 5 contingency table by g02gcc. 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 g02gkc and printed.

### 10.1Program Text

Program Text (g02gkce.c)

### 10.2Program Data

Program Data (g02gkce.d)

### 10.3Program Results

Program Results (g02gkce.r)