What is the arithmetic mean of no numbers?

18.6k Views Asked by At

I have two programs that both behave nearly identically: they both take in any numbers you give them and can tell you the arithmetic mean and how many numbers were given. However, when you don't give them any numbers, one says the arithmetic mean is 0.0, and the other says it's NaN ("Not a Number"). Which of these answers, if any, is more correct, and why?

Note: Although I use "programs" as a metaphor here, this isn't a programming question; I could've just as easily said "computers", "machines", "wise men", etc. and my question would be the same

10

There are 10 best solutions below

21
On BEST ANSWER

From a statistical point-of-view, the average of no sample points should not exist. The reason is simple. The average is an indication of the centre of mass of the distribution. Clearly, for no observations there can be no way to prefer one location vs. another as their centre of mass since the the empty set is translation invariant.

More mathematically, taking the average is a linear operation, which means if you add a constant $c$ to each observation, then the average $a$ becomes $a+c$. Now if you add $c$ to each observation in the empty set, you get the empty set again, and thus the average will have to satisfy $a+c=a$ for all $c$, clearly nonsense.

9
On

The average of $n$ numbers is their sum divided by $n$.

If $n=0$ then the sum of $0$ numbers is $0$. But dividing by $0$ will result in a computation error.

Either answer can be taken as correct, depending on your needs.

  • If you want the average of $0$ numbers to be defined, make it $0$ (since it's the only sane choice),
  • and if you want it to be indeterminate (e.g. you want to make a claim like "the average of $a_1,\ldots,a_n$ is the unique $a$ such that $n\cdot a=a_1+\ldots+a_n$", in which case for $n=0$ any $a$ would work) then leave it as an indeterminate.
2
On

The Fréchet mean generalizes the concept of mean to arbitrary metric spaces. It is the point which minimizes the sum-of-squared distances between elements of the dataset $X$: $$\text{arg}\min_\bar{x} \sum_{x\in X} d(\bar{x},x)^2$$

In the case that $X=\varnothing$, the summation is the empty sum and hence $0$, thus there is no minimizer and the mean is undefined.

However, in general there are multiple points that minimize this sum (consider the dataset consisting of a pair of antipodal points on the sphere), so we should not speak of the mean, rather we should consider the set of such points as mean. Then, the empty set has as mean the entire space (presumably $\mathbb{R}$ in this case).

To directly answer the question, NaN would be better, since being undefined is certainly not-a-number and, likewise, a set is not-a-number.

4
On

The correct answer is "Error: Cannot compute the average without any numbers. Please enter at least one number."

$0$ is incorrect, because division by $0$ is undefined, not $0$: $\frac00\neq 0$. If you have $0$ elements, you simply cannot compute their average.

NaN is slightly better, but still kind of wrong. It's a special value of the IEEE floating point standard and represents the result of a calculation that is undefined. It's an implementation detail of how numbers work under the hood, not a proper result to show to the user. You should at least translate it into something like "undefined" or "N/A". Or display a message to explain why there is no result (see above).

4
On

The average of an empty collection of numbers is clearly undefined, as is the centroid of the empty set (or a set of measure zero, for that matter). Therefore the value $0$ given by one of your computers is wrong.

What a clever computer should say in such a case depends on the implementation. I'd expect at least some sort of error message, but certainly not an overflow alert.

2
On

You can have an average of whatever is input (assuming we are not looking at PI which I do not know as having an ending). If you press Enter or whatever method is used to cause an input into the program, then the programming language or input design of the program will interpret that information, likely perform some calculation, then give the result of the calculation.

What I mean is, you can just press enter (with no other value entered) and (depending on the programming language or design of the program) the program can interpret your value (if reading integers) as Zero. Some languages may interpret the input as a non value or nul and may output something similar to your 'NaN'.

However, in answer to your first question, the average of one thing is always that thing. Unless you can only have an average until you have two or more of something to create an average. So whatever is input, as long as it was only one input, would result in that input as being the average.

To answer your ending question, I would say the NaN is more correct because just pressing enter (assuming that is how the data is input) and is done so with the intent of at least not giving a specific value. That is the answer for the person inputting the data. The answer may also depend on the programmers intent on what type of input they are looking for --- numerical (0 may be correct) or non-numerical (Nan is correct).

0
On

The average of $n$ real numbers is defined to be their sum divided by $n$. When there are no numbers, i.e. when $n=0$, we have that the average is $\frac{S}{0}$. It doesn't matter what $S$ equals to (even though by convention the empty sum $S$ is usually taken to be $0$ because of some technical and conceptual reasons) - any real number divided by zero is undefined because it breaks math.

0
On

Others have already given a number of excellent answers, however I'll give one more idea for why an empty average shouldn't be zero, but should instead be undefined. My reasoning is somewhat in line with Ittay's. The point I'd make is that averages of non-empty sets make sense in affine spaces, which look like a vector space where we've forgotten the privileged basepoint.

For example: think about Newtonian Physics or even Special Relativity. In these cases space(time) has a fundamentally affine underlying model. Nevertheless we can take averages of points, for example when looking for centers of mass. But to say the empty average is zero is ridiculous, as zero was arbitrarily chosen.

0
On

In support of the Frechet mean argument, the mean of no numbers is defined as 0/0. This is the solution of the equation x * 0 = 0 (from the definition of division) which is solved by any x. So the mean is any number.

Note that 0/0 is different from a/0 where a != 0, because x * 0 = a has no solutions.

However there is no way to represent "any number" as a double, so if you want a function returning double I would say NaN is the best. Or in C++ you could throw different exceptions to distinguish these cases say NoNumberException and AnyNumberException.

The correct behaviour of a program depends upon the use for which it is intended. I would need to see your User Requirements :-)

1
On

Is this a mathematics question, or a programming question?

If you are asking about the proper behavior for the two programs you have, then my proposal is that the correct output would be throwing an exception (exiting with an error message if they are standalone programs).

Returning zero is unacceptable: the input (empty set) is clearly incorrect for the operation performed (averaging), so the return value can not be a valid one. Returning a NaN is roughly equivalent to the proposed solution of raising an exception/exiting with error message.