Mrk
Mrk

Reputation: 555

Difference between skewness function and skewness formula result

Consider the matrix

c =

 1     2
 3     4


m = 2;
n = 2;
% mean
% sum1 = uint32(0);
b4 = sum(c);
b5 = sum(b4');
c5 = b5 / ( m * n )

% standard deviation
sum2 = uint32(0);

for i = 1 : m
   for j = 1 : n
     b = ( double(c(i,j)) - c5 ) ^ 2 ;
     sum2 = sum2 + b ;
   end
end
sum3 = sum2 / ( m * n );
std_dev = sqrt(double(sum3))

% skewness

sum9 = 0;
for i = 1 : m
    for j = 1 : n
        skewness_old = ( ( double(c(i,j)) - c5 ) / ( std_dev) )^ 3 ;
        sum9 = sum9 + skewness_old ;
    end
end
skewness_new = sum9 / ( m * n )    

The skewness result is 0

If I use the matlab function skewness,

skewness(c)

c =

 1     2
 3     4

skewness(c)

ans =

 0     0

Why is the function skewness returning two 0's, While the formula returns only one 0

Upvotes: 1

Views: 1383

Answers (1)

yuk
yuk

Reputation: 19870

MATLAB function SKEWNESS by default calculates skewness for each column separately. For the whole matrix do skewness(c(:)).

Upvotes: 2

Related Questions