% Kruskal-Wallis vs ANOVA
clear all
close all
  disp('Kruskal-Wallis versus ANOVA')
  lw =2.5; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 16;
  msize = 10;
  s = RandStream('mt19937ar','Seed',0);
 RandStream.setGlobalStream(s);
 %

addpath('C:\STAT\NP\NPmat\') %needed for kruskalwallistest.m
n=30;
ps=[]; pvals=[];
M=20000 
 for i = 1:M
    % 
% y1= normrnd(1/2, 1,[1 n]);
% y2= gamrnd(1/4, 2,[1 n]);
% y3 = 1/2 + ( 2*(rand(1,n)>0.5)-1).*exprnd(1/sqrt(2),[1 n]);

 y1=normrnd(1/2, 1/3 ,[1 n]);
 y2=gamrnd(1, 1/(2*log(2)),[1 n]);
 y3 =  0.1* rand(1,n)+0.45;

 %[ median(y1) median(y2) median(y3)]
 %mean( [y1' y2' y3'])
% 
data=[y1 y2 y3];
belong=[ones(1,n) 2*ones(1,n) 3*ones(1,n)];
[pv]=kruskalwallistest(data, belong, 0);
[pval]=anova1(data, belong,'off');
ps=[ps pv]; pvals=[pvals pval];
 end
% 
close all force
bihist(ps, pvals, 30)
legend('KW','ANOVA')
%print -depsc 'C:\STAT\NP\NPeps\kwvsanova.eps'