Class ChiSquareTest
java.lang.Object
cloud.opencode.base.math.stats.inference.ChiSquareTest
Chi-squared test implementations for hypothesis testing.
卡方检验实现,用于假设检验
Provides goodness-of-fit and independence tests.
All methods return a TestResult with p-values computed from the chi-squared distribution.
提供拟合优度检验和独立性检验。
所有方法返回从卡方分布计算 p 值的 TestResult。
All methods are stateless and thread-safe.
所有方法无状态且线程安全。
- Since:
- JDK 25, opencode-base-math V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic TestResultgoodnessOfFit(double[] observed, double[] expected) Performs a chi-squared goodness-of-fit test.static TestResultindependence(double[][] contingencyTable) Performs a chi-squared test of independence on a contingency table.
-
Method Details
-
goodnessOfFit
Performs a chi-squared goodness-of-fit test. 执行卡方拟合优度检验Tests whether observed frequencies differ significantly from expected frequencies. Statistic = sum((O - E)^2 / E), df = k - 1.
检验观察频率与期望频率是否存在显著差异。 统计量 = sum((O - E)^2 / E),df = k - 1。
- Parameters:
observed- the observed frequencies (must all be non-negative) / 观察频率(必须全部非负)expected- the expected frequencies (must all be positive) / 期望频率(必须全部为正)- Returns:
- the test result / 检验结果
- Throws:
MathException- if arrays are null, different lengths, fewer than 2 categories, or contain invalid values
-
independence
Performs a chi-squared test of independence on a contingency table. 对列联表执行卡方独立性检验Tests whether two categorical variables are independent. df = (rows - 1) * (cols - 1).
检验两个分类变量是否独立。 df = (rows - 1) * (cols - 1)。
- Parameters:
contingencyTable- the contingency table (at least 2x2, all values non-negative) / 列联表(至少 2x2,所有值非负)- Returns:
- the test result / 检验结果
- Throws:
MathException- if table is null, too small, jagged, or contains invalid values
-