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

Syntax

C#
public static void g02gp(
	string errfn,
	string link,
	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, _
	link 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^ link, 
	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 * 
        link : 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.
errfn="B"
The binomial distribution is used.
errfn="G"
The gamma distribution is used.
errfn="N"
The Normal (Gaussian) distribution is used.
errfn="P"
The Poisson distribution is used.
Constraint: errfn="B", "G", "N" or "P".
mean
Type: System..::..String
On entry: indicates if a mean term is to be included.
mean="M"
A mean term, intercept, will be included in the model.
mean="Z"
The model will pass through the origin, zero-point.
Constraint: mean="M" or "Z".
offset
Type: System..::..String
On entry: indicates if an offset is required.
offset="Y"
An offset must be supplied in off.
offset="N"
off is not referenced.
Constraint: offset="Y" or "N".
weight
Type: System..::..String
On entry: if vfobs=true indicates if weights are used, otherwise weight is not referenced.
weight="U"
No weights are used.
weight="W"
Weights are used and must be supplied in wt.
Constraint: if vfobs=true, weight="U" or "W".
n
Type: System..::..Int32
On entry: n, the number of observations.
Constraint: n1.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: dim1n
Note: the second dimension of the array x must be at least m.
On entry: x[i-1,j-1] must contain the ith observation for the jth independent variable, for i=1,2,,n and j=1,2,,m.
m
Type: System..::..Int32
On entry: m, the total number of independent variables.
Constraint: m1.
isx
Type: array<System..::..Int32>[]()[][]
An array of size [m]
On entry: indicates which independent variables are to be included in the model.
If isx[j-1]>0, the jth independent variable is included in the regression model.
Constraints:
  • isx[j-1]0, for i=1,2,,m;
  • if mean="M", exactly ip-1 values of isx must be >0;
  • if mean="Z", exactly ip values of isx must be >0.
ip
Type: System..::..Int32
On entry: the number of independent variables in the model, including the mean or intercept if present.
Constraint: ip>0.
t
Type: array<System..::..Double>[]()[][]
An array of size [_lt]
Note: the dimension of the array must be at least n if errfn="B", and at least 1 otherwise.
On entry: if errfn="B", t[i-1] must contain the binomial denominator, ti, for the ith observation.
Otherwise t is not referenced.
Constraint: if errfn="B", t[i-1]0.0, for i=1,2,,n.
off
Type: array<System..::..Double>[]()[][]
An array of size [_lof]
Note: the dimension of the array must be at least n if offset="Y", and at least 1 otherwise.
On entry: if offset="Y", off[i-1] must contain the offset oi, for the ith 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 n if weight="W" and vfobs=true, and at least 1 otherwise.
On entry: if weight="W" and vfobs=true, wt[i-1] must contain the weight, wi, for the ith observation.
If the variance of future observations is not included in the standard error of the predicted variable, wt is not referenced.
Constraint: if vfobs=true and weight="W", wt[i-1]0., for i=1,2,,i.
s
Type: System..::..Double
On entry: if errfn="N" or "G" and vfobs=true, the scale parameter, ϕ.
Otherwise s is not referenced and ϕ=1.
Constraint: if errfn="N" or "G" and vfobs=true, s>0.0.
a
Type: System..::..Double
On entry: if link="E", a must contain the power of the exponential.
If link"E", a is not referenced.
Constraint: if link="E", a0.0.
b
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On entry: the model parameters, β.
If mean="M", b[0] must contain the mean parameter and b[i] the coefficient of the variable contained in the jth independent x, where isx[j-1] is the ith positive value in the array isx.
If mean="Z", b[i-1] must contain the coefficient of the variable contained in the jth independent x, where isx[j-1] is the ith positive value in the array isx.
cov
Type: array<System..::..Double>[]()[][]
An array of size [ip×ip+1/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 βi and βj, that is the values stored in b[i-1] and b[j-1], should be supplied in cov[j×j-1/2+i-1], for i=1,2,,ip and j=i,,ip.
Constraint: the matrix represented in cov must be a valid variance-covariance matrix.
vfobs
Type: System..::..Boolean
On entry: if vfobs=true, the variance of future observations is included in the standard error of the predicted variable (i.e., Ifobs=1), otherwise Ifobs=0.
eta
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the linear predictor, η.
seeta
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the standard error of the linear predictor, seη.
pred
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the predicted value, y^.
sepred
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the standard error of the predicted value, sey^. If pred[i-1] could not be calculated, then g02gp returns ifail=22, and sepred[i-1] is set to -99.0.
ifail
Type: System..::..Int32%
On exit: 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 η=Xβ, where X is a matrix of independent variables and β a column vector of p parameters.
(iii) A link function g. between the expected value of y and the linear predictor, that is Ey=μ=gη.
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 β and their associated variance-covariance matrix, C. Suitable values for β 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η=diagXCXT,
o is a vector of offsets and Ifobs=0, if the variance of future observations is not taken into account, and 1 otherwise. Here diagA indicates the diagonal elements of matrix A.
If required, the variance for the ith future observation, Varyi, can be calculated as:
Varyi=ϕVθwi
where wi is a weight, ϕ is the scale (or dispersion) parameter, and Vθ is the variance function. Both the scale parameter and the variance function depend on the distribution used for the y, with:
Poisson Vθ=μi, ϕ=1
binomial Vθ=μiti-μiti, ϕ=1
Normal Vθ=1
gamma Vθ=μi2
In the cases of a Normal and gamma error structure, the scale parameter (ϕ), 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, ϕ=σ^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.
ifail=1
On entry, errfn"B", "P", "G" or "N".
ifail=2
On entry, errfn="B" and link"G", "P" or "C" or errfn"B" and link"E", "I", "L", "R" or "S".
ifail=3
On entry, mean"M" or "Z".
ifail=4
On entry, offset"Y" or "N".
ifail=5
On entry, vfobs=true and weight"U" or "W".
ifail=6
On entry, n<1.
ifail=8
On entry, ldx<n.
ifail=9
On entry, m0.
ifail=10
On entry, number of nonzero elements in isx is not consistent with ip.
ifail=11
On entry, ip<1.
ifail=12
On entry, errfn="B" and t[i-1]<0.0 for at least one i=1,2,,n.
ifail=14
On entry, vfobs=true, weight="W" and wt[i-1]<0.0 for at least one i=1,2,,n.
ifail=15
On entry, vfobs=true, errfn="G" or "N" and s0.0.
ifail=16
On entry, link="E" and a=0.0.
ifail=18
On entry, supplied covariance matrix has at least one diagonal element <0.0.
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.
ifail=-9000
An error occured, see message report.
ifail=-6000
Invalid Parameters value
ifail=-4000
Invalid dimension for array value
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

Not applicable.

Parallelism and Performance

None.

Further Comments

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

See Also