StatsTtest
Namespace: STSLIB · Library: Statistics Library
#include <sts/sts_ttest.h>
class STSLIB::StatsTtest
Provides t-test implementations: one-sample, paired, and independent two-sample.
One-sample, paired and independent two-sample Student t-tests with exact p-values via the regularised incomplete beta function.
const StatsTtestResult oneSample = StatsTtest::oneSample(a); // H0: column mean = 0
const StatsTtestResult paired = StatsTtest::paired(a, b); // H0: mean(a - b) = 0
const StatsTtestResult independent = StatsTtest::independent(a, b); // pooled variance, df = 10
const StatsTtestResult rightTail = StatsTtest::oneSample(a, 0.0, StatsTailType::Right);
Static Methods
oneSample(data, mu, tail)
One-sample t-test.
Each column of data is tested against mu.
Parameters:
-
data : const Eigen::MatrixXd & Matrix of observations (rows = observations, cols = variables).
-
mu : double Hypothesized mean (default 0.0).
-
tail : StatsTailType Tail type for the test.
Returns:
- StatsTtestResult —
StatsTtestResultwith t-statistics, p-values, and degrees of freedom.
paired(dataA, dataB, tail)
Paired t-test.
Tests dataA - dataB against 0.
Parameters:
-
dataA : const Eigen::MatrixXd & Matrix of observations for condition A.
-
dataB : const Eigen::MatrixXd & Matrix of observations for condition B (same dimensions as dataA).
-
tail : StatsTailType Tail type for the test.
Returns:
- StatsTtestResult —
StatsTtestResultwith t-statistics, p-values, and degrees of freedom.
independent(dataA, dataB, tail)
Independent two-sample t-test.
Parameters:
-
dataA : const Eigen::MatrixXd & Matrix of observations for group A (rows = observations, cols = variables).
-
dataB : const Eigen::MatrixXd & Matrix of observations for group B (same number of columns as dataA).
-
tail : StatsTailType Tail type for the test.
Returns:
- StatsTtestResult —
StatsTtestResultwith t-statistics, p-values, and degrees of freedom.
permutation(data, nPermutations, tail, seed)
One-sample sign-flip permutation t-test with max-statistic correction, as mne.stats.permutation_t_test.
Every column is tested against 0; the p-values compare each t with the distribution of the maximum |t| over all columns.
Parameters:
-
data : const Eigen::MatrixXd & Observations (rows = samples, cols = tests).
-
nPermutations : int Number of permutations including the observed data; when it exceeds the number of distinct sign flips, all of them are used (exact test).
-
tail : StatsTailType Tail type for the test.
-
seed : unsigned int Seed for the random subset of sign flips.
Returns:
- StatsTtestResult —
StatsTtestResultwith t-statistics (1 x n_tests), corrected p-values and n - 1 degrees of freedom.
tCdf(t, df)
Compute the CDF of the t-distribution using the regularized incomplete beta function.
Parameters:
-
t : double The t-value.
-
df : int Degrees of freedom.
Returns:
- double — The probability P(T <= t).
regularizedBeta(x, a, b)
Regularized incomplete beta function I_x(a, b).
Public because it is also used by StatsFtest.
Parameters:
-
x : double Upper integration limit in [0, 1].
-
a : double First shape parameter (positive).
-
b : double Second shape parameter (positive).
Returns:
- double — I_x(a, b) in [0, 1]; 0 for x at or below 0 and 1 for x at or above 1.
Example
- Full source:
src/examples/ex_sts_statistics/main.cpp - Build target:
ex_sts_statistics(runs under CTest)
Used in examples
ex_sts_statistics
Statistics library on small literal data sets with known answers.
const StatsTtestResult oneSample = StatsTtest::oneSample(a); // H0: column mean = 0
const StatsTtestResult paired = StatsTtest::paired(a, b); // H0: mean(a - b) = 0
const StatsTtestResult independent = StatsTtest::independent(a, b); // pooled variance, df = 10
const StatsTtestResult rightTail = StatsTtest::oneSample(a, 0.0, StatsTailType::Right);
// scipy.stats.ttest_1samp / ttest_rel / ttest_ind
ok &= expectRow(oneSample.matTstat, {10.285912696499036, 0.24544034683690788, -0.12327841818038444}, 1e-10, "one-sample t = scipy");
ok &= expectRow(oneSample.matPval, {0.00014930867649425364, 0.8158714843641037, 0.9066888237538449}, 1e-10, "one-sample p = scipy");
ok &= expectRow(paired.matTstat, {26.0, 0.0, -0.7254762501100115}, 1e-10, "paired t = scipy");
ok &= expectRow(paired.matPval, {1.5724552146685355e-06, 1.0, 0.5006803901900951}, 1e-10, "paired p = scipy");
ok &= expectRow(independent.matTstat, {5.918268896877812, 0.0, -0.34452048127477725}, 1e-10, "independent t = scipy");
ok &= expectRow(independent.matPval, {0.0001473880425533016, 1.0, 0.7375904333691938}, 1e-10, "independent p = scipy");
ok &= expect(oneSample.degreesOfFreedom == 5 && independent.degreesOfFreedom == 10, "df 5 and 10");
ok &= expect(std::fabs(rightTail.matPval(0, 0) - oneSample.matPval(0, 0) / 2.0) < 1e-12, "right-tailed p is half the two-tailed p");
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>