# How the sum of statistical error of a population is not equal to zero?

While searching for difference between error and residual, found this in Wikipedia's article on Errors and residuals

the sum of the residuals within a random sample is necessarily zero, and thus the residuals are necessarily not independent. The statistical errors on the other hand are independent, and their sum within the random sample is almost surely not zero.

Can anyone explain how the sum of statistical error of a population is not equal to zero? And what is that dependent and independent theory.?

P. S. I am very new to statistics. Answers with example will clear my doubt more.

• Can you elaborate on "when I took some sample values randomly from a population I did not find this statement true"? How was it not true? Jul 25, 2017 at 8:55
• @Chill2Macht really sorry actually I was calculating wrong. But now the second part of the statement has become problematic. Why the sum of statistical error is not equal to zero. What is that dependent and independent theory... Can you please explain!!!! Jul 25, 2017 at 9:36
• See Residuals in a linear model are independent but sum to zero; isn't it a contradiction?, & note that the text you cite says the sum of errors within a sample won't generally be zero. Jul 25, 2017 at 12:32
• Actually I asked that too.. Why errors are independent. While residuals are dependent.... What does that mean Jul 26, 2017 at 2:58
• Can you explain what you mean by "independent theory" and "dependent theory"? Where did you see those terms? I know of "independent random variables" and "dependent random variables", but I have not heard of "(in)dependent theory" so it is a little difficult for me to understand what you are asking and to gauge whether I can help you with it. Do you just want to know why the residuals are dependent random variables but why the errors are independent random variables? Jul 27, 2017 at 15:57

Let's suppose you have a coffee machine which produces coffee cups of 50ml. Now, due to various external conditions and technical imperfections, the quantities are not exactly 50ml. The real quantities effectively produced are around 50ml. Let's say that the errors are normally distributed with zero mean and standard deviation equals 1. This describes our population.

We can consider taking the process of producing quantities of coffee modeled as $y = \mu + \epsilon$, where $\mu=50$ and $\epsilon \sim Normal(0,1)$. Consider now taking samples, basically, you will collect a number of samples, which can be considered as observing a number of random variables. Let further suppose your observed sample values are $\{y_1, y_2, y_3, y_4, y_5\} = \{49, 51.1, 47.8, 52.1, 50.5\}$.

Now here comes the trick. In reality, because your random variables are modeled as $Y_i = \mu + \epsilon_i$, you will have the following statistical errors $\epsilon_i = \{-1, 1.1, -2.2, 2.1, 0.5\}$. But this knowledge is not available to you. We can ay the following about the statistical errors:

• the statistical errors are unknown to you, you know only the outcomes $y_i$
• the sum of the errors has zero probability to be equal with $0$. I is intuitive why. As an example think about the situation when you take only one sample, which is the probability to produce exactly 50ml?
• on the other hand if the sample is large, the sum of the errors will go closer to zero, even if it will have zero probability t be exactly $0$.

What does a statistician? He is correctly assuming that the random variables are distributed as $Normal(\mu, \sigma^2)$ an he ask what is the value of $\mu$. What he has is the sample observations $y_i$. He wisely thinks that a good estimator of $\mu$ would be the sample mean: $$\hat{\mu} = \frac{1}{n}\sum_{i=1}^{n}y_i$$ This is actually a really good estimator, unbiased, efficient and so on. So he computes it and he get $\hat{\mu}=50.1$. Notice that the estimated values is different than the real unknown value $\mu = 50$. This is normal and it happens for the same reason why the sum of errors has zero probability to be equal with $0$. Intuitively you can think that the errors which happens produce errors in estimation.

The residual errors can now be computed as $$e_i = y_i - \hat{\mu} = \{-1.1, 1.0, -2.3, 2.0, 0.4\}$$.

You can check now and see that the sum of residual errors is $0$. Why is that? It is because of the way the estimator is build. Let's see:

$$\sum_{i=1}^{n} e_i = \sum_{i=1}^{n} (y_i - \hat{\mu}) = \sum_{i=1}^{n}y_i - n \hat{\mu} = \sum_{i=1}^{n}y_i - n \frac{1}{n}\sum_{i=1}^{n}y_i = 0$$

So, by the way we constructed the esimator the residuals are zero. Because the sum is $0$ we state that the residuals are not independent. This can be checked simply by noticing that if you knew the values of the first $n-1$ residuals, than the value of the last residual is precisely the negative sum of the previous residuals. The last residual does not have a chance to be something else, so it is not independent, its value depends on others.

Now another trick. This is always true? Well, this is not always true, and I think the statement from wikipedia that the sum of residuals is zero is not correct, in the sense that it does not state that this happens in that specific context.

Consider the following procedure. The statistician which estimates the mean $\mu$ does not use the sample mean, but sample median. It is still a good estimator, not as efficient as sample mean, but with enough samples it is robust and work as well. Because of the way the sample median is computed, the sum of the residuals will NOT be zero.

So the conclusion is that the statement: Note that the sum of the residuals within a random sample is necessarily zero, and thus the residuals are necessarily not independent. is valid only for this specific case, of using sample mean to estimate the real mean. Of course, it is valid also in other situations, depending on the way how estimators are formulated. The point is that it is not always true.

• First of all... Very thankful for such a precise answer. Just needed one more help... In your example you have an expected value. What if you don't have that. Like if I have population of 125 samples only and I took a random sample of 25. now while calculating statistical error should I take mean of complete population or mean of sample only Jul 28, 2017 at 18:26

Note: I have more to say about this, but right now I am struggling to think of ways to explain it clearly, and would like to pause so you can give me feedback about what parts of this answer do or do not make sense to you, so I can change the parts currently within the answer, and plan to better write the remaining parts of the answer so you hopefully understand them.

Right now this is not a complete answer nor does it directly address what you are asking, so it should under no circumstances be accepted in its current form.

Part of the reason why the explanation in the Wikipedia article is confusing is because the word "mean" is used to mean (pun unintended) too many different things.

The main difference, when thinking about any of these related concepts, to always keep in mind, is the difference between a population and a sample. (See here, although I don't really like the answers given to the question.)

This also comes down to the difference between a random variable and an observation/realization of a random variable.

That might sound too obvious to be helpful, but it is what always anchored me and helped me to figure things out when I got confused. There are many concepts in statistics which seem similar to each other or somehow redundant, but which one investigates closer, it turns out that a fundamental difference includes the difference between a population and a sample. Whenever you get confused between two concepts in statistics, try asking yourself: "how does this relate to the difference between a population and a sample (from that population)?" Answering that question may anchor you as it has anchored me.

I don't know if the language of probability theory and random variables will either help you or make you more confused, so with that caveat I will continue.

population: In a model of a real-life situation, the mathematical notion of a sample space is what is used to represent a population. Thus the "population mean" corresponds to the notion of expectation of a random variable.

(finite) sample: This is a set of $n$ "realizations" of the random variable. In other words, given a random variable $X$ whose sample space $\Omega$ is the population in question, a sample will be an element of the space $\Omega^n = \Omega \times \dots \times \Omega$, i.e. an $n$-tuple of elements from $\Omega$.

In other words, the population is the entire space $\Omega$, while an individual sample is just one element of that space. The same way that $x \in \mathbb{R}$ and the entire set $\mathbb{R}$ are different kinds of objects.

This is already tricky, but it gets even trickier when one considers sampling. If one "takes a sample at random", then one is observing the outcomes of the random variable $X$, which often causes the distinction between population and sample to appear blurry in theoretical treatments.

If one considers "the" sample, or "a given" sample, then one is talking about a specific element of $\Omega$ ($n = 1$), but if one is talking about "a" sample, then one is talking about a random variable which takes values in the sample space (i.e. the population) $\Omega$.

It becomes even more confusing when one considers (and only knows about) unbiased estimators -- the difference can still be clear when talking about "a given" or "the" sample, but when talking about "a" sample, then one can only talk about the expected value of the estimator (not a particular realization of it) but for unbiased estimators (like the sample mean) the expected value of the estimator is the same as the parameter it is supposed to be estimating, so it is more difficult to see the difference.

Another useful concept to keep in mind here is statistic (Wikipedia also fails us here), which is just any arbitrary function from $\Omega$. But as I mentioned before, understanding this concept well, as well as understanding basically any other concept well in statistics, depends on a clear understanding of the difference between a sample and a population, and this is difficult to explain, since the word sample is also used to mean too many different things (e.g. in particular both the realizations of a random variable as well as the random variable itself). The distinction is usually inferred from the context, but since it is never made explicit, it is difficult to learn in the first place that the distinction exists and needs to be thought about.

• Also please note that I won't be home for about a week after this, so please do not be alarmed when it takes me a long time to respond. Jul 27, 2017 at 16:33

Given a set of data, we might want to split it into two portions - one for fitting and obtaining the model (training data) and one for testing the model (testing data). (There are other methods such as cross-validation)

The rationale is it is often not possible to get the entire population, and the model that we obtain might be better fitted within the existing data set (in your case, the random sample) but may not be able to predict beyond the existing data set.

When used on the training data, we call it residual. It is necessarily zero in cases where our best fitted model is computed by minimising the sum of residuals. However, when your model is tested on the testing data (which was not used to obtain the model), we call the "residuals" as "errors" and these are independent. Because of the "randomness", it is unlikely that you will have zero error.

• Thank you very much for quick response. Just wanted to confirm what I am getting.... So we calculate mean based on the training data and use the same mean on the testing data to calculate the residuals which are basically errors. Jul 25, 2017 at 10:28
• Are you referring to "mean" or "model"? Jul 25, 2017 at 10:46
• I am referring to mean... Let's say for given set of data, mean of the training data is 15.. So when I am calculating the residuals on the testing sample I should use the same value of mean (i.e.15). If you can go through this article en.m.wikipedia.org/wiki/Errors_and_residuals you will better understand what I want to ask. Jul 25, 2017 at 11:12
• Yes, you're right. Jul 25, 2017 at 13:15
• While it is true that using a testing data set you obtain a better estimation for the error, those differences are not statistical errors, but an estimate of them. The OP asks for the properties of the statistical errors which cannot be observed vs residuals. Jul 27, 2017 at 17:30