Main Content

feval

Predict responses of censored linear regression model using one input for each predictor

Since R2025a

    Description

    ypred = feval(mdl,Xnew1,Xnew2,...,Xnewn) returns the predicted responses of mdl to the new input predictors Xnew1,Xnew2,...,Xnewn.

    example

    Examples

    collapse all

    Load the readmissiontimes sample data.

    load readmissiontimes

    The variables Age, Smoker, and ReadmissionTime contain data for patient age, smoking status, and time of readmission. The Censored variable contains censoring information for ReadmissionTime.

    Save Age, Smoker, and ReadmissionTime in a table, and fit a censored linear regression model to the data.

    tbl = table(Age,Smoker,ReadmissionTime);
    mdl = fitlmcens(tbl,Censoring=Censored,CategoricalVars="Smoker");

    mdl is a CensoredLinearModel object that contains the results of fitting a linear model to the censored data.

    Generate curves of new data for each smoking status.

    a = linspace(min(tbl.Age),max(tbl.Age))';
    time_0 = feval(mdl,a,0);
    time_1 = feval(mdl,a,1);

    For each smoking status, plot the prediction curves together with the corresponding input data.

    tiledlayout(1,2)
    nexttile
    line(a,time_0,Color="r")
    hold on
    scatter(tbl.Age(Smoker==0),tbl.ReadmissionTime(Smoker==0),"r");
    title("Nonsmokers")
    xlabel("Age")
    ylabel("Readmission Time")
    nexttile
    line(a,time_1,Color="g")
    hold on
    scatter(tbl.Age(Smoker==1),tbl.ReadmissionTime(Smoker==1),"g");title("Nonsmokers")
    xlabel("Age")
    title("Smokers")

    Figure contains 2 axes objects. Axes object 1 with title Nonsmokers, xlabel Age, ylabel Readmission Time contains 2 objects of type line, scatter. Axes object 2 with title Smokers, xlabel Age contains 2 objects of type line, scatter.

    Input Arguments

    collapse all

    Censored linear regression model, specified as a CensoredLinearModel object created using fitlmcens, or a CompactCensoredLinearModel object created using fitlmcens and compact.

    New input predictor values, specified as a vector, matrix, or table.

    • If you pass multiple inputs Xnew1,Xnew2,...,Xnewn and each includes observations for one predictor variable, then each input must be a vector. Each vector must have the same size. If you specify a predictor variable as a scalar, then feval expands the scalar argument into a constant vector of the same size as the other arguments.

    • If you pass a single input Xnew1, then Xnew1 must be a matrix or table.

      • If Xnew1 is a matrix, it must have the same number of variables (columns) in the same order as the predictor input used to create mdl. Note that Xnew1 must also contain any predictor variables that are as predictors in the fitted model. All variables used in to create mdl must be numeric. To treat numerical predictors as categorical, specify the predictors using the CategoricalVars name-value argument of fitlmcens.

      • If Xnew1 is a table, it must contain predictors that have the same names as predictors in the PredictorNames property of mdl.

    Data Types: single | double | table

    Output Arguments

    collapse all

    Predicted response values at Xnew1,Xnew2,...,Xnewn, returned as a numeric vector.

    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 pass feval 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 to feval without creating a table or matrix.

    Alternative Functionality

    • The predict function gives the same predictions as feval by using a single input argument containing all predictor variables, rather than multiple input arguments with one input for each predictor variable. predict also gives confidence intervals on its predictions.

    • The random function predicts responses with added noise.

    Version History

    Introduced in R2025a