Why is MATLAB calculation of standard deviation different than a hand calculation?

瘦欲@ 提交于 2019-12-20 05:45:41

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/32238976/why-is-matlab-calculation-of-standard-deviation-different-than-a-hand-calculatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!