r/askmath • u/HexedDaisy • 4d ago
Statistics Why square the deviations in variance instead of using absolute values?
I'm going through some intro stats material and keep coming back to the definition of variance. Squaring the differences from the mean gets rid of negatives and gives more weight to outliers, but I don't see why that has to be the default choice over just taking the absolute value (which would give the mean absolute deviation).
Is there a reason the squared version leads to nicer properties later on, like with normal distributions, derivatives, or projections? Or does it mostly come down to historical convention and easier algebra? Any simple examples that show where one version clearly works better than the other would help.
47
u/Many-Durian-6530 4d ago
Absolute values are hard to work with.
21
u/OutrageousPair2300 4d ago
Despite how people typically think about the math, squares are actually computationally simpler than absolute values.
Many of the other standard mathematical forms in statistics work well with squares. The value that minimizes the squared distances to the other points in a set is the arithmetic mean. The value that minimizes the absolute distances to the other points is the median. Means are easier to compute than medians.
It all boils down to squares making things easier to compute, really. Working with absolute values, medians, etc. is more robust though. When you have "clean" data it's typically better to use the simpler math, and people only resort to using absolute differences, medians, etc. when they have "dirty" data with many statistical outliers.
43
u/Harmonic_Gear 4d ago
because square is rotationally invariant, when you work with multivariate probability some times it makes more sense that when you rotate the frame of reference the variance shouldn't change
e.g. you shouldn't suddenly be a better shooter when you rotate the target by 45degree
10
u/xnick_uy 3d ago
I want to point out that the covariance between two random variables is defined by
cov(X, Y) = E[ (X - E[X]) (Y - E[Y])]
which is a natural quantity to look at -- using absolute values here wouldn't be particularly useful. The covariance has a lot of useful properties. For instance, If X and Y are independant, then their covariance is zero.
The variance of a random variable X in terms of a covariance is just
var(X) = cov(X, X)
7
u/TheBB 4d ago
(Co)variance is to random variables as the Euclidean inner product is to vectors. Everything else follows from this.
You wouldn't suggest to use the taxicab norm either, I assume.
7
u/StructuredChess 3d ago
Mean absolute error is definitely a legit error measure. It just happens that variance has nicer propierties in some common distributions.
6
u/EighthGreen 4d ago
One nice thing about variance defined in the usual way, is that the variance of the sum of several uncorrelated variables is the sum of the variances of the variables. That saves a lot of work.
4
u/WoodyTheWorker 4d ago
Variance is noise. Energy of the total set is sum of energy of its average and energy of the variance.
4
u/defectivetoaster1 4d ago
Squaring penalises larger outliers more which is nice to have, squaring also differentiates nicely which is extremely nice whenever you’re trying to maximise or minimise variance. Same reason squared error is generally more common than absolute error
3
u/seanv507 4d ago
Basically because variances of independent random variables add up, so variance is a more natural metric
5
u/Head_Evening_5697 4d ago
> Is there a reason the squared version leads to nicer properties later on
I mean, the Math is significantly easier to work with. All the function are analytic instead of not-even-differentiable.
2
u/okarox 4d ago
You can use the absolute values the result is called MAD (Mean absolute deviation). The problem is that to calculate it you need to fist calculate the average and then calculate the average of the differences. That means you must store the entire data (or enter it twice).
On the other hand you can calculate the standard deviation and variance by storing just three values: the count, the sum and the sum of the squares. There is no need to store the entire data set. Also if you add values, you just need to update those three values. That is why even older scientific calculators with limited memory could calculate it. (Modern ones do store the entire data but are limited to some 80 entries)
2
u/steerpike1971 3d ago
Funnily enough I was teaching one today. A simple random walk with X(t) = X(t-1) + 1 probability p and X(t) = X(t-1) - 1 probability 1-p. The mathematics to calculate the expectation of X(t) and X(t)2 and hence variance and standard deviation is just a few lines. The same derivation for the absolute value I don't know.
This is very common in stochastic processes - calculate the expectation of the square easy - calculate the expectation of the absolute value hard.
2
u/Brightlinger 3d ago
A bunch of reasons that other people have already said. But maybe the most important one hasn't been mentioned yet: the variance is objectively more important than the mean absolute deviation or whatever other metric you want to use.
Why? Because of the Central Limit Theorem, which is maybe the most important theorems in statistics. Roughly, CLT says that for a sufficiently large sample size, your sampling distribution is normal, and determined by the variance of your underlying population. Not by the MAD of the population; that doesn't matter. Specifically the variance.
1
u/cigar959 4d ago
The variance as defined arises naturally in many real world problems.
1
u/Crichris 4d ago
you can. but mathematically it's a bit easier to optimize with squared error than the absolute value (piecewise linear)
1
u/Mundane_Prior_7596 3d ago
If you add independent stochastic variables, the variances add. The mean absolute deviations do not add but rather depends on ... Well ... Let me ... Integral H cntrl-C ERROR D
1
u/fluffykitten55 3d ago edited 3d ago
There is a simple reason, and it relates to the normal distribution. The sample variance is the best estimator of the population variance, and then alongside the mean, the best estimator of the parameters of the normal distribution.
Then in the case of OLS, minimising the squared errors in OLS finds the maximum likelihood solution assuming normal residuals.
This is because the log likelihood of an observation is a parabola centred on the expected value using normal error terms.
So the sum of squared errors is then a monotone (actually log) function of the product of the reciprocals of the likelihoods, and both of these are monotonically decreasing in the model likelihood (negative of the log likelihood). So minimising either maximising the model likelihood.
However minimising the sum of the squared errors is computationally easier so we do that and teach it this way too, but it is actually IMO misleading to skip this step in the teaching.
1
u/mH48124 3d ago
分散 σ^2 の 1 次元正規分布 exp[ - (1/2) x^2/σ^2 ]
共分散行列 V の多次元正規分布 exp[ - (1/2) x^T V^{-1} x ]
1
u/free_meson 3d ago
Mainly because of the Normal distribution being a limit for most noises. And the max likelihood of Prod exp(-(x-m)^2) will be just a sum of squares. The variance and mean of the normal distribution are also independent variables, so easy to estimate.
1
u/SpinozaTheSpiteful 3d ago
Squares are easier to manipulate algebraically than absolute values.
1
u/svmydlo 3d ago
Both are examples of p-norms. You take absolute values to the p-th power, sum them, and then take p-th root. If p=1, then it's a sum of absolute values. If p=2, then it's a square root of sum of squares. You can do that for any p≥1.
Among all the possible p-norms the only one induced by an inner product is the 2-norm, i.e. Euclidean norm. That makes it the most convenient to handle as you can use all the tools of linear algebra.
For example, look at the formula for correlation coefficient. It's an angle formula for vectors X and Y. Angles only make sense in spaces with norms induced by an inner product.
1
u/migmit 3d ago
E((x+c)2) = E(x2) + 2cE(x) + c2, if c is a constant. E(|x+c|) = who tf knows.
1
u/Mountain-Time-1010 3d ago
To me it makes a lot of sense in the context of the central limit theorem.