1

Matlab:

>> std( [3 2 2 3] )
ans =
    0.5774

Layman's interpretation of standard deviation per Google:

Mean of {3,2,2,3} = 2.5
Deviation from mean for each value = {0.5, 0.5, 0.5, 0.5}
Square of deviation from mean = {0.25, 0.25, 0.25, 0.25}
Mean of the squares = 0.25
Square root of 0.25 = 0.5
Therefore Standard Deviation of {3,2,2,3} = 0.5

What did I muck up? I was foolishly expecting those two numbers to agree.

Jahangir
  • 105
  • 4
David Parks
  • 30,789
  • 47
  • 185
  • 328
  • 1
    Caught by failure to read your Intro Stats textbook :-) . The reasons for using an unbiased estimator can be found there (or elsewhere on the webZ ) – Carl Witthoft Aug 27 '15 at 14:05
  • I was going through the basic stat package on khanacademy.com. I now vaguely recall this, but since it wasn't being mentioned in the problems there it didn't pop up. Hopefully it'll be covered later on. – David Parks Aug 28 '15 at 01:01

1 Answers1

17

Matlab std computes the corrected standard deviation. From help std:

std normalizes Y by (N-1), where N is the sample size. This is the sqrt of an unbiased estimator of the variance of the population from which X is drawn, as long as X consists of independent, identically distributed samples.

So you have

Square of deviation from mean = {0.25, 0.25, 0.25, 0.25}

Then you don't compute the actual root mean of the deviations, but sqrt(sum([0.25 0.25 0.25 0.25])/3). Generally, sum(square of deviation)/(N-1) for a vector of length N.

Update: as Leonid Beschastny pointed out, you can get matlab to calculate the uncorrected standard deviation. Again, from help std:

Y = std(X,1) normalizes by N and produces the square root of the second moment of the sample about its mean. std(X,0) is the same as std(X).

Community
  • 1
  • 1