Code covered by the BSD License  

Highlights from
Sandler's test

from Sandler's test by Giuseppe Cardillo
Calculate the Sandler's test for paired samples

sandler(varargin)
function sandler(varargin)
%Sandler's test for paired samples.
% This file use the Sandler's test to evaluate if exist a difference after a
% treatment. The Sandler's A-value can be transformed in the Student's t-value.
% Sandler requires powerStudent by Trujillo-Ortiz, A. and R. Hernandez-Walls. 
% URL http://www.mathworks.com/matlabcentral/fileexchange/2907
%
% Syntax: 	SANDLER(X1,X2,ALPHA,TAIL)
%      
%     Inputs:
%           X1 and X2 - data vectors. 
%           ALPHA - significance level (default = 0.05).
%           TAIL - 1-tailed test (1) or 2-tailed test (2). (default = 2).
%     Outputs:
%           - A value.
%           - t value.
%           - degrees of freedom.
%           - Critical value.
%           - p-value.
%
%      Example: 
%
%           X1=[77 79 79 80 80 81 81 81 81 82 82 82 82 83 83 84 84 84 84 85 ...
%           85 86 86 87 87];
% 
%           X2=[82 82 83 84 84 85 85 86 86 86 86 86 86 86 86 86 87 87 87 88 ...
%           88 88 89 90 90];
%
%           Calling on Matlab the function: sandler(X1,X2)
%
%           Answer is:
%
%           A value: 0.0421
%           t value: 21.3956
%           Degrees of freedom: 24
%           Critical value at 95% (2-tailed test): 2.0639
%           Probability (p-value) that the observed difference is accidental: 0.0000
%           It is a two-tailed hypothesis test.
%           (The null hypothesis was statistically significative.)
%   
%           Power is: 1.0000
%
%           Created by Giuseppe Cardillo
%           giuseppe.cardillo-edta@poste.it
%
% To cite this file, this would be an appropriate format:
% Cardillo G. (2006). Sandler Test: a function to calculate the Sandler test for paired samples.
% http://www.mathworks.com/matlabcentral/fileexchange/12700


%Input Error handling
args=cell(varargin);
nu=numel(args);
if isempty(nu) || nu==1
    error('Warning: two data vectors are required...')
elseif nu>4
    error('Warning: Max four input data are required')
end
default.values = {[],[],0.05,2};
default.values(1:nu) = args;
[x1 x2 alpha tail] = deal(default.values{:});
if ~isvector(x1) || ~isvector(x2)
   error('SANDLER requires vector rather than matrix data.');
end 
if ((numel(x1) ~= numel(x2))),
   error('Warning: SANDLER requires the data vectors to have the same number of elements.');
end
if ~all(isfinite(x1)) || ~all(isnumeric(x1)) || ~all(isfinite(x2)) || ~all(isnumeric(x2))
    error('Warning: all X1 and X2 values must be numeric and finite')
end
if nu>2
    if ~isscalar(alpha) || ~isnumeric(alpha) || ~isfinite(alpha) || isempty(alpha)
        error('Warning: it is required a numeric, finite and scalar ALPHA value.');
    end
end
if nu>3
    if ~isscalar(tail) || ~isfinite(tail) || ~isnumeric(tail) || isempty(tail)
        error('Warning: it is required a scalar, numeric and finite TAIL value.')
    end
    if tail~=1 && tail~=2 %check if tail is 1 or 2
        error('Warning: TAIL must be 1 or 2.')
    end
end
clear args default nu

n=length(x1); %numbers of elements
d=x1-x2; %difference
A=sum(d.^2)/(sum(d)^2); %Sandler A-value
t=realsqrt((n-1)/(A*n-1)); %Student t-value
p=(1-tcdf(t,n-1))*tail; %t-value associated p-value
vc=tinv(1-alpha/tail,n-1); %critical value
lf=(1-alpha)*100; %fiducial level

%display results
fprintf('A value: %0.4f\n',A)
fprintf('t value: %0.4f\n',t)
fprintf('Degrees of freedom: %d\n',n-1)
fprintf('Critical value at %d%% (%d-tailed test): %0.4f\n',lf,tail,vc)
fprintf('Probability (p-value) that the observed difference is accidental: %0.4f\n',p)
try
    powerStudent(t,n-1,tail,alpha)
catch ME
    disp(ME)
    disp('I am trying to download the powerStudent function by Antonio Trujillo Ortiz from FEX')
    [F,Status]=urlwrite('http://www.mathworks.com/matlabcentral/fileexchange/2907-powerstudent?controller=file_infos&download=true','powerStudent.zip')
    if Status
        unzip(F)
        powerStudent(t,n-1,tail,alpha)
    end
    clear F Status
end

Contact us at files@mathworks.com