The function may be called by the names: g02gbc, nag_correg_glm_binomial or nag_glm_binomial.
A generalized linear model with binomial errors consists of the following elements:
(a)a set of observations, , from a binomial distribution:
(b), a set of independent variables for each observation, .
(c)a linear model:
(d)a link function , linking the linear predictor, and the mean of the distribution, .
The possible link functions are:
(i)logistic link: ,
(ii)probit link: ,
(iii)complementary log-log link:
(e)a measure of fit, the deviance:
The linear arguments are estimated by iterative weighted least squares. An adjusted dependent variable, , is formed:
and a working weight, ,
At each iteration an approximation to the estimate of , is found by the weighted least squares regression of on with weights .
g02gbc finds a decomposition of , i.e.,
where is a triangular matrix and is an column orthogonal matrix.
If is of full rank then is the solution to:
If is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of .
where is a diagonal matrix with nonzero diagonal elements, being the rank of and .
This gives the solution
being the first columns of , i.e., .
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 distribution with degrees of freedom given by the difference in the degrees of freedom associated with the two deviances.
The arguments estimates, , are asymptotically Normally distributed with variance-covariance matrix:
in the full rank case, otherwise
The residuals and influence statistics can also be examined.
The estimated linear predictor , can be written as for an matrix . The th diagonal elements of , , give a measure of the influence of the th values of the independent variables on the fitted regression model. These are known as leverages.
The fitted values are given by .
g02gbc also computes the deviance residuals, :
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., , for . 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, :
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 g02gkc after using 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 g02gnc.
Details of the SVD, are made available, in the form of the matrix :
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
1: – Nag_LinkInput
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.
, or .
2: – Nag_IncludeMeanInput
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.
3: – IntegerInput
On entry: the number of observations, .
4: – const doubleInput
On entry: must contain the th observation for the th independent variable, for and .
5: – IntegerInput
On entry: the stride separating matrix column elements in the array x.
6: – IntegerInput
On entry: the total number of independent variables.
7: – const IntegerInput
On entry: indicates which independent variables are to be included in the model. If , then the variable contained in the th column of x is included in the regression model.
On entry: the number of independent variables in the model, including the mean or intercept if present.
9: – const doubleInput
On entry: observations on the dependent variable, , for .
, for .
10: – const doubleInput
On entry: the binomial denominator, .
, for .
11: – const doubleInput
On entry: if weighted estimates are required, then wt must contain the weights to be used. Otherwise wt need not be defined and may be set to NULL.
If , then the th observation is not included in the model, in which case the effective number of observations is the number of observations with positive weights.
If wt is NULL, then the effective number of observations is .
or , for .
12: – const doubleInput
On entry: if an offset is required then offset must contain the values of the offset . Otherwise offset must be supplied as NULL.
13: – double *Output
On exit: the deviance for the fitted model.
14: – double *Output
On exit: the degrees of freedom associated with the deviance for the fitted model.
15: – doubleOutput
On exit: , contains the estimates of the arguments of the generalized linear model, .
If , then will contain the estimate of the mean argument and will contain the coefficient of the variable contained in column of x, where is the th positive value in the array sx.
If , then will contain the coefficient of the variable contained in column of x, where is the th positive value in the array sx.
16: – Integer *Output
On exit: the rank of the independent variables.
If the model is of full rank, then .
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 (largest singular value). It is possible for the SVD to be carried out but rank to be returned as ip.
17: – doubleOutput
On exit: the standard errors of the linear arguments.
contains the standard error of the parameter estimate in , for .
18: – doubleOutput
On exit: the 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 and the parameter estimate given in , , is stored in , for and .
19: – doubleOutput
On exit: auxiliary information on the fitted model.
, contains the linear predictor value, , for .
, contains the fitted value, , for .
, contains the variance standardization, , for .
, contains the working weight, , for .
, contains the deviance residual, , for .
, contains the leverage, , for .
, for , contains the results of the decomposition or the singular value decomposition.
If the model is not of full rank, i.e., , then the first ip rows of columns to contain the matrix.
20: – IntegerInput
On entry: the stride separating matrix column elements in the array v.
21: – 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 (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 machine precision, then the function will use machine precision.
22: – IntegerInput
On entry: the maximum number of iterations for the iterative weighted least squares.
If , then a default value of 10 is used.
23: – IntegerInput
On entry: indicates if the printing of information on the iterations is required and the rate at which printing is produced.
There is no printing.
The following items are printed every print_iter iterations:
(ii)the current estimates, and
(iii)if the weighted least squares equations are singular then this is indicated.
24: – 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: – 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 machine precision, then the function will use machine precision instead.
26: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
Parameter ip is greater than the effective number of observations.
Parameter ip is incompatible with arguments mean and sx.
The iterative weighted least squares has failed to converge in 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.
Cannot open file for appending.
Cannot close file .
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 singular value decomposition has failed to converge.
A fitted value is at a boundary, i.e., or . This may occur if there are y values of or binom_t and the model is too complex for the data. The model should be reformulated with, perhaps, some observations dropped.
The degrees of freedom for error are . A saturated model has been fitted.
The accuracy is determined by tol as described in Section 5. As the adjusted deviance is a function of 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 .
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g02gbc is not threaded in any implementation.
A linear trend is fitted to data relating the incidence of carriers of Streptococcus pyogenes to size of tonsils. The data is described in Cox (1983).