feval - Predict responses of generalized linear regression model using one input for
each predictor - MATLAB ([original](http://www.mathworks.com/help/stats/generalizedlinearmodel.feval.html)) ([raw](?raw))
Predict responses of generalized linear regression model using one input for each predictor
Syntax
Description
[ypred](#btbshi0-ypred) = feval([mdl](#btbshi0%5Fsep%5Fshared-mdl),[Xnew1,Xnew2,...,Xnewn](#btbshi0%5Fsep%5Fshared-Xnew1Xnew2Xnewn))
returns the predicted response of mdl
to the new input predictorsXnew1,Xnew2,...,Xnewn
.
Examples
Create a generalized linear regression model, and plot its responses to a range of input data.
Generate sample data using Poisson random numbers with two underlying predictors X(:,1)
and X(:,2)
.
rng('default') % For reproducibility rndvars = randn(100,2); X = [2 + rndvars(:,1),rndvars(:,2)]; mu = exp(1 + X*[1;2]); y = poissrnd(mu);
Create a generalized linear regression model of Poisson data.
mdl = fitglm(X,y,'y ~ x1 + x2','Distribution','poisson');
Generate a range of values for X(:,1)
and X(:,2)
, and plot the predictions at the values.
[Xtest1,Xtest2] = meshgrid(min(X(:,1)):.5:max(X(:,1)),min(X(:,2)):.5:max(X(:,2))); Z = feval(mdl,Xtest1,Xtest2); surf(Xtest1,Xtest2,Z)
Input Arguments
Data Types: single
| double
| table
Output Arguments
Predicted response values at Xnew1,Xnew2,...,Xnewn, returned as a numeric vector.
For a binomial model, feval
uses 1 as theBinomialSize
parameter, so the values inypred
are predicted probabilities. To return the numbers of successes in the trials, use the predict function and specify the number of trials by using the 'BinomialSize'
name-value pair argument.
For a model with an offset, feval
uses 0 as the offset value. To specify the offset value used when you fit a model, use thepredict function and the'Offset'
name-value pair argument.
Tips
- A regression object is, mathematically, a function that estimates the relationship between the response and predictors. The
feval
function enables an object to behave like a function in MATLABĀ®. You can passfeval
to another function that accepts a function input, such as fminsearch and integral. feval
can be simpler to use with a model created from a table or dataset array. When you have new predictor data, you can pass it tofeval
without creating a table or matrix.
Alternative Functionality
- predict gives the same predictions as
feval
if you use the default values for the 'Offset' and'BinomialSize' name-value pair arguments ofpredict
. The prediction values can be different if you specify other values for these arguments. Thepredict
function also returns confidence intervals on its predictions. Note that thepredict
function accepts a single input argument containing all predictor variables, rather than multiple input arguments with one input for each predictor variable. - random predicts responses with added noise.
Extended Capabilities
Version History
Introduced in R2012a