At each iteration an approximation to the estimate of β, β^ is found by the weighted least squares regression of z on X with weights w.

nag_glm_binomial (g02gbc) finds a QR decomposition of w12X, i.e.,

w12X=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β^=QTw12z

If R is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of R.

R=Q*D000PT,

where D is a k by k diagonal matrix with nonzero diagonal elements, k being the rank of R and w12X.

This gives the solution

β^=P1D-1Q*00IQTw12z

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 estimated linear predictor η^=Xβ^, can be written as Hw12z 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 known as leverages.

The fitted values are given by μ^=g-1η^.

nag_glm_binomial (g02gbc) also computes the deviance residuals, r:

ri=signyi-μ^idevyi,μ^i.

An option allows prior weights to be used with 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 a variable 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 be may be obtained by applying constraints to the arguments. These solutions can be obtained by using nag_glm_tran_model (g02gkc) after using nag_glm_binomial (g02gbc).

Only certain linear combinations of the arguments will have unique estimates, these are known as estimable functions, these can be estimated and tested using nag_glm_est_func (g02gnc).

On exit: b[i-1], i=1,…,ip contains the estimates of the arguments of the generalized linear model, β^.

If mean=Nag_MeanInclude, then b[0] will contain the estimate of the mean argument and b[i] will contain the coefficient of the variable contained in column j of x, where sx[j-1] is the ith positive value in the array sx.

If mean=Nag_MeanZero, then b[i-1] will contain the coefficient of the variable contained in column j of x, where sx[j-1] is the ith positive value in the array sx.

16:
rank – Integer *Output

On exit: the rank of the independent variables.

If the model is of full rank, then rank=ip.

If the model is not of full rank, then rank is an estimate of the rank of the independent variables. rank is calculated as the number of singular values greater than eps× (largest singular value). It is possible for the SVD to be carried out but rank to be returned as ip.

se[i-1] contains the standard error of the parameter estimate in b[i-1], for i=1,2,…,ip.

18:
cov[ip×ip+1/2] – doubleOutput

On exit: the ip×ip+1/2 elements of cov contain 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 b[i] and the parameter estimate given in b[j], j≥i, is stored in cov[jj+1/2+i], for i=0,1,…,ip-1 and j=i,…,ip-1.

v[i-1×tdv+j-1], for j=7,8,…,ip+6, contains the results of the QR decomposition or the singular value decomposition.

If the model is not of full rank, i.e., rank<ip, then the first ip rows of columns 7 to ip+6 contain the P* matrix.

20:
tdv – IntegerInput

On entry: the stride separating matrix column elements in the array v.

Constraint:
tdv≥ip+6.

21:
tol – doubleInput

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 interactions 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.0≤tol<machine precision, then the function will use 10×machine precision.

Constraint:
tol≥0.0.

22:
max_iter – IntegerInput

On entry: the maximum number of iterations for the iterative weighted least squares.

If max_iter=0, then a default value of 10 is used.

Constraint:
max_iter≥0.

23:
print_iter – IntegerInput

On entry: indicates if the printing of information on the iterations is required and the rate at which printing is produced.

if the weighted least squares equations are singular then this is indicated.

24:
outfile – const char *Input

On entry: a null terminated character string giving the name of the file to which results should be printed. If outfile is NULL or an empty string then the stdout stream is used. Note that the file will be opened in the append mode.

25:
eps – doubleInput

On entry: the value of eps is used to decide if the independent variables are of full rank and, if not, what the rank of the independent variables is. The smaller the value of eps the stricter the criterion for selecting the singular value decomposition.

If 0.0≤eps<machine precision, then the function will use machine precision instead.

The iterative weighted least squares has failed to converge in max_iter=value iterations. The value of max_iter could be increased but it may be advantageous to examine the convergence using the print_iter 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.

NE_NOT_APPEND_FILE

Cannot open file string for appending.

NE_NOT_CLOSE_FILE

Cannot close file string.

NE_RANK_CHANGED

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.

NE_REAL_ARG_LT

On entry, binom_t[value] must not be less than 0.0: binom_t[value]=value.

A fitted value is at a boundary, i.e., 0.0 or 1.0. This may occur if there are y values of 0.0 or binom_t and the model is too complex for the data. The model should be reformulated with, perhaps, some observations dropped.

NE_ZERO_DOF_ERROR

The degrees of freedom for error are 0. A saturated model has been fitted.

7 Accuracy

The accuracy is determined by tol as described in Section 5. As the adjusted deviance is a function of log⁡μ the accuracy of the β^'s will be a function of tol. tol should therefore be set to a smaller value than the accuracy required for β^.

8 Parallelism and Performance

Not applicable.

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