Saying a distribution "has a long right tail" is useful, but two datasets can both lean right by very different amounts. The skewness coefficient turns the lean into a single number. For values x1,…,xn with mean xˉ:
g=(n1∑i=1n(xi−xˉ)2)3/2n1∑i=1n(xi−xˉ)3
- The numerator cubes each distance from the mean. Cubing keeps the sign, so a value far above the mean pushes g up and a value far below pushes it down, and it lets the farthest values dominate.
- The denominator is the population standard deviation σ raised to the power 3. That makes g unit-free: the same data recorded in seconds instead of minutes gives the same g.
Task: write skewness(values) that returns a tuple (g, tail):
g is the coefficient above, rounded to 4 decimal places.
tail names the direction of the longer tail, decided from the rounded g: "right" if g > 0, "left" if g < 0, and "symmetric" if g is exactly 0.
- If every value is identical there is no spread to divide by: return
(0.0, "symmetric").
values is a non-empty list of numbers in any order.