No BSD License  

Highlights from
testsymmetry

from testsymmetry by Zlatko Petroff
Simple and powerful test detecting asymmetric of distributions.

testsymmetry(X);
% The function testsymmetry(X) implements simple and powerfull method that evidence the presence or 
% absence of asymetric. The method is based on the computation of the mean eighth, mean quartile 
% and the median. If they are equal then there is no evidence that the distribution is asymmetric 
% and we can accept that the distribution is symmetric
%
% X is the row vector of data, which we want ot test for symmetry
%
%
% If you find any bug, the author will be very glad to report for it on the
% following e-mail address: zlatkopetrov@yahoo.com.
% Any comments and suggestions would be accepted with appreciation. 
% 
%
%
% Author: Zlatko Petroff, July 29, 2004


function testsymmetry(X);
if nargin==0, help testsymmetry
    return;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                             Evaluation of median                                              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Y=sort(X);
n=length(X);
m=(n+1)/2;
mm=fix(m);
n=mm-m;
if n==0
    median=Y(m);
    mq=m;
else
    m1=Y(mm);
    m2=Y(mm+1);
    median=(m1+m2)/2;
    mq=mm+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                             Evaluation of quartiles                                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Y1=Y(mq:length(Y));
mm=length(Y1);
q=(mm+1)/2;
qq=fix(q);
n=qq-q;
if n==0
    low_quartile=Y(q);
    high_quartile=Y(q+mm);
    me=q+mm;
else
    q1=Y(qq);
    q2=Y(qq+1);
    low_quartile=(q1+q2)/2;
    q1=Y(qq+mm);
    q2=Y(qq+1+mm);
    high_quartile=(q1+q2)/2;
    me=qq+mm+1;
end
mean_quartile = (low_quartile+high_quartile)/2;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                             Evaluation of eighths                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Y1=Y(me:length(Y));
ee=length(Y1);
e=(ee+1)/2;
ee=fix(e);
n=ee-e;
if n==0
    low_eighth=Y(e);
    high_eighth=Y(e+mm+qq);
else
    e1=Y(ee);
    e2=Y(ee);
    low_eighth=(e1+e2)/2;
    e1=Y(ee+mm+qq);
    e2=Y(ee+mm+qq+1);
    high_eighth=(e1+e2)/2;
end
mean_eighth = (low_eighth+high_eighth)/2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                   Checking of the skewness                                     %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (mean_eighth > mean_quartile & mean_quartile > median)
    disp('The distribution is asymmetrical with a tail to the right.')
elseif (mean_eighth < mean_quartile & mean_quartile < median)
    disp('The distribution is asymmetrical with a tail to the left.')
else
    disp('There is no evidence of asymmetry. You can accept the hypothesis that the distribution is symmetric.')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                          Displaying information for the persetiles                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('The value of median is:');
disp(median)

disp('The value of mean quartile is:');
disp(mean_quartile)

disp('The value of mean eighth is:');
disp(mean_eighth)

n=1:3;
t=[median mean_quartile mean_eighth];
plot(n,t,'bd','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10)
grid on

Contact us at files@mathworks.com