www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TestforAutocorrelationAmongResidualsExample.m
%% Test for Autocorrelation Among Residuals % This example shows how to test for autocorrelation among the residuals % of a linear regression model. % Copyright 2015 The MathWorks, Inc. %% % Load the sample data and fit a linear regression model. load hald mdl = fitlm(ingredients,heat); %% % Perform a two-sided Durbin-Watson test to determine if there is any autocorrelation % among the residuals of the linear model, |mdl|. [p,DW] = dwtest(mdl,'exact','both') %% % The value of the Durbin-Watson test statistic is 2.0526. The $p$-value % of 0.6285 suggest that the residuals are not autocorrelated.