为什么标准差的 MATLAB 计算与手工计算不同?
Why is MATLAB calculation of standard deviation different than a hand calculation?
Matlab:
>> std( [3 2 2 3] )
ans =
0.5774
外行对标准差的解释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
我搞砸了什么?我愚蠢地期望这两个数字一致。
Matlab std
计算 corrected standard deviation。来自 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.
所以你有
Square of deviation from mean = {0.25, 0.25, 0.25, 0.25}
那么您不计算偏差的实际均值根,而是 sqrt(sum([0.25 0.25 0.25 0.25])/3)
。通常,sum(square of deviation)/(N-1)
表示长度为 N
.
的向量
更新: 正如Leonid Beschastny指出的,你可以得到matlab来计算未校正的标准偏差。同样,来自 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).
Matlab:
>> std( [3 2 2 3] )
ans =
0.5774
外行对标准差的解释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
我搞砸了什么?我愚蠢地期望这两个数字一致。
Matlab std
计算 corrected standard deviation。来自 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.
所以你有
Square of deviation from mean = {0.25, 0.25, 0.25, 0.25}
那么您不计算偏差的实际均值根,而是 sqrt(sum([0.25 0.25 0.25 0.25])/3)
。通常,sum(square of deviation)/(N-1)
表示长度为 N
.
更新: 正如Leonid Beschastny指出的,你可以得到matlab来计算未校正的标准偏差。同样,来自 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).