為什么樣本方差(sample variance)的分母是 n-1?
(補充一句哦,題主問的方差 estimator 通常用 moments 方法估計。如果用的是 ML 方法,請不要多想不是你們想的那樣, 方差的 estimator 的期望一樣是有 bias 的,有興趣的同學可以自己用正態分佈算算看。)
本來,按照定義,方差的 estimator 應該是這個:
但,這個 estimator 有 bias,因為:
而 (n-1)/n * σ² != σ² ,所以,為了避免使用有 bias 的 estimator,我們通常使用它的修正值 S²:
上面有答案解釋得很明確,即樣本方差計算公式里分母為的目的是為了讓方差的估計是無偏的。無偏的估計(unbiased estimator)比有偏估計(biased estimator)更好是符合直覺的,盡管有的統計學家認為讓mean square error即MSE最小才更有意義,這個問題我們不在這里探討;不符合直覺的是,為什么分母必須得是
而不是
才能使得該估計無偏。我相信這是題主真正困惑的地方。
要回答這個問題,偷懶的辦法是讓困惑的題主去看下面這個等式的數學證明:.
但是這個答案顯然不夠直觀(教材里面統計學家像變魔法似的不知怎么就得到了上面這個等式)。
下面我將提供一個略微更友善一點的解釋。
==================================================================
===================== 答案的分割線 ===================================
==================================================================
首先,我們假定隨機變量的數學期望
是已知的,然而方差
未知。在這個條件下,根據方差的定義我們有
由此可得.
因此是方差
的一個無偏估計,注意式中的分母不偏不倚正好是
!
這個結果符合直覺,並且在數學上也是顯而易見的。
現在,我們考慮隨機變量的數學期望
是未知的情形。這時,我們會傾向於無腦直接用樣本均值
替換掉上面式子中的
。這樣做有什么后果呢?后果就是,
如果直接使用作為估計,那么你會傾向於低估方差!
這是因為:
換言之,除非正好,否則我們一定有
,
而不等式右邊的那位才是的對方差的“正確”估計!
這個不等式說明了,為什么直接使用會導致對方差的低估。
那么,在不知道隨機變量真實數學期望的前提下,如何“正確”的估計方差呢?答案是把上式中的分母換成
,通過這種方法把原來的偏小的估計“放大”一點點,我們就能獲得對方差的正確估計了:
至於為什么分母是而不是
或者別的什么數,最好還是去看真正的數學證明,因為數學證明的根本目的就是告訴人們“為什么”;暫時我沒有辦法給出更“初等”的解釋了。
樣本方差與樣本均值,都是隨機變量,都有自己的分布,也都可能有自己的期望與方差。取分母n-1,可使樣本方差的期望等於總體方差,即這種定義的樣本方差是總體方差的無偏估計。 簡單理解,因為算方差用到了均值,所以自由度就少了1,自然就是除以(n-1)了。
再不能理解的話,形象一點,對於樣本方差來說,假如從總體中只取一個樣本,即n=1,那么樣本方差公式的分子分母都為0,方差完全不確定。這個好理解,因為樣本方差是用來估計總體中個體之間的變化大小,只拿到一個個體,當然完全看不出變化大小。反之,如果公式的分母不是n-1而是n,計算出的方差就是0——這是不合理的,因為不能只看到一個個體就斷定總體的個體之間變化大小為0。
我不知道是不是說清楚了,詳細的推導相關書上有,可以查閱。
因為樣本均值與實際均值有差別。
如果分母用n,樣本估計出的就方差會小於真實方差。
維基上有具體計算過程:
http://en.wikipedia.org/wiki/Unbiased_estimator#Sample_variance
Sample variance[edit]
The sample variance of a random variable demonstrates two aspects of estimator bias: firstly, the naive estimator is biased, which can be corrected by a scale factor; second, the unbiased estimator is not optimal in terms of mean squared error (MSE), which can be minimized by using a different scale factor, resulting in a biased estimator with lower MSE than the unbiased estimator. Concretely, the naive estimator sums the squared deviations and divides by n, which is biased. Dividing instead by n − 1 yields an unbiased estimator. Conversely, MSE can be minimized by dividing by a different number (depending on distribution), but this results in a biased estimator. This number is always larger than n − 1, so this is known as a shrinkage estimator, as it "shrinks" the unbiased estimator towards zero; for the normal distribution the optimal value is n + 1.
Suppose X1, ..., Xn are independent and identically distributed (i.i.d.) random variables with expectation μ and variance σ2. If the sample mean and uncorrected sample variance are defined as
then S2 is a biased estimator of σ2, because
In other words, the expected value of the uncorrected sample variance does not equal the population variance σ2, unless multiplied by a normalization factor. The sample mean, on the other hand, is an unbiased[1] estimator of the population mean μ.
The reason that S2 is biased stems from the fact that the sample mean is an ordinary least squares (OLS) estimator for μ: is the number that makes the sum
as small as possible. That is, when any other number is plugged into this sum, the sum can only increase. In particular, the choice
gives,
and then
Note that the usual definition of sample variance is
and this is an unbiased estimator of the population variance. This can be seen by noting the following formula, which follows from the Bienaymé formula, for the term in the inequality for the expectation of the uncorrected sample variance above:
The ratio between the biased (uncorrected) and unbiased estimates of the variance is known as Bessel's correction.