The function may be called by the names: g02gdc, nag_correg_glm_gamma or nag_glm_gamma.
A generalized linear model with gamma errors consists of the following elements:
(a)a set of observations, , from a gamma distribution with probability density function:
being constant for the sample.
(b), a set of independent variables for each observation, .
(c)a linear model:
(d)a link between the linear predictor, , and the mean of the distribution, , . The possible link functions are:
(i)power link: , for a constant ,
(ii)identity link: ,
(iii)log link: ,
(iv)square root link: ,
(e)reciprocal link: .
(f)a measure of fit, an adjusted deviance. This is a function related to the deviance, but defined for :
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 .
g02gdc 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 scale argument, is estimated by a moment estimator:
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 or adjusted deviance between two nested models with known 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 .
g02gdc also computes the Anscombe residuals, :
An option allows the use of prior weights, . This gives a model with:
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 may be obtained by applying constraints to the arguments. These solutions can be obtained by using g02gkc after using g02gdc.
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
McCullagh P and Nelder J A (1983) Generalized Linear Models Chapman and Hall
1: – Nag_LinkInput
On entry: indicates which link function is to be used.
An exponent link is used.
An identity link is used.
A log link is used.
A square root link is used.
A reciprocal 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 exit: the adjusted deviance for the fitted model.
15: – double *Output
On exit: the degrees of freedom associated with the deviance for the fitted model.
16: – doubleOutput
On exit: 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.
17: – 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.
18: – doubleOutput
On exit: the standard errors of the linear arguments.
contains the standard error of the parameter estimate in , for .
19: – 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 .
20: – 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 Anscombe 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.
21: – IntegerInput
On entry: the stride separating matrix column elements in the array v.
22: – 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.
23: – IntegerInput
On entry: the maximum number of iterations for the iterative weighted least squares.
If , then a default value of 10 is used.
24: – 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.
25: – 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.
26: – 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.
27: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
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., . This may occur if there are small values of and the model is not suitable 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
g02gdc is not threaded in any implementation.
A set of 10 observations from two groups is input and a model for the two groups is fitted.