%Shapiro Wilk Simulation Test 
%
%
%needs swdist
clear all
n=100;
rs=normrnd(0,1,[1 n])+trnd(10,[1 n]);


[wsimul a] =swdist(n);
close all force
histp(wsimul, 100, 0.94, 1);
hold on
W= (sum(a .* sort(rs)))^2/((n-1)*var(rs))
plot([W  W],[0,90],'r-','LineWidth',3)
pval=sum(wsimul < W)/length(wsimul)
%
[h  p wst]=swtest(rs, 0.05, 1)
% activity for NP

% Shapiro, S. S., and Wilk, M. B. (1965), An analysis of variance test for normality (com-
% plete samples), Biometrika 52, 591–611.
% 
% 
% Dudley http://math.mit.edu/~rmd/465/shapiro.pdf
% 
