![]() |
Home | Libraries | People | FAQ | More |
#include <boost/math/distributions/chi_squared.hpp>
namespace boost{ namespace math{ template <class RealType = double, class Policy = policies::policy<> > class chi_squared_distribution; typedef chi_squared_distribution<> chi_squared; template <class RealType, class Policy> class chi_squared_distribution { public: typedef RealType value_type; typedef Policy policy_type; // 構造函數: chi_squared_distribution(RealType i); // 參數訪問函數(Accessor to parameter): RealType degrees_of_freedom()const; // 參數估計(Parameter estimation): static RealType find_degrees_of_freedom( RealType difference_from_mean, RealType alpha, RealType beta, RealType sd, RealType hint = 100); }; }} // namespaces
χ方形分佈(Chi-Squared distribution)是統計測試中使用最廣泛的分佈之一。如果χi 是 ν 獨立的, 正態分佈隨機變量的均值(means)為 μi 且 方差(variances)為 σi2,那麼隨機變量:
按照χ方形分佈( Chi-Squared distribution )來進行分佈。
χ方形分佈( Chi-Squared distribution )是γ分佈(gamma distribution)的一個特例,並且有一個參數 ν 來指定自由度(degrees of freedom)。下面的圖像顯示了對於不同的ν值,分佈是如何改變的:
chi_squared_distribution(RealType v);
使用自由度ν來構造一個χ方形分佈( Chi-Squared distribution )。
要求 v > 0, 否則調用定義域錯誤。
RealType degrees_of_freedom()const;
返回構造這個分佈的參數v。
static RealType find_degrees_of_freedom( RealType difference_from_variance, RealType alpha, RealType beta, RealType variance, RealType hint = 100);
估算在針對相等的標準差進行的χ方形測試(Chi-Squared test)中檢測出與標稱方差( nominal variance)的差值所需要的樣本大小。
將要檢測的與假定的標稱方差(nominal variance)的差值:這個差值的符號很關鍵,參看下面。
當實際上為真的時候而否決虛假設(null hypothesis)的最大可接受風險(maximum acceptable risk)。
錯誤地否決虛假設(null hypothesis)的最大的可接受風險( maximum acceptable risk)。
進行測試的標稱方差(nominal variance)。
從哪裡開始查找結果的一個可選的提示值(optional hint):當前的樣本值是一個好的選擇 。
注意:這種計算使用方差(variances)而不是標準差( standard deviations)進行計算 。
參數difference_from_variance
的符號很重要:χ方形分佈(Chi Squared distribution)是非對稱的,而且調用者必須事先決定是否針對於方差(variance)大於標稱值( nominal value)進行測試(正的difference_from_variance)
或是 針對於方差(variance)小於標稱值( nominal value)進行測試(負的difference_from_variance)。如果是後者,那麼很明顯地,要求variance +
difference_from_variance >
0,因為沒有樣本可以有一個負的方差( negative
variance)!
這個計算過程使用Diamond, W. J. (1989). Practical Experiment Designs, Van-Nostrand Reinhold, New York中描述的方法。
參見the NIST Engineering Statistics Handbook, Section 7.2.3.2中關於樣本大小要求的章節。
支持所有的分佈都通用的 常見的非成員訪問函數 : 累積分佈函數(Cumulative Distribution Function),概率密度函數(Probability Density Function),分位點(Quantile), 故障率函數(Hazard Function), 累積危險函數(Cumulative Hazard Function), 均值(mean), 中位數(median), 眾數(mode), 方差(variance), 標準差(standard deviation), 偏斜(skewness), 峰態(kurtosis), 峰態超越(kurtosis_excess), 值域(range) 以及 支持(support)。
(我們遵循眾數(mode)的通常限制:自由度(degrees of freedom)>=2, 但請注意:對於自由度(degrees of freedom)從2到0,函數pdf的最大值為0,並且作為交錯代碼(alternative code),在註釋中提供了一個可以避免函數在眾數(mode)中不連續的擴展定義).
隨機變量的定義域為: [0, +∞]。
有多個可運行的例子 說明了如何使用χ方形分佈(Chi Squared Distribution)。
χ方形分佈(Chi-Squared distribution)使用不完全γ函數(incomplete gamma functions)來實現:請參考這些函數的精度信息。
在下面的表中:v 是分佈的自由度(degrees of freedom),x 是隨機變量,p 是概率, 且 q = 1-p。
|
函數 |
實現註解 |
|---|---|
|
|
使用關係:pdf = gamma_p_derivative(v / 2, x / 2) / 2 |
|
cdf |
使用關係: p = gamma_p(v / 2, x / 2) |
|
cdf 補集(complement) |
使用關係:q = gamma_q(v / 2, x / 2) |
|
分位點(quantile) |
使用關係:x = 2 * gamma_p_inv(v / 2, p) |
|
補集(complement)的分位點(quantile) |
Using the relation:使用關係: x = 2 * gamma_q_inv(v / 2, p) |
|
均值(mean) |
v |
|
方差(variance) |
2v |
|
眾數(mode) |
v - 2 (if v >= 2) |
|
偏斜(skewness) |
2 * sqrt(2 / v) == sqrt(8 / v) |
|
峰態(kurtosis) |
3 + 12 / v |
|
峰態超越(kurtosis excess ) |
12 / v |