4

Here is what I did :

accumulator_set<double, stats<tag::variance> > accumulator;
accumulator = for_each(x.begin(), x.end(), accumulator);
double sDeviation = sqrt(variance(accumulator));

But the standard deviation returned is the population standard deviation. I need the sample standard deviation (divived by n-1).

Can Boost do that?

Gradient
  • 2,253
  • 6
  • 25
  • 36

1 Answers1

5

Before you take the square root, just multiply variance by n/(n-1). See wikipedia page on standard deviation for the maths. Keep in mind that while the sample variance is unbiased, if you don't know the distribution in question, sample standard deviation is always slightly biased after you take the square root.

jcmcclurg
  • 66
  • 1
  • 2
  • I tested this approach (multiply by n/n-1) and found that it did produce the expected results. – Boinst Apr 15 '16 at 01:54