clear all
close all
%

 disp('Sphericity/Circularity Correction for Dialysis Data')
 lw = 3; 
 set(0, 'DefaultAxesFontSize', 16);
 fs = 16;
 msize = 10;
%



weich=[  2.90  2.97  2.67 ;    2.56  2.45  2.62 ;...
         2.88  2.76  1.84 ;    1.73  1.20  1.33 ;...
         2.50  2.16  1.27 ;    3.18  2.89  2.39 ;...
         2.83  2.87  2.39 ;    1.92  2.01  1.66 ];
n = size(weich,1);    %number of subjects, n=8     
k = size(weich,2);    %number of treatments, k=3
Sig = cov(weich);     %covariance matrix of weich  
md = trace(Sig)/k;    %mean of diagonal entries of Sig
ma = mean(mean(Sig)); %mean of all components in Sig
mr = mean(Sig');      %row means of Sig
A = (k*(md-ma))^2;
B = (k-1)*(sum(sum(Sig.^2))-2*k*sum(mr.^2)+k^2*ma^2); 
epsGG = A/B          %Greenhouse-Geisser epsilon 0.7038 
epsHF = (n*(k-1)*epsGG-2)/((k-1)*((n-1)-(k-1)*epsGG))   
                     %Huynh-Feldt epsilon 0.8281
%Corrections based on Trujillo-Ortiz et al. functions 
%epsGG.m and epsHF.m available on MATLAB Central.
F = 9.2436; %F statistic for testing treatment differences
p = 1-fcdf(F,k-1,(n-1)*(k-1))  %unadjusted pvalue 0.0028
%
padjGG = 1-fcdf(F,epsGG*(k-1),epsGG*(n-1)*(k-1)) %0.0085
padjHF = 1-fcdf(F,epsHF*(k-1),epsHF*(n-1)*(k-1)) %0.0053
