
% SIGN TEST


tcddpla = [2.5 3.1 2.1 3.5 3.1 1.8 6.8 3.0 36.0 ...
   4.7 6.9 3.3 4.6 1.6 7.2 1.8 20.0 2.0 2.5 4.1];
tcddfat = [4.9 5.9 4.4 3.5 7.0 4.2 10.0 5.5 41.0 ...
   4.4 7.0 2.9 4.6 1.4 7.7 1.8 11.0 2.5 2.3 2.5];
% ignore ties
 [pvae, pvaa, n, plusses, ties] =signtst(tcddpla, tcddfat)
%pvae =0.1662
%pvaa =0.1660
%n =17
%plusses =6
%ties =3

% randomize ties
 [pvae, pvaa, n, plusses, ties] =signtst(tcddpla, tcddfat,'R')
% pvae =0.2517
% take the conservative, least favorable approach
 [pvae, pvaa, n, plusses, ties] =signtst(tcddpla, tcddfat,'C')
% pvae =0.0577
% MATLAB's signtest
[p h stat] = signtest(tcddpla, tcddfat)  %NAN???

%%

% WILCOXON SIGNED RANK TEST
   fb = [86 71 77 68 91 72 77 91 70 71 88 87];
   sb = [88 77 76 64 96 72 65 90 65 80 81 72];
   [w1, z1, p] = wsirt(fb, sb, 1)

  % w1 =   17           %value of T
  % z1 =   0.7565       %value of Z
  % p =    0.2382       %p-value of the test
  [h p] = ttest(fb, sb, 0.05, 'right')
  %  0.1866

  
%%

% WILCOXON SUM RANK TEST
% or WILCOXON-MANN-WHITNEY
 monovalent =  [117  92  84 213  89  76  96 104 114 142 ...
                122 154 124  65 129  67 100 127  63  82 ...
                114  93 117  83  82  83 111  78  92  91];

 tetravalent = [103  78 155 107 113  75  74  80 120 112 ...
                158  72  81 124 110  90  64  74 110 149 ...
                 97  70 105  94 110  93 115 114 110 95];

[sumranks1, tstat, pval] = wsurt(monovalent, tetravalent, 0)

% sumranks1 = 925.5000
%
% tstat = 0.1553
%
% pval =  0.8737
[h p] = ttest(monovalent, tetravalent, 0.05, 'both')

%   0.8186
%%

% KRUSKAL-WALLIS TEST

data  =  [ 1 3 4  3 4 5  4 4 4 6 5 ];
belong = [ 1 1 1  2 2 2  3 3 3 3 3 ];
[H, p, aver1] = kruskalwallistest(data, belong)
kwpairwise(data, belong)
 % [H, p, aver1] =  3.8923      0.1428   [3.1667   6    7.7]
 
  
  %MATLAB Built In
   [P,TABLE,STATS] = kruskalwallis(data, belong)
   multcompare(STATS)
 
 %%
 
 % FRIEDMAN TEST
 % six professional drivers evaluated 3 cars (A,B,C).
 % rankings are 1-10
  data = [7  8  9;    6  10  7;   6  8  8; ...
          7  9  8;    7  10  9;   8  8  9];
 [S,F,pS,pF] = friedmantest(data)

%S =  8.2727
%F = 11.0976
%pS =0.0160
%pF =0.0029   % this p-value is more reliable
  friedmanpairwise(data, 0.05)

  
  %MATLAB Built In
   [P,TABLE,STATS] = friedman(data)
   multcompare(STATS)
  
  