g02gpc allows prediction from a generalized linear model fit via
g02gac,
g02gbc,
g02gcc or
g02gdc or a linear model fit via
g02dac.
A generalized linear model consists of the following elements:
-
(i)A suitable distribution for the dependent variable .
-
(ii)A linear model, with linear predictor , where is a matrix of independent variables and a column vector of parameters.
-
(iii)A link function between the expected value of and the linear predictor, that is .
In order to predict from a generalized linear model, that is estimate a value for the dependent variable,
, given a set of independent variables
, the matrix
must be supplied, along with values for the parameters
and their associated variance-covariance matrix,
. Suitable values for
and
are usually estimated by first fitting the prediction model to a training dataset with known responses, using for example
g02gac,
g02gbc,
g02gcc or
g02gdc. The predicted variable, and its standard error can then be obtained from:
where
is a vector of offsets and
, if the variance of future observations is not taken into account, and
otherwise. Here
indicates the diagonal elements of matrix
.
If required, the variance for the
th future observation,
, can be calculated as:
where
is a weight,
is the scale (or dispersion) parameter, and
is the variance function. Both the scale parameter and the variance function depend on the distribution used for the
, with:
Poisson |
, |
binomial |
, |
Normal |
|
gamma |
|
-
1:
– Nag_Distributions
Input
-
On entry: indicates the distribution used to model the dependent variable,
.
- The binomial distribution is used.
- The gamma distribution is used.
- The Normal (Gaussian) distribution is used.
- The Poisson distribution is used.
Constraint:
, , or .
-
2:
– Nag_Link
Input
-
On entry: indicates which link function is to be used.
- A complementary log-log link is used.
- An exponent link is used.
- A logistic link is used.
- An identity link is used.
- A log link is used.
- A probit link is used.
- A reciprocal link is used.
- A square root link is used.
Details on the functional form of the different links can be found in the
G02 Chapter Introduction.
Constraints:
- if , , or ;
- otherwise , , , or .
-
3:
– Nag_IncludeMean
Input
-
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:
or .
-
4:
– Integer
Input
-
On entry: , the number of observations.
Constraint:
.
-
5:
– const double
Input
-
Note: the dimension,
dim, of the array
x
must be at least
.
On entry: must contain the th observation for the th independent variable, for and .
-
6:
– Integer
Input
-
On entry: the stride separating matrix column elements in the array
x.
Constraint:
-
7:
– Integer
Input
-
On entry: , the total number of independent variables.
Constraint:
.
-
8:
– const Integer
Input
-
On entry: indicates which independent variables are to be included in the model.
If
, the variable contained in the
th column of
x is included in the regression model.
Constraints:
- , for ;
- if , exactly values of sx must be ;
- if , exactly ip values of sx must be .
-
9:
– Integer
Input
-
On entry: the number of independent variables in the model, including the mean or intercept if present.
Constraint:
.
-
10:
– const double
Input
-
Note: the dimension,
dim, of the array
binom_t
must be at least
- , when .
On entry: if
,
must contain the binomial denominator,
, for the
th observation.
Otherwise
binom_t is not referenced and may be
NULL.
Constraint:
if ,
, for .
-
11:
– const double
Input
-
Note: the dimension,
dim, of the array
offset
must be at least
- , when .
On entry: if an offset is required, then
must contain the value of the offset
, for the
th observation. Otherwise
offset must be
NULL.
-
12:
– const double
Input
-
Note: the dimension,
dim, of the array
wt
must be at least
- , when .
On entry: if weighted estimates are required then
must contain the weight,
for the
th observation. Otherwise
wt must be supplied as
NULL.
If , 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, the effective number of observations is .
If the variance of future observations is not included in the standard error of the predicted variable,
wt is not referenced.
Constraint:
if and , , for .
-
13:
– double
Input
-
On entry: if
or
and
, the scale parameter,
.
Otherwise
scale is not referenced and
.
Constraint:
if or and , .
-
14:
– double
Input
-
On entry: if
,
ex_power must contain the power of the exponential.
If
,
ex_power is not referenced.
Constraint:
if , .
-
15:
– const double
Input
-
On entry: the model parameters,
.
If
,
must contain the mean parameter and
the coefficient of the variable contained in the
th independent
x, where
is the
th positive value in the array
sx.
If
,
must contain the coefficient of the variable contained in the
th independent
x, where
is the
th positive value in the array
sx.
-
16:
– const double
Input
-
On entry: the upper triangular part of the variance-covariance matrix, , of the model parameters. This matrix should be supplied packed by column, i.e., the covariance between parameters and , that is the values stored in and , should be supplied in
, for and .
Constraint:
the matrix represented in
cov must be a valid variance-covariance matrix.
-
17:
– Nag_Boolean
Input
-
On entry: if , the variance of future observations is included in the standard error of the predicted variable (i.e., ), otherwise .
-
18:
– double
Output
-
On exit: the linear predictor, .
-
19:
– double
Output
-
On exit: the standard error of the linear predictor, .
-
20:
– double
Output
-
On exit: the predicted value, .
-
21:
– double
Output
-
On exit: the standard error of the predicted value,
. If
could not be calculated,
g02gpc returns
NE_INVALID_PRED, and
is set to
.
-
22:
– NagError *
Input/Output
-
The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
On entry, the error type and link function combination supplied is invalid.
- NE_CHARACTER
-
On entry, .
Constraint: if , , or ,
otherwise, , , , or .
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
-
On entry, and .
Constraint: .
- NE_INT_ARRAY_CONS
-
On entry, .
Constraint: , for .
- NE_INTERNAL_ERROR
-
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
See
Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
- NE_INVALID_PRED
-
At least one predicted value could not be calculated as required.
sepred is set to
for affected predicted values.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library CL Interface for further information.
- NE_REAL
-
On entry, .
Constraint: if , .
On entry, .
Constraint: .
- NE_REAL_ARRAY_CONS
-
On entry, .
Constraint: , for all .
On entry, .
Constraint: for at least one diagonal element.
On entry, .
Constraint: , for all .
Not applicable.
Background information to multithreading can be found in the
Multithreading documentation.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The model
is fitted to a training dataset with five observations. The resulting model is then used to predict the response for two new observations.