Mean

Overview


The mean (or expected value) of a random variable is the sum (or integral) of each of the variables values multiplied by that values corresponding probability.

Definition


When the random variable is discrete, the mean is just a sum
{% Mean(X) = \sum_i^n X_i \times \mathbb{P}(X_i) %}
which for a distribution where each point is equally likely is
{% Mean(X) = \sum_i^n X_i / n %}

For continuous variables, the mean is an integral
{% Mean(X) = \int X(\omega) d \mathbb{P}(\omega) %}

The mean is written with a stylized E, as a shorthand for "expected value"
{% Mean(X) = \mathbb{E}[X] %}

Properties


  • Linearity : {% \mathbb{E}[aX + bY] = a \mathbb{E}[X] + b \mathbb{E} [Y] %}

Estimation


It is often necessary to estimate what the distribution mean in is from a set of data points sampled from the given distribution. The sample average is usually taken to be the estimator of the distribution mean, mostly on the basis of Law of Large Numbers.

The average can be computed using the $list api as follows.

let numbers = [1,2,3,4,5];
let average = $list(numbers).average();
					
Try it!


Additionally, there is a moments library that provides tools for computing moments. The average can also be computed using the moments library.

let mt = await import('/lib/statistics/moments/v1.0.0/moments.mjs');
let numbers = [1,2,3,4,5];
let average = mt.average(numbers);
					
Try it!

Centering


Often you may have a dataset for which you want to every column to have an average of zero. That is, you may want to compute the average of each column and then subtract that value from each record for that column.

let mt = await import('/lib/statistics/moments/v1.0.0/moments.mjs');
let records = [
	[1,2,3],
	[1,5,3],
	[1,2,6],
	[4,2,3]
]
let data = mt.center(records);
					
Try it!


let mt = await import('/lib/statistics/moments/v1.0.0/moments.mjs');
let records = [
	{price1:100, price2:200},
	{price1:110, price2:204},
	{price1:120, price2:203},
	{price1:90, price2:201},
]
let data = mt.center(records);
					
Try it!

Contents