|
NAG[g02gbc] NAG[nag_glm_binomial] - Fits a generalized linear model with binomial errors
|
|
Calling Sequence
g02gbc(link, mean, x, sx, y, binom_t, 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_binomial(. . .)
Parameters
|
link - String;
|
|
|
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.
|
|
Constraint: "Nag_Logistic", "Nag_Probit" or "Nag_Compl". .
|
|
|
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 . .
|
|
|
binom_t - Vector(1..n, datatype=float[8]);
|
|
|
On entry: the binomial denominator, .
|
|
Constraint: , for . .
|
|
|
dev - assignable;
|
|
|
Note: On exit the variable dev will have a value of type float.
|
|
On exit: the 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]);
|
|
|
|
rank - assignable;
|
|
|
Note: On exit the variable rank will have a value of type integer.
|
|
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 - float;
|
|
|
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 - integer;
|
|
|
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 precisioninstead.
|
|
Constraint: . .
|
|
|
'n'=n - integer; (optional)
|
|
|
Default value: the first dimension of the arrays x, y, binom_t, 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_binomial (g02gbc) 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: . .
|
|
|
'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_binomial (g02gbc) 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_binomial (g02gbc) fits a generalized linear model with binomial errors.
|
|
Description
|
|
A generalized linear model with binomial errors consists of the following elements:
|
a. a set of observations, , from a binomial distribution:
|
|
The possible link functions are:
|
|
logistic link:
|
|
probit link:
|
|
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 .
nag_glm_binomial (g02gbc) 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 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 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_binomial (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 (nag_glm_tran_model) 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 g02gnc (nag_glm_est_func).
Details of the SVD, are made available, in the form of the matrix :
|
|
Error Indicators and Warnings
|
|
"NE_2_REAL_ARG_GT"
On entry, while . These arguments must satisfy .
"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"
Argument ip is greater than the effective number of observations.
"NE_IP_INCOMP_SX"
Argument ip is incompatible with arguments 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, tol must not be less than 0.0: .
"NE_SVD_NOT_CONV"
The singular value decomposition has failed to converge.
"NE_VALUE_AT_BOUNDARY_B"
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.
|
|
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_Logistic":
mean := "Nag_MeanInclude":
n := 3:
tdx := 1:
m := 1:
ip := 2:
tdv := 8:
tol := 5e-05:
max_iter := 10:
print_iter := 0:
eps := 1e-06:
x := Matrix([[1], [0], [-1]], datatype=float[8], order='C_order'):
sx := Vector([1], datatype=integer[kernelopts('wordsize')/8]):
y := Vector([19, 29, 24], datatype=float[8]):
binom_t := Vector([516, 560, 293], 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(3, 8, datatype=float[8], order='C_order'):
NAG:-g02gbc(link, mean, x, sx, y, binom_t, 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):
|
|
|