function  [p atab stats] = quadetest( data  )
% ------------------------------------------------------------------------------------
%   QUADE TEST
%   Input:  data - data matrix in which rows are blocks/subjects and columns are treatments. 
%           
%   Output:
%    
%                      
%   Comes with M-function ranks.m (ranking procedure)
%-------------------------------------------------------------------------------------
  
  
%   Quade Test
%   D. Quade (1979), Using weighted rankings in the analysis of complete blocks with additive block effects.
%   Journal of the American Statistical Association 74, 680–683.
   %   Quade Test
%   D. Quade (1979), Using weighted rankings in the analysis of complete blocks with additive block effects.
%   Journal of the American Statistical Association 74, 680–683.
     
          [b,k]=size(data);
          rij=ranks(data',0)';
          q= repmat(ranks(range(data')'), 1,k);
          kpl1over2 = (k+1)/2 * ones(size(data));
          sij = q.*(rij - kpl1over2);
          % 
treat=repmat(1:k,b,1);
blocks=repmat((1:b)',1,k);
[p, atab stats] = anovan(sij(:), {treat(:), blocks(:)}, ...
                        'model',1, 'sstype',2, ...
                        'varnames',strvcat('Rows', 'Columns'));
                 
%--------------------------------------------------------------------
function  r = ranks(data, glob)
%--------------------------------------------------------------------
% RANK TRANSFORMATION of data on input
%    Input: data - data to be ranked, data is matrix
%           glob - how to rank data matrix. glob=1 ranks amm matrix components (global 
%                  ranking; glob ne 1 - rank by columns of data. Default glob=1.
%    Output:   r - rank-transformed data
% Finds ranks of a vector of observations and adjusts for ties (by averaging)
% 
% Comment. If ties are no present (ties in ranking are matching observations), 
% ranks can be found simply as the indices in sorting of the indices of the
% sorted data (sentence is OK), i.e.,  [a,b]=sort(data); [c,d]=sort(b);
% and the ranks are in 'd'. If there are ties, they are ranked from left to
% right and also from right to left, and then averaged!
%---------------------------------------------------------------------
if nargin < 2
    glob = 1;
end
    shape = size(data);
if glob == 1    
     data=data(:);
 end     
% Ties ranked from UptoDown
  [ irrelevant , indud ]  =  sort(data);
  [ irrelevant , rUD ]    =  sort(indud);
% Ties ranked from RtoL
  [ irrelevant , inddu ]  =  sort(flipud(data));
  [ irrelevant , rDU ]    =  sort(inddu);
% Averages ranks of ties, keeping ranks of no-tie-observations the same
r = (rUD + flipud(rDU))./2;
r = reshape(r,shape); 
%---------------------------------------------------------------------
% Copyright (C) 2002 by GaTech
% Ver 0.1   9/28/2002


                    