From e4861e7b50e432a40d4161d6d8f37095fb817e8c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 19 Jun 2025 22:24:50 +0100 Subject: [PATCH] Hotelling T2 p-value --- lib/LatAnalyze/Core/Math.cpp | 12 ++++++++++++ lib/LatAnalyze/Core/Math.hpp | 1 + 2 files changed, 13 insertions(+) diff --git a/lib/LatAnalyze/Core/Math.cpp b/lib/LatAnalyze/Core/Math.cpp index 16ab66d..bef4040 100644 --- a/lib/LatAnalyze/Core/Math.cpp +++ b/lib/LatAnalyze/Core/Math.cpp @@ -166,5 +166,17 @@ auto chi2CcdfVecFunc = [](const double arg[2]) return gsl_cdf_chisq_Q(arg[0], arg[1]); }; +auto hotellingT2PValueVecFunc = [](const double arg[3]) +{ + double T2 = arg[0]; + double n = arg[1]; + double p = arg[2]; + double F = (n - p) / (p * (n - 1)) * T2; + double p_value = 1.0 - gsl_cdf_fdist_P(F, p, n - p); + + return p_value; +}; + DoubleFunction MATH_NAMESPACE::chi2PValue(chi2PValueVecFunc, 2); DoubleFunction MATH_NAMESPACE::chi2Ccdf(chi2CcdfVecFunc, 2); +DoubleFunction MATH_NAMESPACE::hotellingT2PValue(hotellingT2PValueVecFunc, 3); diff --git a/lib/LatAnalyze/Core/Math.hpp b/lib/LatAnalyze/Core/Math.hpp index 7ad4ad1..a11ed7b 100644 --- a/lib/LatAnalyze/Core/Math.hpp +++ b/lib/LatAnalyze/Core/Math.hpp @@ -160,6 +160,7 @@ namespace MATH_NAMESPACE { extern DoubleFunction chi2PValue; extern DoubleFunction chi2Ccdf; + extern DoubleFunction hotellingT2PValue; } END_LATAN_NAMESPACE