diff --git a/math/src/main/scala/breeze/stats/hypothesis/package.scala b/math/src/main/scala/breeze/stats/hypothesis/package.scala index 6a7843d3d..508df9c9c 100644 --- a/math/src/main/scala/breeze/stats/hypothesis/package.scala +++ b/math/src/main/scala/breeze/stats/hypothesis/package.scala @@ -31,7 +31,7 @@ package object hypothesis { val tScore = (mu1 - mu2) / sqrt((var1 / n1) + (var2 / n2)) // T statistic val dof = pow((var1 / n1) + (var2 / n2), 2) / (pow(var1, 2) / (pow(n1, 2) * (n1 - 1)) + pow(var2, 2) / (pow(n2, 2) * (n2 - 1))) //Welch–Satterthwaite equation - new StudentsT(dof)(RandBasis.mt0).unnormalizedPdf(tScore) //return p value + new StudentsT(dof)(RandBasis.mt0).cdf(tScore) //return p value } def tTest[T](it1: Traversable[T])(implicit numeric: Numeric[T]): Double = @@ -40,7 +40,7 @@ package object hypothesis { val MeanAndVariance(mu1, var1, n1) = meanAndVariance(it1) val Z = mu1 / sqrt(var1 / n1) val dof = n1 - 1 - new StudentsT(dof)(RandBasis.mt0).unnormalizedPdf(Z) //return p value + new StudentsT(dof)(RandBasis.mt0).cdf(Z) //return p value } case class Chi2Result(chi2: Double, pVal: Double) diff --git a/math/src/test/scala/breeze/stats/hypothesis/TTestTest.scala b/math/src/test/scala/breeze/stats/hypothesis/TTestTest.scala index 28355f965..dd32b04e6 100644 --- a/math/src/test/scala/breeze/stats/hypothesis/TTestTest.scala +++ b/math/src/test/scala/breeze/stats/hypothesis/TTestTest.scala @@ -7,14 +7,14 @@ import matchers.should.Matchers._ class TTestTest extends AnyFunSuite { val threshold = 0.01 test("T Test two sample") { - tTest(List(1.0, 1, 2, 3), List(9.0, 9, 8, 9)) should be(4.29E-5 +- threshold) + tTest(List(1.0, 1, 2, 3), List(9.0, 9, 8, 9)) should be(4.752E-5 +- threshold) } test("T Test one sample") { - tTest(Array(1.0, 1, 2, 3)) should be(0.0336 +- threshold) + tTest(Array(1.0, 1, 2, 3)) should be(0.982 +- threshold) } test("T Test one sample for Traversable") { //This test is designed to detect this bug, just in case a refactoring re-introduces it: https://github.com/scalanlp/breeze/issues/486 - tTest(List(1.0, 1, 2, 3)) should be(0.0336 +- threshold) + tTest(List(1.0, 1, 2, 3)) should be(0.982323 +- threshold) } test("T Test one sample should throw error when given vector of length 1") { intercept[IllegalArgumentException] {