h1# Averages: mean, median, mode, range

Basic statistical concepts.

This is a naive collection of mathematical tools for analyzing data and computing averages on it. You have a set of numbers, on which you apply some operations.

h2## Mean

The mean is the average of all the numbers in your set. Add up all the numbers and divide the sum by the size of the set.

 x̄ = (x_1 + x_2 + ... + x_n) / n

The line over x is a bar (aka overbar): a horizontal line written above a mathematical symbol to give it some special meaning. In this case it represents the mean of the set x. Another way of writing it:

 x̄ = 1/n sum_{i=1}^{n} x_i

For example, I calculate the mean of the following set x:

 x = {1, 5, 4, 3, 2, 8}

 x̄ = (1 + 5 + 4 + 3 + 2 + 8) / 6 = 3.8333...

h2## Median

The median is the number in the middle of you sorted set. Yes, the set must be sorted first. If the set has a even amount of numbers, you can't pick the central point. In such case the median is the average of the two middle values. Example:

 x = {1, 2, 3, 4, 5, 8}

 "median(x)" = (4 + 3) / 2 = 3.5

h2## Mode

The mode is the number that occurs more often in your set. Example:

 x = {1, 2, 2, 3, 4, 5, 8}

 "mode(x)" = 2

A set can have more than one mode:

 x = {1, 2, 2, 3, 4, 5, 8, 10, 10, 10}

 "mode(x)" = 2, 10

If no number is repeated, then there is no mode for the set.

h2## Range

The range is the difference between the highest and lowest values of a set. Example:

 x = {1, 2, 3, 4, 5, 8}

 "range(x)" = 8 - 1 = 7