Main Content

plotSlice

Plot of slices through fitted nonlinear regression surface

Description

plotSlice(mdl) creates a figure containing one or more plots, each representing a slice through the regression surface predicted by mdl. Each plot shows the fitted response values as a function of a single predictor variable, with the other predictor variables held constant.

plotSlice also displays the 95% confidence bounds for the response values. You can specify the type of confidence bounds, and select which predictors to use for each slice plot. For more information, see Tips.

example

plotSlice(mdl,Xnew) uses the predictor data in Xnew to create the figure.

example

plotSlice(fig,___) plots into the figure fig instead of the current figure (gcf) using any of the input argument combinations in the previous syntaxes. (since R2024a)

Examples

collapse all

Load the reaction sample data set.

load reaction

The reactants variable contains data for the partial pressures of three chemicals, and the rate variable contains data for the corresponding reaction rates.

Use the hougen function to fit a Hougen-Watson model to the data. Specify reactants as the predictors and rate as the response.

mdl = fitnlm(reactants,rate,@hougen,[1 .05 .02 .1 2]);

mdl is a NonLinearModel object that contains the results of fitting a nonlinear regression model to the data.

Create a slice plot for mdl.

plotSlice(mdl)

Figure Prediction Slice Plots contains 3 axes objects and another object of type uigridlayout. Axes object 1 contains 4 objects of type line, patch. Axes object 2 contains 4 objects of type line, patch. Axes object 3 contains 4 objects of type line, patch.

Each plot shows rate as a function of a single predictor variable, X1, X2, and X3. Each predictor is fixed at the value shown in the x-axis of each plot. In each plot, the 95% confidence intervals are represented by a blue shaded region. The dashed lines indicate a selected point, and the table to the left of the plots shows the response value and confidence bounds for the selected point. You can select a different point by changing the predictor values in the x-axis labels or by dragging the dashed lines to a different location.

Change the value of X1 to 450.

NonLinearModel.plotSlice.png

The plots show that increasing X1 to 450 shifts the regression curves for X2 and X3 toward smaller values for rate.

Load the carbig sample data set.

load carbig

The variables Horsepower and Weight contain data for the horsepower and weight of each car. The variable MPG contains data for miles per gallon.

Create a matrix of predictor data from Horsepower and Weight and define a nonlinear model by using an anonymous function.

X = [Horsepower,Weight];
modelfun = @(b,x)b(1)+b(2)*x(:,1).^b(3)+...
    b(4)*x(:,2).^b(5);

modelfun is a handle to the nonlinear model.

Fit modelfun to the predictor and response data.

mdl = fitnlm(X,MPG,modelfun,[-50 500 -1 500 -1],VarNames=["Horsepower" "Weight" "MPG"]);

mdl is a NonLinearModel object that contains the results of fitting modelfun to the data.

Generate new predictor data for horsepower and weight.

Horsepower_new = 100:200;
Weight_new = 3000:10:4000;
Xnew = [Horsepower_new' Weight_new'];

Create a slice plot for mdl using the new predictor data.

plotSlice(mdl,Xnew)

Figure Prediction Slice Plots contains 2 axes objects and another object of type uigridlayout. Axes object 1 contains 4 objects of type line, patch. Axes object 2 contains 4 objects of type line, patch.

The left plot shows MPG as a function of Horsepower with Weight fixed at 3500. The right plot shows MPG as a function of Weight with Horsepower fixed at 150. The Confidence Interval Type options indicate that the confidence intervals are simultaneous and for the fitted responses. For more information, see Tips.

Load the carbig sample data set.

load carbig

The variables Horsepower and MPG contain data for the horsepower and miles per gallon of each car.

Define a nonlinear model by using an anonymous function.

modelfun = @(b,x)b(1)+b(2)*x.^b(3);

modelfun is a handle to the nonlinear model.

Fit modelfun to the predictor and response data.

mdl = fitnlm(Horsepower,MPG,modelfun,[-50 500 -1],VarNames=["Horsepower" "MPG"]);

mdl is a NonLinearModel object that contains the results of fitting modelfun to the data.

Create a slice plot for mdl.

plotSlice(mdl)

Figure Prediction Slice Plots contains an axes object and another object of type uigridlayout. The axes object contains 5 objects of type line, patch. One or more of the lines displays its values using only markers

Because mdl has only one predictor, the slice plot displays a single set of axes containing a scatter plot of the training data. The regression line for mdl is shown in red together with a shaded region representing the 95% confidence intervals. The Confidence Interval Type options indicate that the confidence intervals are simultaneous and for the fitted responses. For more information, see Tips.

Input Arguments

collapse all

Nonlinear regression model object, specified as a NonLinearModel object created by using fitnlm.

New predictor input values, specified as a table or numeric matrix. If Xnew is a table, its columns must have the same names as the predictors in mdl.VariableNames. If Xnew is a matrix, its columns must correspond to the predictors in mdl.VariableNames. Xnew cannot contain categorical predictor values not used during training.

Data Types: single | double | table

Since R2024a

Target figure, specified as a Figure object. You must create fig using the uifigure function. If you do not specify fig, then plotSlice creates a new figure.

Tips

  • Use the Confidence Interval Type menu in the figure window to choose the type of confidence bounds. You can choose simultaneous or non-simultaneous, and curve or observation.

    • Simultaneous or Non-Simultaneous

      • Simultaneous (default) — plotSlice computes confidence bounds for the curve of the response values using Scheffé's method. The range between the upper and lower confidence bounds contains the curve consisting of true response values with 95% confidence.

      • Non-SimultaneousplotSlice computes confidence bounds for the response value at each observation. The confidence interval for a response value at a specific predictor value contains the true response value with 95% confidence.

      With simultaneous bounds, the entire curve of true response values is within the bounds at high confidence. By contrast, non-simultaneous bounds require only the response value at a single predictor value to be within the bounds at high confidence. Therefore, simultaneous bounds are wider than non-simultaneous bounds.

      If you do not want the plot to display confidence bounds, you can uncheck the Show Confidence Intervals in Plot box.

    • Curve or Observation

      A regression model for the predictor variables X and the response variable y has the form

      y = f(X) + ε,

      where f is a function of X and ε is a random noise term.

      • Curve (default) — plotSlice predicts confidence bounds for the fitted responses f(X).

      • ObservationplotSlice predicts confidence bounds for the response observations y.

      The bounds for y are wider than the bounds for f(X) because of the additional variability of the noise term.

  • Use the Predictors menu in the figure window to select which predictors to use for each slice plot. If the regression model mdl includes more than eight predictors, plotSlice creates plots for the first five predictors by default.

Version History

Introduced in R2012a

expand all