Calculates the skewness of a given set of data.

View versions (1)

Interface

#include <codecogs/statistics/moments/skewness.h>

using namespace Statistics::Moments;

Skewness is a measure of symmetry, or more precisely, the lack of symmetry. A distribution, or data set, is symmetric if it looks the same to the left and right of the center point. For univariate data x_1, x_2, ..., x_N, the formula for skewness is:

skewness= \frac{1}{(N-1) \sigma^3} \sum_{i=1}^N (x_i - \overline{x})^3
(1)

where \overline{x} is the aritmetic mean, \sigma is the standard deviation, and N is the number of data points.

The skewness for a normal distribution is zero, and any symmetric data should have a skewness near zero. Negative values for the skewness indicate data that are skewed left and positive values for the skewness indicate data that are skewed right.

Example 1

#include <codecogs/statistics/moments/skewness.h>
#include <iostream>
int main()
{
  float x[5] = {3.4 , 7.1 , 1.5 , 8.6 , 4.9};
  double skew = Stats::Moments::skewness<float>(5, x);
  std::cout << "The population skewness is: " << skew << std::endl;
  return 0;
}

Output:

The population skewness is:-0.0107687

Parameters

n
the size of the population
data
the actual population data given as an array

Returns

the skewness of the given set of data
GPL Licence — free for non commercial use. See Licence details.