G02GBF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document


Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G02GBF fits a generalized linear model with binomial errors.

2  Specification

REAL (KIND=nag_wp)  X(LDX,M), Y(N), T(N), WT(*), DEV, B(IP), SE(IP), COV(IP*(IP+1)/2), V(LDV,IP+7), TOL, EPS, WK((IP*IP+3*IP+22)/2)

3  Description

A generalized linear model with binomial errors consists of the following elements:
(a) a set of n observations, yi, from a binomial distribution:
t y πy1-πt-y.
(b) X, a set of p independent variables for each observation, x1,x2,,xp.
(c) a linear model:
(d) a link between the linear predictor, η, and the mean of the distribution, μ=πt, the link function, η=gμ. The possible link functions are:
(i) logistic link: η=logμ t-μ ,
(ii) probit link: η=Φ-1 μt ,
(iii) complementary log-log link: log-log1-μt .
(e) a measure of fit, the deviance:
i=1ndevyi,μ^i=i=1n2 yilogyiμ^i+ti-yilog ti-yi ti-μ^i .
The linear parameters are estimated by iterative weighted least squares. An adjusted dependent variable, z, is formed:
z=η+y-μdη dμ
and a working weight, w,
w= τdη dμ 2,   where ​τ=tμt-μ .
At each iteration an approximation to the estimate of β, β^, is found by the weighted least squares regression of z on X with weights w.
G02GBF finds a QR decomposition of w1/2X, i.e., w1/2X=QR where R is a p by p triangular matrix and Q is an n by p column orthogonal matrix.
If R is of full rank, then β^ is the solution to
If R is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of R.
R=Q* D 0 0 0 PT,
where D is a k by k diagonal matrix with nonzero diagonal elements, k being the rank of R and w1/2X.
This gives the solution
β^=P1D-1 Q* 0 0 I QTw1/2z,
P1 being the first k columns of P, i.e., P=P1P0.
The iterations are continued until there is only a small change in the deviance.
The initial values for the algorithm are obtained by taking
The fit of the model can be assessed by examining and testing the deviance, in particular by comparing the difference in deviance between nested models, i.e., when one model is a sub-model of the other. The difference in deviance between two nested models has, asymptotically, a χ2-distribution with degrees of freedom given by the difference in the degrees of freedom associated with the two deviances.
The parameters estimates, β^, are asymptotically Normally distributed with variance-covariance matrix
The residuals and influence statistics can also be examined.
The estimated linear predictor η^=Xβ^, can be written as Hw1/2z for an n by n matrix H. The ith diagonal elements of H, hi, give a measure of the influence of the ith values of the independent variables on the fitted regression model. These are sometimes known as leverages.
The fitted values are given by μ^=g-1η^.
G02GBF also computes the deviance residuals, r:
An option allows the use of prior weights in the model.
In many linear regression models the first term is taken as a mean term or an intercept, i.e., xi,1=1, for i=1,2,,n. This is provided as an option.
Often only some of the possible independent variables are included in a model; the facility to select variables to be included in the model is provided.
If part of the linear predictor can be represented by variables with a known coefficient then this can be included in the model by using an offset, o:
If the model is not of full rank the solution given will be only one of the possible solutions. Other estimates may be obtained by applying constraints to the parameters. These solutions can be obtained by using G02GKF after using G02GBF. Only certain linear combinations of the parameters will have unique estimates, these are known as estimable functions and can be estimated and tested using G02GNF.
Details of the SVD are made available in the form of the matrix P*:
P*= D-1 P1T P0T .

4  References

Cook R D and Weisberg S (1982) Residuals and Influence in Regression Chapman and Hall
Cox D R (1983) Analysis of Binary Data Chapman and Hall
McCullagh P and Nelder J A (1983) Generalized Linear Models Chapman and Hall

5  Parameters

On entry: indicates which link function is to be used.
A logistic link is used.
A probit link is used.
A complementary log-log link is used.
Constraint: LINK='G', 'P' or 'C'.
2:     MEAN – CHARACTER(1)Input
On entry: indicates if a mean term is to be included.
A mean term, intercept, will be included in the model.
The model will pass through the origin, zero-point.
Constraint: MEAN='M' or 'Z'.
3:     OFFSET – CHARACTER(1)Input
On entry: indicates if an offset is required.
An offset is required and the offsets must be supplied in the seventh column of V.
No offset is required.
Constraint: OFFSET='N' or 'Y'.
4:     WEIGHT – CHARACTER(1)Input
On entry: indicates if prior weights are to be used.
No prior weights are used.
Prior weights are used and weights must be supplied in WT.
Constraint: WEIGHT='U' or 'W'.
5:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N2.
6:     X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: Xij must contain the ith observation for the jth independent variable, for i=1,2,,N and j=1,2,,M.
7:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02GBF is called.
Constraint: LDXN.
8:     M – INTEGERInput
On entry: m, the total number of independent variables.
Constraint: M1.
9:     ISX(M) – INTEGER arrayInput
On entry: indicates which independent variables are to be included in the model.
The variable contained in the jth column of X is included in the regression model.
  • ISXj0, for j=1,2,,M;
  • if MEAN='M', exactly IP-1 values of ISX must be >0;
  • if MEAN='Z', exactly IP values of ISX must be >0.
10:   IP – INTEGERInput
On entry: the number of independent variables in the model, including the mean or intercept if present.
Constraint: IP>0.
11:   Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the observations on the dependent variable, yi, for i=1,2,,n.
Constraint: 0.0YiTi, for i=1,2,,n.
12:   T(N) – REAL (KIND=nag_wp) arrayInput
On entry: t, the binomial denominator.
Constraint: Ti0.0, for i=1,2,,n.
13:   WT(*) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array WT must be at least N if WEIGHT='W', and at least 1 otherwise.
On entry: if WEIGHT='W', WT must contain the weights to be used in the weighted regression. If WTi=0.0, the ith observation is not included in the model, in which case the effective number of observations is the number of observations with nonzero weights.
If WEIGHT='U', WT is not referenced and the effective number of observations is n.
Constraint: if WEIGHT='W', WTi0.0, for i=1,2,,n.
14:   DEV – REAL (KIND=nag_wp)Output
On exit: the deviance for the fitted model.
15:   IDF – INTEGEROutput
On exit: the degrees of freedom associated with the deviance for the fitted model.
16:   B(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the estimates of the parameters of the generalized linear model, β^.
If MEAN='M', the first element of B will contain the estimate of the mean parameter and Bi+1 will contain the coefficient of the variable contained in column j of X, where ISXj is the ith positive value in the array ISX.
If MEAN='Z', Bi will contain the coefficient of the variable contained in column j of X, where ISXj is the ith positive value in the array ISX.
17:   IRANK – INTEGEROutput
On exit: the rank of the independent variables.
If the model is of full rank, IRANK=IP.
If the model is not of full rank, IRANK is an estimate of the rank of the independent variables. IRANK is calculated as the number of singular values greater that EPS×(largest singular value).
It is possible for the SVD to be carried out but for IRANK to be returned as IP.
18:   SE(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the standard errors of the linear parameters.
SEi contains the standard error of the parameter estimate in Bi, for i=1,2,,IP.
19:   COV(IP×IP+1/2) – REAL (KIND=nag_wp) arrayOutput
On exit: the upper triangular part of the variance-covariance matrix of the IP parameter estimates given in B. They are stored in packed form by column, i.e., the covariance between the parameter estimate given in Bi and the parameter estimate given in Bj, ji, is stored in COVj×j-1/2+i.
20:   V(LDV,IP+7) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if OFFSET='N', V need not be set.
If OFFSET='Y', Vi7, for i=1,2,,n must contain the offset values oi. All other values need not be set.
On exit: auxiliary information on the fitted model.
Vi1 contains the linear predictor value, ηi, for i=1,2,,n.
Vi2 contains the fitted value, μ^i, for i=1,2,,n.
Vi3 contains the variance standardization, 1τi, for i=1,2,,n.
Vi4 contains the square root of the working weight, wi12, for i=1,2,,n.
Vi5 contains the deviance residual, ri, for i=1,2,,n.
Vi6 contains the leverage, hi, for i=1,2,,n.
Vi7 contains the offset, oi, for i=1,2,,n. If OFFSET='N', all values will be zero.
Vij for j=8,,IP+7, contains the results of the QR decomposition or the singular value decomposition.
If the model is not of full rank, i.e., IRANK<IP, the first IP rows of columns 8 to IP+7 contain the P* matrix.
21:   LDV – INTEGERInput
On entry: the first dimension of the array V as declared in the (sub)program from which G02GBF is called.
Constraint: LDVN.
22:   TOL – REAL (KIND=nag_wp)Input
On entry: indicates the accuracy required for the fit of the model.
The iterative weighted least squares procedure is deemed to have converged if the absolute change in deviance between iterations is less than TOL×1.0+Current Deviance. This is approximately an absolute precision if the deviance is small and a relative precision if the deviance is large.
If 0.0TOL<machine precision, the routine will use 10×machine precision instead.
Constraint: TOL0.0.
23:   MAXIT – INTEGERInput
On entry: the maximum number of iterations for the iterative weighted least squares.
If MAXIT=0, a default value of 10 is used.
Constraint: MAXIT0.
On entry: indicates if the printing of information on the iterations is required.
There is no printing.
The following is printed every IPRINT iterations:
  • the deviance,
  • the current estimates,
  • and if the weighted least squares equations are singular, then this is indicated.
When printing occurs the output is directed to the current advisory message unit (see X04ABF).
25:   EPS – REAL (KIND=nag_wp)Input
On entry: the value of EPS is used to decide if the independent variables are of full rank and, if not, what is the rank of the independent variables. The smaller the value of EPS the stricter the criterion for selecting the singular value decomposition.
If 0.0EPS<machine precision, the routine will use machine precision instead.
Constraint: EPS0.0.
26:   WK(IP×IP+3×IP+22/2) – REAL (KIND=nag_wp) arrayWorkspace
27:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G02GBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
On entry,N<2,
orLINK'G', 'P' or 'C'.
orMEAN'M' or 'Z'.
orWEIGHT'U' or 'W'.
orOFFSET'N' or 'Y'.
On entry,WEIGHT='W' and a value of WT<0.0.
On entry,a value of ISX<0,
orthe value of IP is incompatible with the values of MEAN and ISX,
orIP is greater than the effective number of observations.
On entry,Ti<0 for some i=1,2,,n.
On entry,Yi<0.0,
orYi>Ti for some i=1,2,,n.
A fitted value is at the boundary, i.e., 0.0 or 1.0. This may occur if there are y values of 0.0 or t and the model is too complex for the data. The model should be reformulated with, perhaps, some observations dropped.
The singular value decomposition has failed to converge. This is an unlikely error exit.
The iterative weighted least squares has failed to converge in MAXIT (or default 10) iterations. The value of MAXIT could be increased but it may be advantageous to examine the convergence using the IPRINT option. This may indicate that the convergence is slow because the solution is at a boundary in which case it may be better to reformulate the model.
The rank of the model has changed during the weighted least squares iterations. The estimate for β returned may be reasonable, but you should check how the deviance has changed during iterations.
The degrees of freedom for error are 0. A saturated model has been fitted.

7  Accuracy

The accuracy will depend on the value of TOL as described in Section 5. As the deviance is a function of logμ the accuracy of the β^ will be only a function of TOL, so TOL should be set smaller than the required accuracy for β^.

8  Further Comments


9  Example

A linear trend x=-1,0,1 is fitted to data relating the incidence of carriers of Streptococcus pyogenes to size of tonsils. The data is described in Cox (1983).

9.1  Program Text

Program Text (g02gbfe.f90)

9.2  Program Data

Program Data (g02gbfe.d)

9.3  Program Results

Program Results (g02gbfe.r)

G02GBF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012