|
NAG[g02gac] NAG[nag_glm_normal] - Fits a generalized linear model with Normal errors
|
|
Calling Sequence
g02gac(link, mean, x, sx, y, scale, ex_power, rss, 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_normal(. . .)
Parameters
|
link - String;
|
|
|
On entry: indicates which link function is to be used.
|
|
An exponent link is used.
|
|
An identity link is used. The user is advised not to use nag_glm_normal (g02gac) with an identity link as g02dac (nag_regsn_mult_linear) provides a more efficient way of fitting such a model.
|
|
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 .
|
|
|
scale - assignable;
|
|
|
Note: On exit the variable scale will have a value of type float.
|
|
On entry: indicates the scale argument for the model, . If , then the scale argument is estimated using the residual mean square.
|
|
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 , . .
|
|
|
rss - assignable;
|
|
|
Note: On exit the variable rss will have a value of type float.
|
|
On exit: the residual sum of squares 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 residual sum of squares 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 residual sum of squares). This is approximately an absolute precision if the residual sum of squares is small and a relative precision if the residual sum of squares 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. The following values are available:
|
|
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, 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_normal (g02gac) 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_normal (g02gac) 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_normal (g02gac) fits a generalized linear model with normal errors.
|
|
Description
|
|
A generalized linear model with Normal errors consists of the following elements:
|
a. a set of observations, , from a Normal distribution with probability density function:
|
|
where is the mean and is the variance.
|
|
exponent link: , for a constant ,
|
|
identity link: ,
|
|
log link: ,
|
|
square root link: ,
|
|
reciprocal link: .
|
|
e. a measure of fit, the residual sum of squares
|
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_normal (g02gac) 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 D is a by diagonal matrix with non-zero 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 residual sum of squares.
The initial values for the algorithm are obtained by taking
The fit of the model can be assessed by examining and testing the residual sum of squares, in particular comparing the difference in residual sums of squares between nested models, i.e., when one model is a sub-model of the other.
Let be the residual sum of squares for the full model with degrees of freedom and let be the residual sum of squares for the sub-model with degrees of freedom then:
has, approximately, a -distribution with , degrees of freedom.
The argument 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 sometimes known as leverages.
The fitted values are given by .
nag_glm_normal (g02gac) also computes the residuals, :
An option allows prior weights, to be used, 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 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_normal (g02gac). Only certain linear combinations of the arguments will have unique estimates; these are known as estimable functions and 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"
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, 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_A"
A fitted value is at a boundary. This will only occur with "Nag_Expo", "Nag_Log" or "Nag_Reci". 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 residual sum of squares is a function of the accuracy of the 's will depend on the link used and may be of the order .
|
|
|
Examples
|
|
>
|
link := "Nag_Reci":
mean := "Nag_MeanInclude":
n := 5:
tdx := 1:
m := 1:
ip := 2:
scale := 0:
ex_power := 0:
tdv := 8:
tol := 5e-05:
max_iter := 10:
print_iter := 0:
eps := 1e-06:
x := Matrix([[1], [2], [3], [4], [5]], datatype=float[8], order='C_order'):
sx := Vector([1], datatype=integer[kernelopts('wordsize')/8]):
y := Vector([25, 10, 6, 4, 3], 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(5, 8, datatype=float[8], order='C_order'):
NAG:-g02gac(link, mean, x, sx, y, scale, ex_power, rss, 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):
|
|
|