|
NAG[g02gdc] NAG[nag_glm_gamma] - Fits a generalized linear model with gamma errors
|
|
Calling Sequence
g02gdc(link, mean, x, sx, y, scale, ex_power, dev, df, b, rank, se, cov, v, tol, max_iter, print_iter, eps, 'n'=n, 'tdx'=tdx, 'm'=m, 'ip'=ip, 'wt'=wt, 'offset'=offset, 'tdv'=tdv, 'outfile'=outfile, 'fail'=fail)
nag_glm_gamma(. . .)
Parameters
|
link - String;
|
|
|
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.
|
|
Constraint: "Nag_Expo", "Nag_Iden", "Nag_Log", "Nag_Sqrt" or "Nag_Reci". .
|
|
|
mean - String;
|
|
|
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: "Nag_MeanInclude" or "Nag_MeanZero". .
|
|
|
x - Matrix(1..n, 1..tdx, datatype=float[8], order=C_order);
|
|
|
|
sx - Vector(1..m, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
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.
|
|
, for ;
|
|
if , then exactly ip values of sx must be .
|
|
|
y - Vector(1..n, datatype=float[8]);
|
|
|
On entry: observations on the dependent variable, , for .
|
|
Constraint: , for . .
|
|
|
scale - assignable;
|
|
|
Note: On exit the variable scale will have a value of type float.
|
|
On entry: the scale argument for the gamma model, .
|
|
If , then the scale argument is estimated with the function using the formula described in Section [Description].
|
|
Constraint: . .
|
|
|
ex_power - float;
|
|
|
On entry: if then ex_power must contain the power of the exponential.
|
|
If , ex_power is not referenced.
|
|
Constraint: If , . .
|
|
|
dev - assignable;
|
|
|
Note: On exit the variable dev will have a value of type float.
|
|
On exit: the adjusted deviance for the fitted model.
|
|
|
df - assignable;
|
|
|
Note: On exit the variable df will have a value of type float.
|
|
On exit: the degrees of freedom associated with the deviance for the fitted model.
|
|
|
b - Vector(1..ip, datatype=float[8]);
|
|
|
On exit: the estimates of the arguments of the generalized linear model, .
|
|
|
rank - assignable;
|
|
|
Note: On exit the variable rank will have a value of type float.
|
|
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.
|
|
|
se - Vector(1..ip, datatype=float[8]);
|
|
|
On exit: the standard errors of the linear arguments.
|
|
|
cov - Vector(1.., datatype=float[8]);
|
|
|
Note: the dimension, dim, of the array cov must be at least .
|
|
|
v - Matrix(1..n, 1..tdv, datatype=float[8], order=C_order);
|
|
|
On exit: auxiliary information on the fitted model.
|
|
|
tol - integer;
|
|
|
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.
|
|
Constraint: . .
|
|
|
max_iter - float;
|
|
|
On entry: the maximum number of iterations for the iterative weighted least-squares.
|
|
If , then a default value of 10 is used.
|
|
Constraint: . .
|
|
|
print_iter - integer;
|
|
|
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:
|
|
the current estimates, and
|
|
if the weighted least-squares equations are singular then this is indicated.
|
|
|
eps - float;
|
|
|
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.
|
|
Constraint: . .
|
|
|
'n'=n - integer; (optional)
|
|
|
Default value: the first dimension of the arrays x, y, wt, offset, v.
|
|
On entry: the number of observations, .
|
|
Constraint: . .
|
|
|
'tdx'=tdx - integer; (optional)
|
|
|
On entry: the second dimension of the array x as declared in the function from which nag_glm_gamma (g02gdc) is called.
|
|
Constraint: . .
|
|
|
'm'=m - integer; (optional)
|
|
|
Default value: the first dimension of the array sx and the second dimension of the array sxthe array x.
|
|
On entry: the total number of independent variables.
|
|
Constraint: . .
|
|
|
'ip'=ip - integer; (optional)
|
|
|
Default value: the first dimension of the arrays b, se and the second dimension of the arrays b, sethe array v.
|
|
On entry: the number of independent variables in the model, including the mean or intercept if present.
|
|
Constraint: ip must be . .
|
|
|
'wt'=wt - Vector(1..n, datatype=float[8]); (optional)
|
|
|
On entry: if weighted estimates are required then wt must contain the weights to be used with the model, . Otherwise wt must be supplied as the null pointer, (double *)0.
|
|
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 null pointer, then the effective number of observations is .
|
|
|
'offset'=offset - Vector(1..n, datatype=float[8]); (optional)
|
|
|
On entry: if an offset is required then offset must contain the values of the offset . Otherwise offset must be supplied as the null pointer, (double *)0.
|
|
|
'tdv'=tdv - integer; (optional)
|
|
|
On entry: the second dimension of the array v as declared in the function from which nag_glm_gamma (g02gdc) is called.
|
|
Constraint: . .
|
|
|
'outfile'=outfile - character; (optional)
|
|
|
On entry: The name of a file to which intermediate or diagnostic output should be appended. If a value is not provided for this parameter then the behaviour of this routine is platform dependent. Usually all output will be suppressed, however on some platforms output will be produced and will be displayed in the Maple session.
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_glm_gamma (g02gdc) fits a generalized linear model with gamma errors.
|
|
Description
|
|
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.
|
|
power link: , for a constant ,
|
|
identity link: ,
|
|
log link: ,
|
|
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 .
nag_glm_gamma (g02gdc) finds a decomposition of , i.e.,
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 by diagonal matrix with non-zero diagonal elements, being the rank of and .
This gives the solution
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 by 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 .
nag_glm_gamma (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 (nag_glm_tran_model) after using nag_glm_gamma (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 (nag_glm_est_func).
Details of the SVD, are made available, in the form of the matrix :
|
|
Error Indicators and Warnings
|
|
"NE_ALLOC_FAIL"
Dynamic memory allocation failed.
"NE_BAD_PARAM"
On entry, argument link had an illegal value.
"NE_INT_ARG_LT"
On entry, n must not be less than 2: .
"NE_IP_GT_OBSERV"
ip is greater than the effective number of observations.
"NE_IP_INCOMP_SX"
ip is incompatible with mean and sx.
"NE_LSQ_ITER_NOT_CONV"
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.
"NE_NOT_APPEND_FILE"
Cannot open file for appending.
"NE_NOT_CLOSE_FILE"
Cannot close file .
"NE_RANK_CHANGED"
The rank of the model has changed during the weighted least-squares iterations. The estimate for returned may be reasonable, but the user should check how the deviance has changed during iterations.
"NE_REAL_ARG_LT"
On entry, scale must not be less than 0.0: .
"NE_REAL_ENUM_ARG_CONS"
On entry, , . These arguments must satisfy and .
"NE_SVD_NOT_CONV"
The singular value decomposition has failed to converge.
"NE_VALUE_AT_BOUNDARY_D"
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.
"NE_ZERO_DOF_ERROR"
The degrees of freedom for error are 0. A saturated model has been fitted.
|
|
Accuracy
|
|
The accuracy is determined by tol as described in Section [Parameters]. 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 .
|
|
|
Examples
|
|
>
|
link := "Nag_Reci":
mean := "Nag_MeanInclude":
n := 10:
tdx := 1:
m := 1:
ip := 2:
scale := 0:
ex_power := 0:
tdv := 8:
tol := 0:
max_iter := 10:
print_iter := 0:
eps := 1e-06:
x := Matrix([[1], [1], [1], [1], [1], [0], [0], [0], [0], [0]], datatype=float[8], order='C_order'):
sx := Vector([1], datatype=integer[kernelopts('wordsize')/8]):
y := Vector([1, 0.3, 10.5, 9.699999999999999, 10.9, 0.62, 0.12, 0.09, 0.5, 2.14], datatype=float[8]):
wt := Vector([], datatype=float[8]):
offset := Vector([], datatype=float[8]):
b := Vector(2, datatype=float[8]):
se := Vector(2, datatype=float[8]):
cov := Vector(3, datatype=float[8]):
v := Matrix(10, 8, datatype=float[8], order='C_order'):
NAG:-g02gdc(link, mean, x, sx, y, scale, ex_power, dev, df, b, rank, se, cov, v, tol, max_iter, print_iter, eps, 'n' = n, 'tdx' = tdx, 'm' = m, 'ip' = ip, 'wt' = wt, 'offset' = offset, 'tdv' = tdv):
|
|
|