# Calculate variance without calculating the mean

Can we calculate the variance without using the mean as the 'base' point?

• Given $\mathbb{E}(X^2)<\infty$, the variance is given by $\sigma^2 = \mathbb{E}((X-\mathbb{E}(X))^2)$ by definition. The formular simplifies to $\sigma^2 =\mathbb{E}(X^2) - \mathbb{E}(X)^2$. I.e., for the variance you need $\mathbb{E}(X)$. Of course you could define your own dispersion measure using some other statistic...or use one from the answers. Commented Mar 26, 2019 at 7:56
• Short answer: Lots of other ways to summarize variability (dispersion, spread, scale) but none of the others would be the variance. (In fact, the variance can be defined without reference to the mean.) Commented Mar 26, 2019 at 8:28
• Yes: given data $X,$ compute the covariance of $(X,X)$ as described at stats.stackexchange.com/a/18200/919. This method never computes the mean.
– whuber
Commented Mar 26, 2019 at 13:15

The median absolute deviation is defined as $$\text{MAD}(X) = \text{median} |X-\text{median}(X)|$$ and is considered an alternative to the standard deviation. But this is not the variance. In particular, it always exists, whether or not $$X$$ allows for moments. For instance, the MAD of a standard Cauchy is equal to one since $$\underbrace{\Bbb P(|X-0|<1)}_\text{0 is the median}=\arctan(1)/\pi-\arctan(-1)/\pi=\frac{1}{2}$$

• Newcomers to this idea should watch out also for mean absolute deviation from the mean (mean deviation, often) and median absolute deviation from the mean. I don't recall mean absolute deviation from the median, but am open to examples. The abbreviation MAD, unfortunately, has been applied variously, so trust people's code first, then their algebraic or verbal definition, but use of an abbreviation MAD only not at all. In symmetric distributions, and some others, MAD as defined here is half the interquartile range. (Punning on MAD I resist as a little too obvious.) Commented Mar 26, 2019 at 8:23
• Also, note that software implementations of the median absolute deviation function can scale the MAD value by a constant factor from the form presented in this answer, so that its value coincides with the standard deviation for a normal distribution.
– EdM
Commented Mar 26, 2019 at 8:30
• @EdM Excellent point. Personally I dislike that practice unless people use some different term. It's no longer the MAD! Commented Mar 26, 2019 at 8:35
• @NickCox: the appeal of centring on the median is that the quantity always exists, whether or not the distribution enjoys a mean. This is the definition found in Wikipedia. Commented Mar 26, 2019 at 9:20
• Commented Mar 26, 2019 at 10:05

There is already a solution for this question on Math.stackexchange:

1. You can use that the variance is $$\overline{x^2} - \overline {x}^2$$, which takes only one pass (computing the mean and the mean of the squares simultaneously), but can be more prone to roundoff error if the variance is small compared with the mean.
$$2v_X = \frac{1}{n(n-1)}\sum_{1 \le i < j \le n}(x_i - x_j)^2.$$
1. The sample variance without mean is calculated as: $$v_{X}=\frac{1}{n-1}\left [ \sum_{i=1}^{n}x_{i}^{2}-\frac{1}{n}\left ( \sum_{i=1}^{n}x_{i} \right ) ^{2}\right ]$$
• For number 2 - shouldn't it be $v_X$ instead of $2v_X$?