plotResiduals
Class:LinearMixedModel
情节残差的线性mixed-effects model
Description
plotResiduals(
also plots the residuals of the linear mixed-effects modellme
,plottype
,Name,Value
)lme
with additional options specified by one or more name-value pair arguments. For example, you can specify the residual type to plot.
plotResiduals
also accepts some other name-value pair arguments that specify the properties of the primary line in the plot. For those name-value pairs, seeplot
.
returns a handle,h
= plotResiduals(___)h
, to the lines or patches in the plot of residuals.
Input Arguments
lme
—Linear mixed-effects model
LinearMixedModel
object
Linear mixed-effects model, specified as aLinearMixedModel
object constructed usingfitlme
orfitlmematrix
.
plottype
—Type of residual plot
'histogram'
(default) |'caseorder'
|'fitted'
|'lagged'
|'probability'
|'symmetry'
Type of residual plot, specified as one of the following.
'histogram' |
Default. Histogram of residuals |
'caseorder' |
Residuals versus case (row) order |
'fitted' |
Residuals versus fitted values |
'lagged' |
Residuals versus lagged residual (r(t) versusr(t– 1)) |
'probability' |
Normal probability plot |
'symmetry' |
Symmetry plot |
Example:plotResiduals(lme,'lagged')
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, whereName
is the argument name andValue
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and encloseName
in quotes.
ResidualType
—Residual type
'Raw'
(default) |'Pearson'
|'Standardized'
Residual type, specified by the comma-separated pair consisting ofResidualType
and one of the following.
Residual Type | Conditional | Marginal |
---|---|---|
'Raw' |
|
|
'Pearson' |
|
|
'Standardized' |
|
|
For more information on the conditional and marginal residuals and residual variances, seeDefinitions
at the end of this page.
Example:'ResidualType','Standardized'
Output Arguments
h
— Handle to residual plot
handle
Handle to the residual plot, returned as a handle.
Examples
Examine Residuals
Load the sample data.
load('weight.mat')
weight
contains data from a longitudinal study, where 20 subjects are randomly assigned to 4 exercise programs, and their weight loss is recorded over six 2-week time periods. This is simulated data.
Store the data in a table. DefineSubject
andProgram
as categorical variables.
tbl = table(InitialWeight,Program,Subject,Week,y); tbl.Subject = categorical(tbl.Subject); tbl.Program = categorical(tbl.Program);
Fit a linear mixed-effects model where the initial weight, type of program, week, and the interaction between the week and type of program are the fixed effects. The intercept and week vary by subject.
lme = fitlme(tbl,'y ~ InitialWeight + Program*Week + (Week|Subject)');
Plot the histogram of the raw residuals.
plotResiduals(lme)
Plot the residuals versus the fitted values.
plotResiduals(lme,'fitted')
There is no obvious pattern, so there are no immediate signs of heteroscedasticity.
Create the normal probability plot of residuals.
plotResiduals(lme,'probability')
Data appears to be normal.
Find the observation number for the data that appears to be an outlier to the right of the plot.
find(residuals(lme)>0.25)
ans = 101
Create a box plot of the raw, Pearson, and standardized residuals.
r = residuals(lme); pr = residuals(lme,'ResidualType','Pearson'); st = residuals(lme,'ResidualType','Standardized'); X = [r pr st]; boxplot(X,“标签”,{'Raw','Pearson','Standardized'})
All three box plots point out the outlier on the right tail of the distribution. The box plots of raw and Pearson residuals also point out a second possible outlier on the left tail. Find the corresponding observation number.
find(pr<-2)
ans = 10
Plot the raw residuals versus lagged residuals.
plotResiduals(lme,'lagged')
There is no obvious pattern in the graph. The residuals do not appear to be correlated.
See Also
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
你也可以选择一个网站rom the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)