Error and residuals in statistics are the measures of the deviation of an observed value of an element of a statistical sample from its theoretical value. The error of an observed value is the deviation of the observed value from the true function value. The residual of an observed value is the difference between the observed value and the estimated function value. The distinction is most important in regression analysis, where it leads to the concept of studentized residuals.
Suppose there is a series of observations from a univariate distribution and we want to estimate the mean of that distribution. The errors in this case are the deviations of the observations from the population mean, while the residuals are the deviation of the observations from the sample mean.
A statistical error is the amount by which an observation differs from its expected value. In the example above, the latter being based on the whole population from which the statistical unit was chosen randomly. The expected value I the mean of the entire population and therefore the statistical error cannot be observed either.
A residual is an observable estimate of the unobservable statistical error. Consider the previous example with men’s heights and suppose we have a random sample of n people. The sample mean could serve as a good estimator of the population mean. It should be noted that the sum of the residuals within a random sample is necessarily zero, and thus, the residuals are necessarily not independent.