pairedTTest

fun pairedTTest(sample1: DoubleArray, sample2: DoubleArray, alternative: Alternative = Alternative.TWO_SIDED, confidenceLevel: Double = 0.95): TestResult(source)

Performs a paired t-test for whether the mean difference between matched observations is zero.

The null hypothesis is that the true mean difference between the paired observations is zero. Internally computes the element-wise differences and delegates to a one-sample t-test on those differences. This test is appropriate when the two samples are not independent — for example, before/after measurements on the same subjects.

Example:

val before = doubleArrayOf(200.0, 190.0, 210.0, 180.0, 195.0)
val after = doubleArrayOf(190.0, 180.0, 195.0, 170.0, 185.0)
val result = pairedTTest(before, after)
result.statistic // t-statistic
result.pValue // p-value
result.confidenceInterval // 95% CI for the mean difference

Return

a TestResult containing the t-statistic, p-value, degrees of freedom (n-1), and a confidence interval for the mean difference.

Parameters

sample1

the first set of observations (e.g. "before"). Must have at least 2 elements.

sample2

the second set of observations (e.g. "after"). Must have the same size as sample1.

alternative

the direction of the alternative hypothesis. Defaults to Alternative.TWO_SIDED, which tests whether the mean difference differs from zero in either direction.

confidenceLevel

the confidence level for the confidence interval. Defaults to 0.95 (95%).