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

    %% One-Sided Hypothesis Test  

% 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 regression
% residuals, against the alternative hypothesis that the autocorrelation
% is greater than zero. 
[p,d] = dwtest(r,x,'Tail','right') 

%%
% The returned value |p = 0| indicates rejection of the null hypothesis
% at the 5% significance level, in favor of the alternative hypothesis that
% the autocorrelation among residuals is greater than zero.