问题
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