Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
針對標準差的χ方形測試(Chi-Square Test for the Standard Deviation)

我們使用這個測試來判斷一個樣本的標準差是否與一個指定值有差別。典型情況下,在這種測試出現在過程改進(process change)中,當我們需要比較一個新過程的標準差與一個確定的過程的標準差。

這個例子的代碼包含在chi_square_std_dev_test.cpp中,我們從定義打印檢驗統計量(test statistics)的函數開始:

void chi_squared_test(
    double Sd,     // 樣本標準差(Sample std deviation)
    double D,      // 真實標準差(True std deviation)
    unsigned N,    // 樣本大小(Sample size)
    double alpha)  // 顯著水平(Significance level)
{

這個函數以打印輸入數據的摘要(summary)開始:

using namespace std;
using namespace boost::math;

// 打印消息頭部:
cout <<
   "______________________________________________\n"
   "Chi Squared test for sample standard deviation\n"
   "______________________________________________\n\n";
cout << setprecision(5);
cout << setw(55) << left << "Number of Observations" << "=  " << N << "\n";
cout << setw(55) << left << "Sample Standard Deviation" << "=  " << Sd << "\n";
cout << setw(55) << left << "Expected True Standard Deviation" << "=  " << D << "\n\n";

檢驗統計量(test statistic) (T) 樣本標準差的平方與「真實」標準差的平方的比值,乘以自由度(degree of freedom)(比樣本大小少1):

double t_stat = (N - 1) * (Sd / D) * (Sd / D);
cout << setw(55) << left << "Test Statistic" << "=  " << t_stat << "\n";

我們需要使用的分佈是自由度(degree of freedom)為N-1的χ方形分佈( Chi Squared distribution) :

chi_squared dist(N - 1);

可以進行測試的不同假設都歸納在下面的表中:

假設(Hypothesis)

測試(Test)

虛假設(null-hypothesis):標準差與指定值沒有差別

如果T < χ2(1-alpha/2; N-1) 或 T > χ2(alpha/2; N-1) 則否決

另一個假設( hypothesis): 標準差與指定值有差別

如果χ2(1-alpha/2; N-1) >= T >= χ2(alpha/2; N-1) 則否決

另一個假設(hypothesis):標準差小於指定值

如果χ2(1-alpha; N-1) <= T 則否決

另一個假設(hypothesis):標準差大於指定值

如果χ2(alpha; N-1) >= T 則否決

其中χ2(alpha; N-1) 是方形分佈(Chi Squared distribution)的上臨界值(upper critical value),且χ2(1-alpha; N-1) 是下臨界值( lower critical value)。

回憶一下:下臨界值( lower critical value)與分位點(quantile)是相同的,而上臨界值(upper cirtical value)與概率補集的分位點(quantile from the complement of the probability)是相同的,這就給出下面的計算臨界值(critical value)的方法:

double ucv = quantile(complement(dist, alpha));
double ucv2 = quantile(complement(dist, alpha / 2));
double lcv = quantile(dist, alpha);
double lcv2 = quantile(dist, alpha / 2);
cout << setw(55) << left << "Upper Critical Value at alpha: " << "=  "
   << setprecision(3) << scientific << ucv << "\n";
cout << setw(55) << left << "Upper Critical Value at alpha/2: " << "=  "
   << setprecision(3) << scientific << ucv2 << "\n";
cout << setw(55) << left << "Lower Critical Value at alpha: " << "=  "
   << setprecision(3) << scientific << lcv << "\n";
cout << setw(55) << left << "Lower Critical Value at alpha/2: " << "=  "
   << setprecision(3) << scientific << lcv2 << "\n\n";

現在我們有了臨界值(critival value),我們可以與檢驗統計量(test statistic)進行比較,並打印每個假設和測試的結果:

cout << setw(55) << left <<
   "Results for Alternative Hypothesis and alpha" << "=  "
   << setprecision(4) << fixed << alpha << "\n\n";
cout << "Alternative Hypothesis              Conclusion\n";

cout << "Standard Deviation != " << setprecision(3) << fixed << D << "            ";
if((ucv2 < t_stat) || (lcv2 > t_stat))
   cout << "ACCEPTED\n";
else
   cout << "REJECTED\n";

cout << "Standard Deviation  < " << setprecision(3) << fixed << D << "            ";
if(lcv > t_stat)
   cout << "ACCEPTED\n";
else
   cout << "REJECTED\n";

cout << "Standard Deviation  > " << setprecision(3) << fixed << D << "            ";
if(ucv < t_stat)
   cout << "ACCEPTED\n";
else
   cout << "REJECTED\n";
cout << endl << endl;

為了查看一些樣本輸出,我們使用來自於NIST/SEMATECH e-Handbook of Statistical Methods.gear data ,這些數據表示來自於一個製造過程(manufacturing process)中測量的齒輪直徑( gear diameter)。這個程序的輸出有意地設計為NIST Handbook Example中所顯示的DATAPLOT數據格式:

______________________________________________
Chi Squared test for sample standard deviation
______________________________________________

Number of Observations                                 =  100
Sample Standard Deviation                              =  0.00628
Expected True Standard Deviation                       =  0.10000

Test Statistic                                         =  0.39030
CDF of test statistic:                                 =  1.438e-099
Upper Critical Value at alpha:                         =  1.232e+002
Upper Critical Value at alpha/2:                       =  1.284e+002
Lower Critical Value at alpha:                         =  7.705e+001
Lower Critical Value at alpha/2:                       =  7.336e+001

Results for Alternative Hypothesis and alpha           =  0.0500

Alternative Hypothesis              Conclusion
Standard Deviation != 0.100            ACCEPTED
Standard Deviation  < 0.100            ACCEPTED
Standard Deviation  > 0.100            REJECTED

在這種情況下,我們測試樣本標準差是否為0.1,並且虛假設(null-hypothesis)被否決了,因此我們可以判定標準差不為0.1。

作為另一個例子,考慮來自於NIST/SEMATECH e-Handbook of Statistical Methods.的.silicon wafer data 。 在這個例子中,一個100 ohm.cm硅圓片(silicon wafer)的供應商聲稱它的製造過程可以生產足夠相容性(consistency)的圓硅片(wafer silicon),使得一批產品的電阻率(resistivity)的標準差不超過10 ohm.cm。一個數量為N=10的樣本硅片從標準差為13.97的一批產器中取得。現在的問題是「這個供應商的聲稱是正確的嗎?」。

現在這個程序的輸出是這樣的:

______________________________________________
Chi Squared test for sample standard deviation
______________________________________________

Number of Observations                                 =  10
Sample Standard Deviation                              =  13.97000
Expected True Standard Deviation                       =  10.00000

Test Statistic                                         =  17.56448
CDF of test statistic:                                 =  9.594e-001
Upper Critical Value at alpha:                         =  1.692e+001
Upper Critical Value at alpha/2:                       =  1.902e+001
Lower Critical Value at alpha:                         =  3.325e+000
Lower Critical Value at alpha/2:                       =  2.700e+000

Results for Alternative Hypothesis and alpha           =  0.0500

Alternative Hypothesis              Conclusion
Standard Deviation != 10.000            REJECTED
Standard Deviation  < 10.000            REJECTED
Standard Deviation  > 10.000            ACCEPTED

在這種情況下,我們的虛假設(null-hypothesis)是樣本的標準差小於10:在上面的分析中,這個假設被否決了,所以, 我們否決了這個供應商的關於硅片質量的聲明。


PrevUpHomeNext