Main Content

plotSlice

Plot of slices through fitted linear regression surface

Description

example

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. Use the Bounds menu to choose the type of confidence bounds, and use the Predictors menu to select which predictors to use for each slice plot. For details, see Tips.

Examples

collapse all

Plot slices through a fitted linear regression model surface.

Load the carsmall data set and fit a linear regression model of the mileage as a function of model year, weight, and weight squared.

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

Create a slice plot.

plotSlice(mdl)

Slice plot as a function of the Weight and Year predictors

The green line in each plot represents the predicted response values as a function of a single predictor variable, with the other predictor variables held constant. The red dotted lines are the 95% confidence bounds. The y-axis label includes the predicted response value and the corresponding confidence bound for the point selected by the vertical and horizontal lines. The x-axis label shows the predictor variable name and the predictor value for the selected point.

Note that mdl includes both the Weight and Weight^2 terms, but plotSlice creates only one plot for the Weight term.

Move the vertical line in the Weight plot to the right and observe the change in the y-axis label and the changes in the Year plot.

Slice plot with the vertical line shifted for the Weight plot

Input Arguments

collapse all

Linear regression model object, specified as a LinearModel object created by using fitlm or stepwiselm, or a CompactLinearModel object created by using compact.

Tips

  • Use the Bounds menu in the figure window to choose the type of confidence bounds. You can choose Simultaneous or Non-Simultaneous, and Curve or Observation. You can also choose No Bounds to have no confidence bounds.

    • Simultaneous or Non-Simultaneous

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

      • Non-Simultaneous — plotSlice 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.

      Simultaneous bounds are wider than separate bounds, because requiring the entire curve of response values to be within the bounds is stricter than requiring the response value at a single predictor value to be within the bounds.

    • 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.

Alternative Functionality

  • Use predict to return the predicted response values and confidence bounds. You can also specify the confidence level for confidence bounds by using the 'Alpha' name-value pair argument of the predict function. Note that predict finds nonsimultaneous bounds by default whereas plotSlice finds simultaneous bounds by default.

  • A LinearModel object provides multiple plotting functions.

    • When creating a model, use plotAdded to understand the effect of adding or removing a predictor variable.

    • When verifying a model, use plotDiagnostics to find questionable data and to understand the effect of each observation. Also, use plotResiduals to analyze the residuals of the model.

    • After fitting a model, use plotAdjustedResponse, plotPartialDependence, and plotEffects to understand the effect of a particular predictor. Use plotInteraction to understand the interaction effect between two predictors. Also, use plotSlice to plot slices through the prediction surface.

Extended Capabilities

Version History

Introduced in R2012a