Class TTest
java.lang.Object
cloud.opencode.base.math.stats.inference.TTest
Student's t-test implementations for hypothesis testing.
Student t 检验实现,用于假设检验
Provides one-sample, independent two-sample (Welch's), and paired t-tests.
All methods return a TestResult with two-tailed p-values.
提供单样本、独立双样本(Welch)和配对 t 检验。
所有方法返回包含双尾 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 TestResultoneSample(double[] data, double mu0) Performs a one-sample t-test (H0: population mean = mu0).static TestResultpaired(double[] x, double[] y) Performs a paired t-test (H0: mean difference = 0).static TestResulttwoSample(double[] x, double[] y) Performs an independent two-sample t-test using Welch's method (unequal variances).
-
Method Details
-
oneSample
Performs a one-sample t-test (H0: population mean = mu0). 执行单样本 t 检验(H0: 总体均值 = mu0)Computes t = (mean - mu0) / (s / sqrt(n)), df = n - 1, two-tailed p-value.
计算 t = (mean - mu0) / (s / sqrt(n)),df = n - 1,双尾 p 值。
- Parameters:
data- the sample data (at least 2 elements) / 样本数据(至少 2 个元素)mu0- the hypothesized population mean / 假设的总体均值- Returns:
- the test result / 检验结果
- Throws:
MathException- if data is null, has fewer than 2 elements, or contains NaN/Infinity
-
twoSample
Performs an independent two-sample t-test using Welch's method (unequal variances). 使用 Welch 方法执行独立双样本 t 检验(不等方差)Computes t = (meanX - meanY) / sqrt(sX^2/nX + sY^2/nY), with Welch-Satterthwaite degrees of freedom approximation.
计算 t = (meanX - meanY) / sqrt(sX^2/nX + sY^2/nY), 使用 Welch-Satterthwaite 自由度近似。
- Parameters:
x- first sample data (at least 2 elements) / 第一组样本数据(至少 2 个元素)y- second sample data (at least 2 elements) / 第二组样本数据(至少 2 个元素)- Returns:
- the test result / 检验结果
- Throws:
MathException- if data is null, has fewer than 2 elements, or contains NaN/Infinity
-
paired
Performs a paired t-test (H0: mean difference = 0). 执行配对 t 检验(H0: 平均差值 = 0)Computes differences d = x - y, then performs a one-sample t-test on d with mu0 = 0.
计算差值 d = x - y,然后对 d 执行 mu0 = 0 的单样本 t 检验。
- Parameters:
x- first sample data / 第一组样本数据y- second sample data (same length as x) / 第二组样本数据(与 x 等长)- Returns:
- the test result / 检验结果
- Throws:
MathException- if arrays are null, different lengths, have fewer than 2 elements, or contain NaN/Infinity
-