Accelerating the pace of engineering and science

# feval

Class: LinearModel

Evaluate linear regression model prediction

## Syntax

ypred = feval(mdl,Xnew1,Xnew2,...,Xnewn)

## Description

ypred = feval(mdl,Xnew1,Xnew2,...,Xnewn) returns the predicted response of mdl to the input [Xnew1,Xnew2,...,Xnewn].

## Input Arguments

 mdl Linear model, as constructed by fitlm or stepwiselm. Xnew1,Xnew2,...,Xnewn Predictor components. Xnewi can be one of: ScalarVectorArray Each nonscalar component must have the same size (number of elements in each dimension). If you pass just one Xnew array, Xnew can be a table, dataset array, or an array of doubles, where each column of the array represents one predictor.

## Output Arguments

 ypred Predicted mean values at Xnew. ypred is the same size as each component of Xnew. For models with an offset, feval uses 0 as the offset value.

## Examples

expand all

### Plot Different Categorical Levels

Fit a mileage model to the smallcar data, including the Year categorical predictor. Superimpose fitted curves on a scatter plot of the data.

Load the data and fit a model.

```load carsmall
tbl = table(MPG,Weight);
tbl.Year = ordinal(Model_Year);
mdl = fitlm(tbl,'MPG ~ Year + Weight^2');```

Create a scatter plot of the mileage versus weight.

`gscatter(tbl.Weight,tbl.MPG,tbl.Year);`

Use feval to plot curves of the model predictions for the various years and weights.

```w = linspace(min(tbl.Weight),max(tbl.Weight))';
line(w,feval(mdl,w,'70'),'Color','r')
line(w,feval(mdl,w,'76'),'Color','g')
line(w,feval(mdl,w,'82'),'Color','b')```

## Alternatives

predict gives the same predictions, but uses a single input array with one observation in each row, rather than one component in each input argument. predict also gives confidence intervals on its predictions.