r/askmath • • 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.

28 Upvotes

56 comments sorted by

47

u/Many-Durian-6530 4d ago

Absolute values are hard to work with.

8

u/AzmiEllez 4d ago

yeah squares keep things differentiable which is a lifesaver when you're already lost in the formulas

15

u/Valuable_Cat_7599 4d ago

absolute values aren't continuous are vital points, while squares are and do the same job, just amplifies and isnt linear

11

u/raspoutyne 4d ago

Not continuous?

21

u/DerHeiligste 4d ago

Maybe they mean not differentiable

5

u/ForceGoat 4d ago

I think he means not smooth (there’s a break).

Several functions are smooth, but not absolute value.

1

u/sippyDrizzle 3d ago

yeah trying to differentiate those absolutes is always a headache in calc

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

4

u/siupa 3d ago

What are you talking about? The other proposed alternative definition is rotationally invariant as well.

Let there be n points on a plane represented by vectors {x_1, …, x_n} and let x_0 be their average. Then

\Sum_{i=1}^n (x_i - x_0)^2

And

\Sum_{i=1}^n |x_i - x_0|

Are both rotationally invariant. If you rotate all the {x_i} about any origin both expressions stay the same.

1

u/svmydlo 3d ago

The \Sum_{i=1}^n |x_i - x_0| is rotationally invariant if the norm of the vector is the usual Euclidean norm, so the square root of the sum of squares of the coordinates. It would not be rotationally invariant if the norm was the 1-norm of sum of absolute values of coordinates.

(cos𝜑)^2+(sin𝜑)^2 is constant

|cos𝜑|+|sin𝜑| is not constant

1

u/siupa 3d ago

Sure? What does this have to do with anything? When did OP or OC talk about the Manhattan norm?

1

u/svmydlo 3d ago

It was directly in the question.

X is a random variable. E(X) is a constant random variable. So, X-E(X) is a vector. Variance should measure its "size", so it should be some kind of metric. Since we are in a vector space, it should be a metric induced by a norm.

The question was why use Euclidean norm instead of Manhattan norm for that purpose.

1

u/siupa 3d ago

I’m sorry, are we reading the same question? The question I’m reading is: “Why, when computing the variance, do we take the sum of the squares of the norms of the differences instead of directly taking the sum of the norms of the differences?” This question is valid for a given type of norm, regardless of what it is.

Instead, you’re telling me that the question your reading is the following: “Why, when computing the variance, do we use the Euclidean norm instead of the Manhattan norm?”

Where are you reading this?

1

u/svmydlo 3d ago

Suppose X is a discrete random variable that can attain values x_1,..., x_n all with equal probability. It can be represented by a vector (x_1,..., x_n). Its expected value is the arithmetic mean a=(x_1+...+x_n)/n.

Then the usual variance of X is defined as the sum of (x_i-a)^2/n for i=1 to n. That's up to the constant 1/n just the square of the Euclidean norm of the vector (x_1,...,x_n)-(a,...a).

OP asks why not use variance defined as the sum of |x_i-a|/n for i=1 to n. That would be up to the constant 1/n the Manhattan norm of the vector (x_1,...,x_n)-(a,...a).

1

u/siupa 3d ago edited 3d ago

I think there’s some kind of confusion going on here, because we seem to be talking about entirely different things. In your previous comment, you said that X - E(X) is a vector. I agree, because individually both X and E(X) are vectors, because they are random variables (not discrete) that can attain vector-valued values. Like the position vectors of the landing location of shots on a target, like the example by OC.

Now instead you’re changing the situation, and saying that X can attain SCALAR values x_1, …, x_n, and the “vector” is simply a representation of a given collection of n outcomes of the random variable X all lumped in a list. Here, X - E(X) is NOT a vector, unlike what you said before. The scenario is markedly different.

Also, here it doesn’t make any physical sense to talk about “rotation” in the abstract n-dimensional space where the list of outcomes lives, as OC was talking about another thing: for the sentence “you’re not a better shooter if you rotate the target by 45°” to have any kind of meaningful sense, we’re obviously talking about rotation in physical space where you rotate each vector x_i individually. Note also how it doesn’t make any sense to talk about “rotating the shots/target/reference frame” if the individual values of the random variable are scalars.

With this cleared: E(X) = (x_1 + … + x_n)/n = a is a vector. X - E(X) is a vector-valued random variable. To use it to compute the variance, we need a norm. We use this norm to compute individually each |x_i - a|. Then we square each and sum them all. The question was: “why squaring them first, and not just summing them?” This is regardless of whether |•| used to compute each individual |x_i - a| is Euclidean or Manhattan.

1

u/svmydlo 3d ago

Right, I see your point now. The rotational invariance is with respect to quite abstract "rotations" in the function space and not related to their example of physical rotation at all.

1

u/MesmerizzeMe 3d ago

which only makes a difference if your observable is a vector. in 1D which is the case that is used common, absolute value is rotationally symmetric as well. great answer nevertheless!

2

u/siupa 3d ago

No? Both things you said are wrong, or worse: one is wrong and the other doesn’t even make sense so it’s not even wrong.

If the data points are vectors, then it doesn’t make a difference whether or not you square the differences or just take the magnitude/norm/absolute value. Both are rotationally invariant.

If the data points are 1D vectors, so just numbers, it doesn’t make sense to even talk about being symmetric under rotations because rotations don’t exist in the first place.

1

u/MesmerizzeMe 2d ago

wow the multiple dimensions were definetly me not being 100% awake thanks for pointing that out. but rotations in 1D are just multiplying by -1. thats the only way to change direction. its trivial but it makes sense.

0

u/GleamMusey 3d ago

that shooter analogy actually makes the rotation thing click

2

u/siupa 3d ago

But it doesn’t make any sense? Yes, the variance shouldn’t change if you rotate the target by any amount of degrees, and in fact it doesn’t: neither if you use squares inside the definition of variance, nor if you use absolute values. So why even bring it up in the first place?

-1

u/LushGleamy 3d ago

the shooter analogy just clicked for me, now i'm wondering what other angles you think about

2

u/siupa 3d ago

But it doesn’t make any sense? Yes, the variance shouldn’t change if you rotate the target by any amount of degrees, and in fact it doesn’t: neither if you use squares inside the definition of variance, nor if you use absolute values. So why even bring it up in the first place?

0

u/desblaterations-574 3d ago

How many dimensions are you doing statistiques with.

One dimension, sure. Multi, not so sure

1

u/siupa 3d ago

What do you mean? What does “rotation” even mean when the data points are 1-dimensional numbers?

0

u/[deleted] 4d ago

[deleted] — view deleted comment

3

u/siupa 3d ago

No? Absolute values of the difference vectors are just as rotationally invariant as squaring the differences.

Also, you could take the variance of any set of data regardless of whether or not the data points represent locations in physical space. It could be the variance of a data set of customer satisfaction scores, blood sugar levels etc… and it doesn’t make any sense in any of these cases to talk about “rotating the data points”. So whatever the advantage of one version of the variance over the other is, it can’t have anything to do with this, because it will still manifest regardless of what your data points actually represent.

It’s a terrible answer in so many different ways

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.

2

u/Brightlinger 3d ago

...which is as the Pythagorean theorem is to regular old distances. Variance quite literally measures how far, in actual plain old geometric distance, your dataset (x1,x2,...,xn) is from the uniform dataset (𝜇,𝜇,...,𝜇). That is a very natural way to measure "how spread out" your data is.

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/bugi_ 3d ago

What does energy have to do with any of this?

1

u/WoodyTheWorker 3d ago

OK, "second moment", if you like that better

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.

2

u/CainPillar 3d ago

the parameters of the normal distribution

We use variance because we use the parameters of the normal distribution is a circular argument.

1

u/fluffykitten55 3d ago edited 3d ago

It is not circular. The choice to work with variances rather than standard deviations, even under the assumption of normality, is a non-trivial one.

We often use the normal distribution (for reasons worth discussing), but conditional on this assumption, we tend to work with variances rather than standard deviations largely because the sample variance is an unbiased estimator of the population variance (and, under normality, the minimum-variance unbiased estimator). This does not hold for the standard deviation, the sample standard deviation is a biased estimator of the population standard deviation and requires the c4 correction factor to be unbiased under normality.

There is also a more general reason to use the variance. The sample variance is an unbiased estimator of population variance more generally for IID distributions with finite variance.

However sample variance is not always the most efficient estimator. E.g. for the uniform distribution the most efficient unbiased estimator of the population variance is a function of the range of observations and this is more efficient than the sample variance.

1

u/CainPillar 2d ago

The choice to work with variances rather than standard deviations

OP is asking why working with the L2 norm based measures at all.

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.