Some Math


The mean of a set of values [math](x_1, x_2, ..., x_n)[/math] is often represented by [math]\overline{x}[/math]. The calculation of the mean is:

[display]\overline{x} = \mu = {\sum_{i=1}^n x_i \over n}[/display]

The mean may make use of weights (p):

[display]\overline{x} = \mu = {\sum_{i=1}^n x_i p_i \over \sum_{i=1}^n p_i}[/display]

You may want to normalize your weights, which means that their sum will equal 1, with the following:

[display]w_i = {p_i \over {\sum_{j=1}^n p_j}}[/display]

With normalized weights, you can simplify with the following:

[display]\overline{x} = \mu = \sum_{i=1}^n x_i w_i[/display]


The median is the average of "the two center numbers". Say you have a set of n numbers, sorted from smallest to largest, the median is calculated as:

[display]median(x) = {{x_{\lceil{n \over 2}\rceil} + x_{\lceil{n \over 2}\rceil +1}} \over 2}[/display]

Standard Deviation

[display]s = \sigma = \sqrt {{\sum_{i=1}^n (x_i - \overline{x})} \over {n - 1}}[/display]

With a complete sample, you can divide by n instead of n - 1, in which case we get a discrete random variable (assuming normalized weights):

[display]\sigma = \sqrt {{\sum_{i=1}^n w_i{(x_i - \mu)}^2}}[/display]