g02gp allows prediction from a generalized linear model fit via g02gag02gbg02gc or g02gd.

Syntax

C#
```public static void g02gp(
string errfn,
string mean,
string offset,
string weight,
int n,
double[,] x,
int m,
int[] isx,
int ip,
double[] t,
double[] off,
double[] wt,
double s,
double a,
double[] b,
double[] cov,
bool vfobs,
double[] eta,
double[] seeta,
double[] pred,
double[] sepred,
out int ifail
)```
Visual Basic
```Public Shared Sub g02gp ( _
errfn As String, _
mean As String, _
offset As String, _
weight As String, _
n As Integer, _
x As Double(,), _
m As Integer, _
isx As Integer(), _
ip As Integer, _
t As Double(), _
off As Double(), _
wt As Double(), _
s As Double, _
a As Double, _
b As Double(), _
cov As Double(), _
vfobs As Boolean, _
eta As Double(), _
seeta As Double(), _
pred As Double(), _
sepred As Double(), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g02gp(
String^ errfn,
String^ mean,
String^ offset,
String^ weight,
int n,
array<double,2>^ x,
int m,
array<int>^ isx,
int ip,
array<double>^ t,
array<double>^ off,
array<double>^ wt,
double s,
double a,
array<double>^ b,
array<double>^ cov,
bool vfobs,
array<double>^ eta,
array<double>^ seeta,
array<double>^ pred,
array<double>^ sepred,
[OutAttribute] int% ifail
)```
F#
```static member g02gp :
errfn : string *
mean : string *
offset : string *
weight : string *
n : int *
x : float[,] *
m : int *
isx : int[] *
ip : int *
t : float[] *
off : float[] *
wt : float[] *
s : float *
a : float *
b : float[] *
cov : float[] *
vfobs : bool *
eta : float[] *
seeta : float[] *
pred : float[] *
sepred : float[] *
ifail : int byref -> unit
```

Parameters

errfn
Type: System..::..String
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"}$.
mean
Type: System..::..String
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"}$.
offset
Type: System..::..String
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"}$.
weight
Type: System..::..String
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"}$.
n
Type: System..::..Int32
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
Note: the second dimension of the array x must be at least ${\mathbf{m}}$.
On entry: ${\mathbf{x}}\left[\mathit{i}-1,\mathit{j}-1\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}}$.
m
Type: System..::..Int32
On entry: $m$, the total number of independent variables.
Constraint: ${\mathbf{m}}\ge 1$.
isx
Type: array<System..::..Int32>[]()[][]
An array of size [m]
On entry: indicates which independent variables are to be included in the model.
If ${\mathbf{isx}}\left[j-1\right]>0$, the $j$th independent variable is included in the regression model.
Constraints:
• ${\mathbf{isx}}\left[j-1\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$.
ip
Type: System..::..Int32
On entry: the number of independent variables in the model, including the mean or intercept if present.
Constraint: ${\mathbf{ip}}>0$.
t
Type: array<System..::..Double>[]()[][]
An array of size [_lt]
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-1\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}-1\right]\ge 0.0$, for $\mathit{i}=1,2,\dots ,n$.
off
Type: array<System..::..Double>[]()[][]
An array of size [_lof]
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-1\right]$ must contain the offset ${o}_{i}$, for the $i$th observation.
Otherwise off is not referenced.
wt
Type: array<System..::..Double>[]()[][]
An array of size [_lwt]
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-1\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}-1\right]\ge 0$., for $\mathit{i}=1,2,\dots ,\mathit{i}$.
s
Type: System..::..Double
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$.
a
Type: System..::..Double
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$.
b
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On entry: the model parameters, $\beta$.
If ${\mathbf{mean}}=\text{"M"}$, ${\mathbf{b}}\left[0\right]$ must contain the mean parameter and ${\mathbf{b}}\left[i\right]$ the coefficient of the variable contained in the $j$th independent x, where ${\mathbf{isx}}\left[j-1\right]$ is the $i$th positive value in the array isx.
If ${\mathbf{mean}}=\text{"Z"}$, ${\mathbf{b}}\left[i-1\right]$ must contain the coefficient of the variable contained in the $j$th independent x, where ${\mathbf{isx}}\left[j-1\right]$ is the $i$th positive value in the array isx.
cov
Type: array<System..::..Double>[]()[][]
An array of size [${\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2$]
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-1\right]$ and ${\mathbf{b}}\left[j-1\right]$, should be supplied in ${\mathbf{cov}}\left[\mathit{j}×\left(\mathit{j}-1\right)/2+\mathit{i}-1\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.
vfobs
Type: System..::..Boolean
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$.
eta
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the linear predictor, $\eta$.
seeta
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the standard error of the linear predictor, $\mathrm{se}\left(\eta \right)$.
pred
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the predicted value, $\stackrel{^}{y}$.
sepred
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the standard error of the predicted value, $\mathrm{se}\left(\stackrel{^}{y}\right)$. If ${\mathbf{pred}}\left[i-1\right]$ could not be calculated, then g02gp returns ${\mathbf{ifail}}={22}$, and ${\mathbf{sepred}}\left[i-1\right]$ is set to $-99.0$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

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 g02gag02gbg02gc or g02gd. The predicted variable, and its standard error can then be obtained from:
 $y^=g-1η, sey^=δg-1xδxηseη+IfobsVary$
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 method used to fit the prediction model. In many cases, for a Normal error structure, $\varphi ={\stackrel{^}{\sigma }}^{2}$, i.e., the estimated variance.

References

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

Error Indicators and Warnings

Note: g02gp may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDX) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{errfn}}\ne \text{"B"}$, $\text{"P"}$, $\text{"G"}$ or $\text{"N"}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{errfn}}=\text{"B"}$ and ${\mathbf{link}}\ne \text{"G"}$, $\text{"P"}$ or $\text{"C"}$ or ${\mathbf{errfn}}\ne \text{"B"}$ and ${\mathbf{link}}\ne \text{"E"}$, $\text{"I"}$, $\text{"L"}$, $\text{"R"}$ or $\text{"S"}$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{mean}}\ne \text{"M"}$ or $\text{"Z"}$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{offset}}\ne \text{"Y"}$ or $\text{"N"}$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{vfobs}}=\mathrm{true}$ and ${\mathbf{weight}}\ne \text{"U"}$ or $\text{"W"}$.
${\mathbf{ifail}}=6$
On entry, ${\mathbf{n}}<1$.
${\mathbf{ifail}}=8$
On entry, ${\mathbf{ldx}}<{\mathbf{n}}$.
${\mathbf{ifail}}=9$
On entry, ${\mathbf{m}}\le 0$.
${\mathbf{ifail}}=10$
On entry, number of nonzero elements in isx is not consistent with ip.
${\mathbf{ifail}}=11$
On entry, ${\mathbf{ip}}<1$.
${\mathbf{ifail}}=12$
On entry, ${\mathbf{errfn}}=\text{"B"}$ and ${\mathbf{t}}\left[i-1\right]<0.0$ for at least one $i=1,2,\dots ,n$.
${\mathbf{ifail}}=14$
On entry, ${\mathbf{vfobs}}=\mathrm{true}$, ${\mathbf{weight}}=\text{"W"}$ and ${\mathbf{wt}}\left[i-1\right]<0.0$ for at least one $i=1,2,\dots ,n$.
${\mathbf{ifail}}=15$
On entry, ${\mathbf{vfobs}}=\mathrm{true}$, ${\mathbf{errfn}}=\text{"G"}$ or $\text{"N"}$ and ${\mathbf{s}}\le 0.0$.
${\mathbf{ifail}}=16$
On entry, ${\mathbf{link}}=\text{"E"}$ and ${\mathbf{a}}=0.0$.
${\mathbf{ifail}}=18$
On entry, supplied covariance matrix has at least one diagonal element $\text{}<0.0$.
${\mathbf{ifail}}=22$
On exit, at least one predicted value could not be calculated as required. sepred is set to $-99.0$ for affected predicted values.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

Not applicable.

None.

None.

Example

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

Example program (C#): g02gpe.cs

Example program data: g02gpe.d

Example program results: g02gpe.r