Main Content

plotEffects

Plot main effects of predictors in linear regression model

Description

example

plotEffects(mdl)creates an effects plot of the predictors in the linear regression modelmdl. An effects plot shows the estimatedmain effecton the response from changing each predictor value, averaging out the effects of the other predictors. A horizontal line through an effect value indicates the 95% confidence interval for the effect value.

h= plotEffects(mdl)returns line objects. Usehto modify the properties of a specific line after you create the plot. For a list of properties, seeLine Properties.

Examples

collapse all

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

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

Create an effects plot.

plotEffects(mdl)

Figure contains an axes object. The axes object contains 4 objects of type line.

The length of each horizontal line in the figure shows a 95% confidence interval for the effect on the response of the change shown for each predictor. For example, the estimated effect of changingYearfrom70to82is an increase of about 8, and is between 6 and 10 with 95% confidence.

Input Arguments

collapse all

Linear regression model object, specified as aLinearModelobject created by usingfitlmorstepwiselm, or aCompactLinearModelobject created by usingcompact.

Output Arguments

collapse all

Line objects, returned as a vector.h(1)corresponds to the circles that represent the effect estimates, andh(j+1)corresponds to the 95% confidence interval for the effect of predictorj. Use dot notation to query and set properties of line objects. For details, seeLine Properties.

More About

collapse all

Main Effect

An effect, or main effect, of a predictor represents an effect of one predictor on the response from changing the predictor value while averaging out the effects of the other predictors.

For a predictor variablexs, the effect is defined by

g(xsi) –g(xsj) ,

wheregis an调整ed Responsefunction. TheplotEffectsfunction chooses the observationsiandjas follows. For a categorical variable that is not ordinal,xsiandxsjare the predictor values that produce the maximum and minimum adjusted responses, respectively, so that the effect value is always positive. For a numeric variable or an ordinal categorical variable, the function chooses two predictor values that produce the minimum and maximum adjusted responses wherexsi<xsj.

plotEffectsplots the effect value and the 95% confidence interval of the effect value for each predictor variable.

调整ed Response

An adjusted response function describes the relationship between the fitted response and a single predictor, with the other predictors averaged out by averaging the fitted values over the data used in the fit.

A regression model for the predictor variables(x1,x2, …,xp)and the response variableyhas the form

yi=f(x1i,x2i, …,xpi) +ri,

wherefis a fitted regression function andris a residual. The subscriptirepresents the observation number.

The adjusted response function for the first predictor variablex1, for example, is defined as

g ( x 1 ) = 1 n i = 1 n f ( x 1 , x 2 i , x 3 i , ... , x p i ) ,

wherenis the number of observations. The adjusted response data value is the sum of the adjusted fitted value and the residual for each observation.

y ˜ i = g ( x 1 i ) + r i .

plotAdjustedResponse情节adjus响应函数和调整ted response data values for a selected predictor variable.

Tips

  • The data cursor displays the values of the selected plot point in a data tip (small text box located next to the data point). The data tip includes thex-axis andy-axis values for the selected point. Use thex-axis values to view an estimated effect value and its confidence bounds.

Alternative Functionality

  • ALinearModelobject provides multiple plotting functions.

Extended Capabilities

版本历史

Introduced in R2012a