hide long namesshow long names
hide short namesshow short names
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)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

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, β^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 nc=p-k constraints will have to be imposed to obtain a unique solution.
Let C be a p by nc matrix of constraints, such that
CTβ=0,  
then the new parameter estimates β^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 CTP0-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:     vldvip+7 – double array
ldv, the first dimension of the array, must satisfy the constraint ldvip..
2:     cldciconst – double array
ldc, the first dimension of the array, must satisfy the constraint ldcip.
Contains the iconst constraints stored by column, i.e., the ith constraint is stored in the ith column of c.
3:     bip – double array
The parameter estimates computed by using the singular value decomposition, β^svd.
4:     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: s>0.0.

Optional Input Parameters

1:     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: ip1.
2:     iconst int64int32nag_int scalar
Default: the second dimension of the array c.
The number of constraints to be imposed on the arguments, nc.
Constraint: 0<iconst<ip.

Output Parameters

1:     bip – double array
The parameter estimates of the arguments with the constraints imposed, β^c.
2:     seip – double array
The standard error of the parameter estimates in b.
3:     covarip×ip+1/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 bi and the parameter estimate given in bj, ji, is stored in covarj×j-1/2+i.
4:     ifail int64int32nag_int scalar
ifail=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
On entry,ip<1.
oriconstip,
oriconst0,
orldv<ip,
orldc<ip,
ors0.0.
   ifail=2
c does not give a model of full rank.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   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.

Further Comments

nag_correg_glm_constrain (g02gk) is intended for use in situations in which dummy (01) 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);

link   = 'L';
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