PDF version (NAG web site
, 64-bit version, 64-bit version)
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,
, and their variance-covariance matrix. Details of the SVD are made available in the form of the matrix
:
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
arguments and the rank of the model is
then
constraints will have to be imposed to obtain a unique solution.
Let
be a
by
matrix of constraints, such that
then the new parameter estimates
are given by:
and the variance-covariance matrix is given by
provided
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:
– double array
-
ldv, the first dimension of the array, must satisfy the constraint
.
.
- 2:
– double array
-
ldc, the first dimension of the array, must satisfy the constraint
.
Contains the
iconst constraints stored by column, i.e., the
th constraint is stored in the
th column of
c.
- 3:
– double array
-
The parameter estimates computed by using the singular value decomposition, .
- 4:
– 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.
Constraint:
.
Optional Input Parameters
- 1:
– 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.)
, the number of terms in the linear model.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the second dimension of the array
c.
The number of constraints to be imposed on the arguments, .
Constraint:
.
Output Parameters
- 1:
– double array
-
The parameter estimates of the arguments with the constraints imposed, .
- 2:
– double array
-
The standard error of the parameter estimates in
b.
- 3:
– 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
and the parameter estimate given in
,
, is stored in
.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | . |
or | , |
or | , |
or | , |
or | , |
or | . |
-
-
c does not give a model of full rank.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
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 () 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
by
contingency table by
nag_correg_glm_poisson (g02gc). The model consists of terms for rows and columns. The table is
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.
Open in the MATLAB editor:
g02gk_example
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;
[dev, idf, b, irank, se, covar, v, ifail] = ...
g02gc( ...
link, mean_p, x, isx, ip, y, 'eps', eps, 'tol', tol);
fprintf('Deviance = %12.4e\n', dev);
fprintf('Degrees of freedom = %2d\n', idf);
c = [0 0;
1 0;
1 0;
1 0;
0 1;
0 1;
0 1;
0 1;
0 1];
s = 1;
[b, se, covar, ifail] = g02gk( ...
v, c, b, s, 'ip', ip);
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)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015