Lesson 16 of 18

Skewness

Skewness

Skewness measures the asymmetry of a distribution. It tells you whether the data leans left or right relative to the mean.

Formula

The population skewness is the third standardized moment:

skewness=1ni=1n(xixˉ)3σ3\text{skewness} = \frac{\frac{1}{n}\sum_{i=1}^n (x_i - \bar{x})^3}{\sigma^3}

where xˉ\bar{x} is the mean and σ\sigma is the population standard deviation (divide by nn, not n1n-1).

Interpretation

  • Positive skew (right-tailed): the tail extends to the right; mean > median
    • Example: income distributions, waiting times
  • Negative skew (left-tailed): the tail extends to the left; mean < median
    • Example: exam scores when most students do well
  • Zero skew: symmetric distribution (e.g., normal distribution)
Right-skewed:  ▓▓▓▓▓▓▓░░░░     (long tail to the right)
Symmetric:     ░░░▓▓▓▓▓░░░
Left-skewed:   ░░░░▓▓▓▓▓▓▓     (long tail to the left)

Example

data = [0, 0, 3]
mean = 1.0
deviations = [-1, -1, 2]
m3 = ((-1)**3 + (-1)**3 + 2**3) / 3  # = 2.0
std = (2.0) ** 0.5                    # population std
skewness = 2.0 / std**3               # = 0.7071

Your Task

Implement skewness(data) that returns the population skewness rounded to 4 decimal places.

Pyodide loading...
Loading...
Click "Run" to execute your code.