8 #include "Pandora/PandoraInternal.h" 17 const T &
t1,
const T &t2, std::mt19937 &randomNumberGenerator,
const unsigned int nPermutations)
19 if (1 > nPermutations)
20 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
24 unsigned int nExtreme(0);
25 for (
unsigned int iPermutation = 0; iPermutation < nPermutations; ++iPermutation)
31 if ((rRandomised - rNominal) > std::numeric_limits<float>::epsilon())
35 return static_cast<float>(nExtreme) / static_cast<float>(nPermutations);
42 const T &
t1,
const T &t2,
const unsigned int nIntegrationSteps,
const float upperLimit)
48 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
50 const float tTestStatisticDenominator(1.
f - correlation - correlation);
52 if (tTestStatisticDenominator < std::numeric_limits<float>::epsilon())
53 throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
55 const float tTestStatistic(correlation * std::sqrt(dof) / (std::sqrt(tTestStatisticDenominator)));
56 const float tDistCoeff(std::tgamma(0.5
f * (dof + 1.
f)) / std::tgamma(0.5
f * dof) / (std::sqrt(dof *
M_PI)));
58 const float dx((upperLimit - tTestStatistic) / static_cast<float>(nIntegrationSteps));
59 float integral(tDistCoeff *
std::pow(1.
f + tTestStatistic * tTestStatistic / dof, -0.5
f * (dof + 1.
f)) +
60 tDistCoeff *
std::pow(1.
f + upperLimit * upperLimit / dof, -0.5
f * (dof + 1.
f)));
61 for (
unsigned int iStep = 1; iStep < nIntegrationSteps; ++iStep)
63 integral += 2.f * tDistCoeff *
64 std::pow(1.
f + (tTestStatistic + static_cast<float>(iStep) * dx) * (tTestStatistic + static_cast<float>(iStep) * dx) / dof,
68 return integral * dx / 2.f;
79 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
82 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
87 float variance1(0.
f), variance2(0.
f), covariance(0.
f);
89 for (
unsigned int iElement = 0; iElement < size1; ++iElement)
94 variance1 += diff1 * diff1;
95 variance2 += diff2 * diff2;
96 covariance += diff1 * diff2;
99 if (variance1 < std::numeric_limits<float>::epsilon() || variance2 < std::numeric_limits<float>::epsilon())
100 throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
102 const float sqrtVars(std::sqrt(variance1 * variance2));
103 if (sqrtVars < std::numeric_limits<float>::epsilon())
104 throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
106 return covariance / sqrtVars;
111 template <
typename T>
116 throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_INITIALIZED);
119 for (
unsigned int iElement = 0; iElement <
size; ++iElement)
122 return mean /
static_cast<float>(
size);
DiscreteProbabilityVector class.
static float CalculateCorrelationCoefficientPValueFromPermutationTest(const T &t1, const T &t2, std::mt19937 &randomNumberGenerator, const unsigned int nPermutations)
Calculate P value for measured correlation coefficient between two datasets via a permutation test...
static float CalculateCorrelationCoefficientPValueFromStudentTDistribution(const T &t1, const T &t2, const unsigned int nIntegrationSteps, const float upperLimit)
Calculate P value for measured correlation coefficient between two datasets via a integrating the stu...
static float CalculateCorrelationCoefficient(const T &t1, const T &t2)
Calculate the correlation coefficient between two datasets.
Header file for the discrete probability helper class.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
static T MakeRandomisedSample(const T &t, std::mt19937 &randomNumberGenerator)
Make a randomised copy of a dataset.
static unsigned int GetSize(const T &t)
Get the size the size of a dataset.
static float CalculateMean(const T &t)
Calculate the mean of a dataset.
static float GetElement(const T &t, const unsigned int index)
Get an element in a dataset.
Dft::FloatVector FloatVector
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)