naginterfaces.library.correg.glm_predict¶
- naginterfaces.library.correg.glm_predict(errfn, x, isx, b, cov, vfobs, link=None, mean='M', t=None, off=None, wt=None, s=0.0, a=0.0)[source]¶
glm_predict
allows prediction from a generalized linear model fit viaglm_normal()
,glm_binomial()
,glm_poisson()
orglm_gamma()
or a linear model fit vialinregm_fit()
.For full information please refer to the NAG Library document for g02gp
https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/g02/g02gpf.html
- Parameters
- errfnstr, length 1
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.
- xfloat, array-like, shape
must contain the th observation for the th independent variable, for , for .
- isxint, array-like, shape
Indicates which independent variables are to be included in the model.
If , the variable contained in the th column of is included in the regression model.
- bfloat, array-like, shape
The model parameters, .
If , must contain the mean parameter and the coefficient of the variable contained in the th independent , where is the th positive value in the array .
If , must contain the coefficient of the variable contained in the th independent , where is the th positive value in the array .
- covfloat, array-like, shape
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 , for .
- vfobsbool
If , the variance of future observations is included in the standard error of the predicted variable (i.e., ), otherwise .
- linkNone or str, length 1, optional
Note: if this argument is None then a default value will be used, determined as follows: if : ; if : ; if : ; otherwise: .
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 Introduction.
- meanstr, length 1, optional
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.
- tNone or float, array-like, shape , optional
Note: the required length for this argument is determined as follows: if : ; otherwise: .
If , must contain the binomial denominator, , for the th observation.
Otherwise is not referenced and may be None.
- offNone or float, array-like, shape , optional
Note: the required length for this argument is determined as follows: if : ; otherwise: .
If an offset is required, then must contain the value of the offset , for the th observation. Otherwise must be None.
- wtNone or float, array-like, shape , optional
Note: the required length for this argument is determined as follows: if : ; otherwise: .
If weighted estimates are required then must contain the weight, for the th observation. Otherwise must be supplied as None.
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 None, the effective number of observations is .
If the variance of future observations is not included in the standard error of the predicted variable, is not referenced.
- sfloat, optional
If or and , the scale parameter, .
Otherwise is not referenced and .
- afloat, optional
If , must contain the power of the exponential.
If , is not referenced.
- Returns
- etafloat, ndarray, shape
The linear predictor, .
- seetafloat, ndarray, shape
The standard error of the linear predictor, .
- predfloat, ndarray, shape
The predicted value, .
- sepredfloat, ndarray, shape
The standard error of the predicted value, . If could not be calculated,
glm_predict
returns = 22, and is set to .
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: , , or .
- (errno )
On entry, .
Constraint: if , , or ,
otherwise, , , , or .
- (errno )
On entry, and .
Constraint: if , , or ,
otherwise, , , , or .
- (errno )
On entry, .
Constraint: or .
- (errno )
On entry, .
Constraint: if , or .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: , for .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: , for all .
- (errno )
On entry, .
Constraint: , for all .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: if , .
- (errno )
On entry, .
Constraint: for at least one diagonal element.
- Warns
- NagAlgorithmicWarning
- (errno )
At least one predicted value could not be calculated as required. is set to for affected predicted values.
- Notes
A generalized linear model consists of the following elements:
A suitable distribution for the dependent variable .
A linear model, with linear predictor , where is a matrix of independent variables and a column vector of parameters.
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
glm_normal()
,glm_binomial()
,glm_poisson()
orglm_gamma()
. 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
In the cases of a Normal and gamma error structure, the scale parameter (), is supplied by you. This value is usually obtained from the function used to fit the prediction model. In many cases, for a Normal error structure, , i.e., the estimated variance.
- References
McCullagh, P and Nelder, J A, 1983, Generalized Linear Models, Chapman and Hall