It all depends on the nature of the data.

If you're together with 20 friends of yours, and you suddenly ask yourself: "what is the our average age?", you can easily calculate it. Then you can ask: "Ok, now what is the standard deviation of our ages?", because you would like how far from that average you are as a group (I mean, you could average 30 because half are 20 and half are 40, or you could average 30 because all of you are 30). In this case, the population is quite restricted (20 friends), and you're able to carry your calculations on exactly - so you can calculate the population standard deviation. The formula for such calculation is the following (assuming a population of N friends):

x1**2 + x2**2 + ... + xN**2 population_stdev = sqrt(---------------------------) N xi = age_i - average_age
where age_i is the age of your i-th friend in the group, of course.

Now consider the task of calculating the standard deviation over all the people in USA, for example. Doing it all on your own: no databases, no Internet, nothing. How can you approach such a problem? You have to guess: you restrict your investigation to a quite small portion of the entire population, do your calculations and hope that what you observed in this restricted view can be scaled well to the entire USA population. The restricted group you're considering is called a sample; sometimes, you get nothing better than a restricted sample out of the entire population.

In this case, the problem suffers from a clear shift in perspective. What was exact mathematics in the first time, dealing with exactly 20 friends, now becomes a matter of estimation. So, instead of using formulas to calculate stuff exactly, you have to build up formulas that are useful to estimate stuff as good as possible. In particular, the problem here is building up a formula that does not contain a-priori errors, AKA biases.

For the average, i.e. the mean value, it can be demonstrated that the formula is pretty the same as in the exact case. That is, if you use the formula, it can be demonstrated that the result is not biased. This does not mean that it will be equal to the true value you would find if you calculated it over the entire population; it only means that you're not introducing systematic errors, i.e. errors that do not depend on the randomness of the data.

For the standard deviation, the issue is a little trickier. The standard deviation is the square root of another thing called variance (the stuff inside the sqrt() function); it can be proved that the formula above inside the sqrt() function will always introduce a multiplicative bias, which is equal to (N - 1) / N. How do you correct this bias? Simple: you multiply by N and divide by (N - 1). That's why the formula for an unbiased estimate of the standard deviation is the following:

x1**2 + x2**2 + ... + xN**2 sample_stdev = sqrt(---------------------------) N - 1 xi = age_i - average_age
Here, N is the size of the sample, of course.

Just to conclude, keep in mind that sometimes you cannot even think of getting values for the entire population. For example, if your input data are measures of the voltage of a battery, you can potentially get infinite, slightly different measures, without the hope to get them in your lifetime :)

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

In reply to Re^4: standard deviation accuracy question by polettix
in thread standard deviation accuracy question by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.