G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

NAG Library Routine DocumentG02GPF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

1  Purpose

G02GPF allows prediction from a generalized linear model fit via G02GAF, G02GBF, G02GCF or G02GDF.

2  Specification

 SUBROUTINE G02GPF ( ERRFN, LINK, MEAN, OFFSET, WEIGHT, N, X, LDX, M, ISX, IP, T, OFF, WT, S, A, B, COV, VFOBS, ETA, SEETA, PRED, SEPRED, IFAIL)
 INTEGER N, LDX, M, ISX(M), IP, IFAIL REAL (KIND=nag_wp) X(LDX,*), T(*), OFF(*), WT(*), S, A, B(IP), COV(IP*(IP+1)/2), ETA(N), SEETA(N), PRED(N), SEPRED(N) LOGICAL VFOBS CHARACTER(1) ERRFN, LINK, MEAN, OFFSET, WEIGHT

3  Description

A generalized linear model consists of the following elements:
 (i) A suitable distribution for the dependent variable $y$. (ii) A linear model, with linear predictor $\eta =X\beta$, where $X$ is a matrix of independent variables and $\beta$ a column vector of $p$ parameters. (iii) A link function $g\left(.\right)$ between the expected value of $y$ and the linear predictor, that is $E\left(y\right)=\mu =g\left(\eta \right)$.
In order to predict from a generalized linear model, that is estimate a value for the dependent variable, $y$, given a set of independent variables $X$, the matrix $X$ must be supplied, along with values for the parameters $\beta$ and their associated variance-covariance matrix, $C$. Suitable values for $\beta$ and $C$ are usually estimated by first fitting the prediction model to a training dataset with known responses, using for example G02GAF, G02GBF, G02GCF or G02GDF. The predicted variable, and its standard error can then be obtained from:
 $y^ = g-1η , se y^ = δg-1x δx η seη + Ifobs Vary$
where
 $η=o+Xβ , seη = diag⁡XCXT ,$
$o$ is a vector of offsets and ${I}_{\mathrm{fobs}}=0$, if the variance of future observations is not taken into account, and $1$ otherwise. Here $\mathrm{diag}A$ indicates the diagonal elements of matrix $A$.
If required, the variance for the $i$th future observation, $\mathrm{Var}\left({y}_{i}\right)$, can be calculated as:
 $Varyi = ϕ Vθ wi$
where ${w}_{i}$ is a weight, $\varphi$ is the scale (or dispersion) parameter, and $V\left(\theta \right)$ is the variance function. Both the scale parameter and the variance function depend on the distribution used for the $y$, with:
 Poisson $V\left(\theta \right)={\mu }_{i}$, $\varphi =1$ binomial $V\left(\theta \right)=\frac{{\mu }_{i}\left({t}_{i}-{\mu }_{i}\right)}{{t}_{i}}$, $\varphi =1$ Normal $V\left(\theta \right)=1$ gamma $V\left(\theta \right)={\mu }_{i}^{2}$
In the cases of a Normal and gamma error structure, the scale parameter ($\varphi$), is supplied by you. This value is usually obtained from the routine used to fit the prediction model. In many cases, for a Normal error structure, $\varphi ={\stackrel{^}{\sigma }}^{2}$, i.e., the estimated variance.

4  References

McCullagh P and Nelder J A (1983) Generalized Linear Models Chapman and Hall

5  Arguments

1:     $\mathrm{ERRFN}$ – CHARACTER(1)Input
On entry: indicates the distribution used to model the dependent variable, $y$.
${\mathbf{ERRFN}}=\text{'B'}$
The binomial distribution is used.
${\mathbf{ERRFN}}=\text{'G'}$
The gamma distribution is used.
${\mathbf{ERRFN}}=\text{'N'}$
The Normal (Gaussian) distribution is used.
${\mathbf{ERRFN}}=\text{'P'}$
The Poisson distribution is used.
Constraint: ${\mathbf{ERRFN}}=\text{'B'}$, $\text{'G'}$, $\text{'N'}$ or $\text{'P'}$.
On entry: indicates which link function to be used.
${\mathbf{LINK}}=\text{'C'}$
A complementary log-log link is used.
${\mathbf{LINK}}=\text{'E'}$
${\mathbf{LINK}}=\text{'G'}$
${\mathbf{LINK}}=\text{'I'}$
${\mathbf{LINK}}=\text{'L'}$
${\mathbf{LINK}}=\text{'P'}$
${\mathbf{LINK}}=\text{'R'}$
${\mathbf{LINK}}=\text{'S'}$
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 ${\mathbf{ERRFN}}=\text{'B'}$, ${\mathbf{LINK}}=\text{'C'}$, $\text{'G'}$ or $\text{'P'}$;
• otherwise ${\mathbf{LINK}}=\text{'E'}$, $\text{'I'}$, $\text{'L'}$, $\text{'R'}$ or $\text{'S'}$.
3:     $\mathrm{MEAN}$ – CHARACTER(1)Input
On entry: indicates if a mean term is to be included.
${\mathbf{MEAN}}=\text{'M'}$
A mean term, intercept, will be included in the model.
${\mathbf{MEAN}}=\text{'Z'}$
The model will pass through the origin, zero-point.
Constraint: ${\mathbf{MEAN}}=\text{'M'}$ or $\text{'Z'}$.
4:     $\mathrm{OFFSET}$ – CHARACTER(1)Input
On entry: indicates if an offset is required.
${\mathbf{OFFSET}}=\text{'Y'}$
An offset must be supplied in OFF.
${\mathbf{OFFSET}}=\text{'N'}$
OFF is not referenced.
Constraint: ${\mathbf{OFFSET}}=\text{'Y'}$ or $\text{'N'}$.
5:     $\mathrm{WEIGHT}$ – CHARACTER(1)Input
On entry: if ${\mathbf{VFOBS}}=\mathrm{.TRUE.}$ indicates if weights are used, otherwise WEIGHT is not referenced.
${\mathbf{WEIGHT}}=\text{'U'}$
No weights are used.
${\mathbf{WEIGHT}}=\text{'W'}$
Weights are used and must be supplied in WT.
Constraint: if ${\mathbf{VFOBS}}=\mathrm{.TRUE.}$, ${\mathbf{WEIGHT}}=\text{'U'}$ or $\text{'W'}$.
6:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{N}}\ge 1$.
7:     $\mathrm{X}\left({\mathbf{LDX}},*\right)$ – REAL (KIND=nag_wp) arrayInput
Note: the second dimension of the array X must be at least ${\mathbf{M}}$.
On entry: ${\mathbf{X}}\left(\mathit{i},\mathit{j}\right)$ must contain the $\mathit{i}$th observation for the $\mathit{j}$th independent variable, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{M}}$.
8:     $\mathrm{LDX}$ – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02GPF is called.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{N}}$.
9:     $\mathrm{M}$ – INTEGERInput
On entry: $m$, the total number of independent variables.
Constraint: ${\mathbf{M}}\ge 1$.
10:   $\mathrm{ISX}\left({\mathbf{M}}\right)$ – INTEGER arrayInput
On entry: indicates which independent variables are to be included in the model.
If ${\mathbf{ISX}}\left(j\right)>0$, the $j$th independent variable is included in the regression model.
Constraints:
• ${\mathbf{ISX}}\left(j\right)\ge 0$, for $\mathit{i}=1,2,\dots ,{\mathbf{M}}$;
• if ${\mathbf{MEAN}}=\text{'M'}$, exactly ${\mathbf{IP}}-1$ values of ISX must be $\text{}>0$;
• if ${\mathbf{MEAN}}=\text{'Z'}$, exactly IP values of ISX must be $\text{}>0$.
11:   $\mathrm{IP}$ – INTEGERInput
On entry: the number of independent variables in the model, including the mean or intercept if present.
Constraint: ${\mathbf{IP}}>0$.
12:   $\mathrm{T}\left(*\right)$ – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array must be at least ${\mathbf{N}}$ if ${\mathbf{ERRFN}}=\text{'B'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{ERRFN}}=\text{'B'}$, ${\mathbf{T}}\left(i\right)$ must contain the binomial denominator, ${t}_{i}$, for the $i$th observation.
Otherwise T is not referenced.
Constraint: if ${\mathbf{ERRFN}}=\text{'B'}$, ${\mathbf{T}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,n$.
13:   $\mathrm{OFF}\left(*\right)$ – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array must be at least ${\mathbf{N}}$ if ${\mathbf{OFFSET}}=\text{'Y'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{OFFSET}}=\text{'Y'}$, ${\mathbf{OFF}}\left(i\right)$ must contain the offset ${o}_{i}$, for the $i$th observation.
Otherwise OFF is not referenced.
14:   $\mathrm{WT}\left(*\right)$ – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array must be at least ${\mathbf{N}}$ if ${\mathbf{WEIGHT}}=\text{'W'}$ and ${\mathbf{VFOBS}}=\mathrm{.TRUE.}$, and at least $1$ otherwise.
On entry: if ${\mathbf{WEIGHT}}=\text{'W'}$ and ${\mathbf{VFOBS}}=\mathrm{.TRUE.}$, ${\mathbf{WT}}\left(i\right)$ must contain the weight, ${w}_{i}$, for the $i$th observation.
If the variance of future observations is not included in the standard error of the predicted variable, WT is not referenced.
Constraint: if ${\mathbf{VFOBS}}=\mathrm{.TRUE.}$ and ${\mathbf{WEIGHT}}=\text{'W'}$, ${\mathbf{WT}}\left(\mathit{i}\right)\ge 0$., for $\mathit{i}=1,2,\dots ,\mathit{i}$.
15:   $\mathrm{S}$ – REAL (KIND=nag_wp)Input
On entry: if ${\mathbf{ERRFN}}=\text{'N'}$ or $\text{'G'}$ and ${\mathbf{VFOBS}}=\mathrm{.TRUE.}$, the scale parameter, $\varphi$.
Otherwise S is not referenced and $\varphi =1$.
Constraint: if ${\mathbf{ERRFN}}=\text{'N'}$ or $\text{'G'}$ and ${\mathbf{VFOBS}}=\mathrm{.TRUE.}$, ${\mathbf{S}}>0.0$.
16:   $\mathrm{A}$ – REAL (KIND=nag_wp)Input
On entry: if ${\mathbf{LINK}}=\text{'E'}$, A must contain the power of the exponential.
If ${\mathbf{LINK}}\ne \text{'E'}$, A is not referenced.
Constraint: if ${\mathbf{LINK}}=\text{'E'}$, ${\mathbf{A}}\ne 0.0$.
17:   $\mathrm{B}\left({\mathbf{IP}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the model parameters, $\beta$.
If ${\mathbf{MEAN}}=\text{'M'}$, ${\mathbf{B}}\left(1\right)$ must contain the mean parameter and ${\mathbf{B}}\left(i+1\right)$ the coefficient of the variable contained in the $j$th independent X, where ${\mathbf{ISX}}\left(j\right)$ is the $i$th positive value in the array ISX.
If ${\mathbf{MEAN}}=\text{'Z'}$, ${\mathbf{B}}\left(i\right)$ must contain the coefficient of the variable contained in the $j$th independent X, where ${\mathbf{ISX}}\left(j\right)$ is the $i$th positive value in the array ISX.
18:   $\mathrm{COV}\left({\mathbf{IP}}×\left({\mathbf{IP}}+1\right)/2\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the upper triangular part of the variance-covariance matrix, $C$, of the model parameters. This matrix should be supplied packed by column, i.e., the covariance between parameters ${\beta }_{i}$ and ${\beta }_{j}$, that is the values stored in ${\mathbf{B}}\left(i\right)$ and ${\mathbf{B}}\left(j\right)$, should be supplied in ${\mathbf{COV}}\left(\mathit{j}×\left(\mathit{j}-1\right)/2+\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{IP}}$ and $\mathit{j}=\mathit{i},\dots ,{\mathbf{IP}}$.
Constraint: the matrix represented in COV must be a valid variance-covariance matrix.
19:   $\mathrm{VFOBS}$ – LOGICALInput
On entry: if ${\mathbf{VFOBS}}=\mathrm{.TRUE.}$, the variance of future observations is included in the standard error of the predicted variable (i.e., ${I}_{\mathrm{fobs}}=1$), otherwise ${I}_{\mathrm{fobs}}=0$.
20:   $\mathrm{ETA}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the linear predictor, $\eta$.
21:   $\mathrm{SEETA}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the standard error of the linear predictor, $\mathrm{se}\left(\eta \right)$.
22:   $\mathrm{PRED}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the predicted value, $\stackrel{^}{y}$.
23:   $\mathrm{SEPRED}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the standard error of the predicted value, $\mathrm{se}\left(\stackrel{^}{y}\right)$. If ${\mathbf{PRED}}\left(i\right)$ could not be calculated, then G02GPF returns ${\mathbf{IFAIL}}={\mathbf{22}}$, and ${\mathbf{SEPRED}}\left(i\right)$ is set to $-99.0$.
24:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if ${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}1$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G02GPF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ERRFN is invalid: ${\mathbf{ERRFN}}=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=2$
On entry, ERRFN and LINK combination is invalid: ${\mathbf{ERRFN}}=〈\mathit{\text{value}}〉$, ${\mathbf{LINK}}=〈\mathit{\text{value}}〉$.
On entry, LINK is invalid: ${\mathbf{LINK}}=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=3$
On entry, MEAN is invalid: ${\mathbf{MEAN}}=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=4$
On entry, OFFSET is invalid: ${\mathbf{OFFSET}}=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=5$
On entry, WEIGHT is invalid: ${\mathbf{WEIGHT}}=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=6$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{N}}\ge 1$.
${\mathbf{IFAIL}}=8$
On entry, ${\mathbf{LDX}}=〈\mathit{\text{value}}〉$ and ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{N}}$.
${\mathbf{IFAIL}}=9$
On entry, ${\mathbf{M}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{M}}\ge 1$.
${\mathbf{IFAIL}}=10$
On entry, ISX not consistent with IP: $〈\mathit{\text{value}}〉$ values $>0$, expected $〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=11$
On entry, ${\mathbf{IP}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{IP}}>0$.
${\mathbf{IFAIL}}=12$
On entry, $i=〈\mathit{\text{value}}〉$ and ${\mathbf{T}}\left(i\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{T}}\left(i\right)\ge 0.0$, for all $i$.
${\mathbf{IFAIL}}=14$
On entry, $i=〈\mathit{\text{value}}〉$ and ${\mathbf{WT}}\left(i\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{WT}}\left(i\right)\ge 0.0$, for all $i$.
${\mathbf{IFAIL}}=15$
On entry, ${\mathbf{S}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{S}}>0.0$.
${\mathbf{IFAIL}}=16$
On entry, ${\mathbf{A}}=0.0$.
${\mathbf{IFAIL}}=18$
On entry, ${\mathbf{COV}}\left(i\right)<0.0$ for at least one diagonal element: $i=〈\mathit{\text{value}}〉$, ${\mathbf{COV}}\left(i\right)=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=22$
At least one predicted value could not be calculated as required. SEPRED is set to $-99.0$ for affected predicted values.
${\mathbf{IFAIL}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

8  Parallelism and Performance

G02GPF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

10  Example

The model
 $y = 1 β1 + β2 x + ε$
is fitted to a training dataset with five observations. The resulting model is then used to predict the response for two new observations.

10.1  Program Text

Program Text (g02gpfe.f90)

10.2  Program Data

Program Data (g02gpfe.d)

10.3  Program Results

Program Results (g02gpfe.r)