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

NAG Library Routine Document

G02GBF

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

SUBROUTINE G02GBF ( LINK, MEAN, OFFSET, WEIGHT, N, X, LDX, M, ISX, IP, Y, T, WT, DEV, IDF, B, IRANK, SE, COV, V, LDV, TOL, MAXIT, IPRINT, EPS, WK, IFAIL)
INTEGER  N, LDX, M, ISX(M), IP, IDF, IRANK, LDV, MAXIT, IPRINT, IFAIL
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)
CHARACTER(1)  LINK, MEAN, OFFSET, WEIGHT

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:
η=βjxj.  
(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
Rβ^=QTw1/2z.  
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
η^=gy.  
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:
ri=signyi-μ^idevyi,μ^i.  
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:
η=o+βjxj.  
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.
LINK='G'
A logistic link is used.
LINK='P'
A probit link is used.
LINK='C'
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.
MEAN='M'
A mean term, intercept, will be included in the model.
MEAN='Z'
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.
OFFSET='Y'
An offset is required and the offsets must be supplied in the seventh column of V.
OFFSET='N'
No offset is required.
Constraint: OFFSET='N' or 'Y'.
4:     WEIGHT – CHARACTER(1)Input
On entry: indicates if prior weights are to be used.
WEIGHT='U'
No prior weights are used.
WEIGHT='W'
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:     XLDXM – 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:     ISXM – INTEGER arrayInput
On entry: indicates which independent variables are to be included in the model.
ISXj>0
The variable contained in the jth column of X is included in the regression model.
Constraints:
  • 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:   YN – 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:   TN – 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:   BIP – 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:   SEIP – 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:   COVIP×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:   VLDVIP+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.
24:   IPRINT – INTEGERInput
On entry: indicates if the printing of information on the iterations is required.
IPRINT0
There is no printing.
IPRINT>0
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:   WKIP×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:
IFAIL=1
On entry,N<2,
orM<1,
orLDX<N,
orLDV<N,
orIP<1,
orLINK'G', 'P' or 'C'.
orMEAN'M' or 'Z'.
orWEIGHT'U' or 'W'.
orOFFSET'N' or 'Y'.
orMAXIT<0,
orTOL<0.0,
orEPS<0.0.
IFAIL=2
On entry,WEIGHT='W' and a value of WT<0.0.
IFAIL=3
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.
IFAIL=4
On entry,Ti<0 for some i=1,2,,n.
IFAIL=5
On entry,Yi<0.0,
orYi>Ti for some i=1,2,,n.
IFAIL=6
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.
IFAIL=7
The singular value decomposition has failed to converge. This is an unlikely error exit.
IFAIL=8
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.
IFAIL=9
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.
IFAIL=10
The degrees of freedom for error are 0. A saturated model has been fitted.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

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  Parallelism and Performance

G02GBF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02GBF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

None.

10  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).

10.1  Program Text

Program Text (g02gbfe.f90)

10.2  Program Data

Program Data (g02gbfe.d)

10.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. 2015