% LMcs140601_4th.m
% Uses the resampling toolbox function runs.m
DATA=...
[61 53 58 51 52 34 45 52 46 52 37 39 50 38 55 59 57 64 73 46 48 47 40 35 40]';
n=length(DATA);
[H,P,STATS]=runstest(diff(DATA)>0); % This is not the same runs test a 
                                    % Larsen and Marx. Matlab's runs test 
                                    % considers the number of positive and
                                    % negative runs, but L&M's test just
                                    % considers the total N (25) in
                                    % calculating its test statistic. Thus,
                                    % L&M's test assumes no trend.
% Theorem 14.6.1:
EW=(2*n-1)/3;
VarW=(16*n-29)/90;
Z=(STATS.nruns-EW)/sqrt(VarW)
if Z>0
    p=1-normcdf(Z);
else
    p=normcdf(Z);
end
fprintf(...
  'With Matlab''s runs test, P(%2.0f runs with %2.0f cases) is %5.3f\n',...
  STATS.nruns,n,P)
fprintf(...
  'With Larsen & Marx''s runs test P(%2.0f runs with %2.0f cases) = %5.3f\n',...
  STATS.nruns,n,p)
                 
% Although undocumented, Matlab is probably using the Wald-Wolfowitz runs
% test; When I can get access to my stats books with the exact version
% of the test, I'll check.
                                    
                                    
                              