Predict response of generalized linear regression model
ypred = predict(mdl,Xnew)
[ypred,yci] = predict(mdl,Xnew)
[ypred,yci] = predict(mdl,Xnew,Name,Value)
Points at which mdl predicts responses.
Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
Positive scalar from 0 to 1. Confidence level of yci is 100(1 – alpha)%.
Default: 0.05, meaning a 95% confidence interval.
Value of the binomial n parameter for each row in the training data. BinomialSize can be a vector the same length as Xnew, or a scalar that applies to each row. The default value 1 produces ypred values that are predicted proportions. Use BinomialSize only if mdl is fit to a binomial distribution.
Value of the offset for each row in Xnew. Offset can be a vector the same length as Xnew, or a scalar that applies to each row. The offset is used as an additional predictor with a coefficient value fixed at 1. In other words, if b is the fitted coefficient vector, and link is the link function,
link(ypred) = Offset + Xnew * b.
Logical value specifying whether the confidence bounds are for all predictor values simultaneously (true), or hold for each individual predictor value (false). Simultaneous bounds are wider than separate bounds, because it is more stringent to require that the entire curve be within the bounds than to require that the curve at a single predictor value be within the bounds.
For details, see polyconf.
Vector of predicted mean values at Xnew.
Confidence intervals, a two-column matrix with each row providing one interval. The meaning of the confidence interval depends on the settings of the name-value pairs.
Create a generalized linear model, and predict its response to new data.
Generate artificial data for the model 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','distr','poisson');
Create points for prediction.
[Xtest1 Xtest2] = meshgrid(-1:.5:3,-2:.5:2); Xnew = [Xtest1(:),Xtest2(:)];
Predict responses at the new points.
ypred = predict(mdl,Xnew);
Plot the predictions.
Create confidence intervals on the predictions.
[ypred yci] = predict(mdl,Xnew);
feval gives the same predictions, but uses separate input arrays for each predictor, instead of one input array containing all predictors.
random predicts with added noise.