g02 Chapter Contents
g02 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_glm_tran_model (g02gkc)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_glm_tran_model (Integer ip, Integer nclin, const double v[], Integer tdv, const double c[], Integer tdc, double b[], double scale, double se[], double cov[], NagError *fail)

## 3  Description

nag_glm_tran_model (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 nag_glm_normal (g02gac), nag_glm_binomial (g02gbc), nag_glm_poisson (g02gcc) or nag_glm_gamma (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 nag_glm_normal (g02gac), nag_glm_binomial (g02gbc), nag_glm_poisson (g02gcc) and nag_glm_gamma (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$ 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-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.

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

## 5  Arguments

1:    $\mathbf{ip}$IntegerInput
On entry: the number of terms in the linear model, $p$.
Constraint: ${\mathbf{ip}}\ge 1$.
2:    $\mathbf{nclin}$IntegerInput
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 doubleInput
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]$.
4:    $\mathbf{tdv}$IntegerInput
On entry: the stride separating matrix column elements in the array v.
Constraint: ${\mathbf{tdv}}\ge {\mathbf{ip}}+6$.
5:    $\mathbf{c}\left[{\mathbf{ip}}×{\mathbf{tdc}}\right]$const doubleInput
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}$IntegerInput
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]$doubleInput/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}$doubleInput
On entry: the estimate of the scale argument.
For results from nag_glm_normal (g02gac) and nag_glm_gamma (g02gdc) then scale is the scale argument, for the model ${\sigma }^{2}$ and ${\stackrel{^}{\nu }}^{-1}$ respectively.
For results from nag_glm_binomial (g02gbc) and nag_glm_poisson (g02gcc) then scale should be set to 1.0.
Constraint: ${\mathbf{scale}}>0.0$.
9:    $\mathbf{se}\left[{\mathbf{ip}}\right]$doubleOutput
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]$doubleOutput
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 2.7 in How to Use the NAG Library and its Documentation).

## 6  Error 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}}〉$.

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

nag_glm_tran_model (g02gkc) is not threaded in any implementation.

nag_glm_tran_model (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.

## 10  Example

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

### 10.1  Program Text

Program Text (g02gkce.c)

### 10.2  Program Data

Program Data (g02gkce.d)

### 10.3  Program Results

Program Results (g02gkce.r)