www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TestResidualsForCorrelationExample.m

    %% Test Residuals For Correlation  

% Copyright 2015 The MathWorks, Inc.


%% 
% Load the sample census data. 
load census 

%% 
% Create a design matrix using the census date (|cdate|) as the predictor.
% Add a column of |1| values to include a constant term. 
n = length(cdate);
x = [ones(n,1),cdate];  

%% 
% Fit a linear regression to the data. 
[b,bint,r] = regress(pop,x);  

%% 
% Test the null hypothesis that there is no autocorrelation among the residuals,
% |r|. 
[p,d] = dwtest(r,x) 

%%
% The returned value |p = 0| indicates rejection of the null hypothesis
% at the 5% significance level.