39 const std::vector<double> &sample2) {
41 for (
double x1 : sample1) {
42 for (
double x2 : sample2) {
54 for (
const auto &value : data) {
57 return sum /
static_cast<double>(data.size());
63 for (
const auto &value : data) {
66 return std::pow(product, 1.0 /
static_cast<double>(data.size()));
73 for (
const auto &value : data) {
74 sum += std::pow(value, p);
76 return std::pow(sum /
static_cast<double>(data.size()), 1.0 / p);
83 for (
const auto &value : data) {
84 product *= std::pow(value, p);
86 return std::pow(product, 1.0 /
static_cast<double>(data.size()));
92 for (
const auto &value : data) {
95 return static_cast<double>(data.size()) / sum;
100 double product = 1.0;
101 for (
const auto &value : data) {
102 product *= std::sqrt(value);
104 return std::pow(product, 2.0 /
static_cast<double>(data.size()));
110 for (
const auto &value : data) {
111 sum += value * std::log(value);
113 return std::exp(sum /
static_cast<double>(data.size()));
120 for (
const auto &value : data) {
121 sum += std::pow(value, p);
123 return sum /
static_cast<double>(data.size());
128 std::sort(data.begin(), data.end());
129 size_t size = data.size();
131 return (data[size / 2 - 1] + data[size / 2]) / 2.0;
133 return data[size / 2];
139 double mean = mean_arith(data);
141 for (
const auto &value : data) {
142 sum += std::abs(value - mean);
144 return sum /
static_cast<double>(data.size());
149 double mean = mean_arith(data);
150 double stddev = stdev(data, mean);
151 return (stddev / mean) * 100.0;
156 std::vector<double> sortedData = data;
157 std::sort(sortedData.begin(), sortedData.end());
159 size_t size = sortedData.size();
160 size_t lowerIndex = size / 4;
161 size_t upperIndex = 3 * size / 4;
163 return sortedData[upperIndex] - sortedData[lowerIndex];
169 std::vector<double> sortedData = data;
170 std::sort(sortedData.begin(), sortedData.end());
172 size_t size = sortedData.size();
173 size_t index =
static_cast<size_t>(percentile * (size - 1));
174 return sortedData[index];
179 auto result = std::minmax_element(data.begin(), data.end());
180 return *result.second - *result.first;
187 for (
const auto &value : data) {
188 sum += std::pow(value - mean, 2.0);
190 return std::sqrt(sum /
static_cast<double>(data.size()));
197 for (
const auto &value : data) {
198 sum += std::pow(value - mean, 2.0);
200 return sum /
static_cast<double>(data.size());
206 double mean = mean_arith(data);
207 double stddev = stdev(data, mean);
208 return stddev / std::sqrt(
static_cast<double>(numSamples));
215 for (
const auto &value : data) {
216 sum += std::pow(value - mean, 4.0);
218 double var = variance(data, mean);
219 return sum / (data.size() * std::pow(var, 2.0)) - 3.0;
226 for (
const auto &value : data) {
227 sum += std::pow(value - mean, 3.0);
229 return sum / data.size();
235 for (
const auto &value : data) {
236 sum += std::pow(value - mean, 4.0);
238 return sum / data.size();
246 for (
const auto &value : data) {
247 sum += std::pow((value - mean) / stddev, 3.0);
249 return sum /
static_cast<double>(data.size());
254 std::vector<size_t> ranks(data.size());
256 for (
size_t i = 0; i < data.size(); ++i) {
258 for (
size_t j = 0; j < data.size(); ++j) {
259 if (j != i && data[j] < data[i]) {
270 const std::vector<double> &y,
271 const std::vector<double> &z) {
272 double r_xy = ppmc(x, y);
273 double r_xz = ppmc(x, z);
274 double r_yz = ppmc(y, z);
276 return (r_xy - (r_xz * r_yz)) /
277 std::sqrt((1.0 - std::pow(r_xz, 2.0)) * (1.0 - std::pow(r_yz, 2.0)));
282 const std::vector<double> &y) {
283 double mean_x = mean_arith(x);
284 double mean_y = mean_arith(y);
286 double numerator = 0.0;
287 double denominator_x = 0.0;
288 double denominator_y = 0.0;
290 for (
size_t i = 0; i < x.size(); ++i) {
291 numerator += (x[i] - mean_x) * (y[i] - mean_y);
292 denominator_x += std::pow(x[i] - mean_x, 2.0);
293 denominator_y += std::pow(y[i] - mean_y, 2.0);
296 return numerator / std::sqrt(denominator_x * denominator_y);
301 const std::vector<double> &y) {
302 size_t concordant = 0;
303 size_t discordant = 0;
305 for (
size_t i = 0; i < x.size() - 1; ++i) {
306 for (
size_t j = i + 1; j < x.size(); ++j) {
307 if ((x[i] < x[j] && y[i] < y[j]) || (x[i] > x[j] && y[i] > y[j])) {
309 }
else if ((x[i] < x[j] && y[i] > y[j]) ||
310 (x[i] > x[j] && y[i] < y[j])) {
316 return static_cast<double>(concordant - discordant) /
317 std::sqrt(
static_cast<double>((concordant + discordant) *
318 (x.size() * (x.size() - 1)) / 2));
323 const std::vector<double> &y) {
324 std::vector<size_t> ranks_x = rank_data(x);
325 std::vector<size_t> ranks_y = rank_data(y);
327 double d_squared = 0.0;
328 for (
size_t i = 0; i < x.size(); ++i) {
329 d_squared += std::pow(ranks_x[i] - ranks_y[i], 2.0);
333 (6.0 * d_squared) / (x.size() * (std::pow(x.size(), 2.0) - 1.0));
static double u_stat(const std::vector< double > &sample1, const std::vector< double > &sample2)
Calculates U statistic given two samples.
double kurtosis(const std::vector< double > &data, double mean)
Calculates the kurtosis of a given dataset.
static double stdev(const std::vector< double > &data, double mean)
Calculates the standard deviation of a given dataset, given the mean.
double lmoment2(const std::vector< double > &data, double mean)
Calculates the second L-moment of a given dataset.
double kendalls_tau(const std::vector< double > &x, const std::vector< double > &y)
Calculates Kendall's Tau Rank Correlation between two variables.
double lmoment1(const std::vector< double > &data, double mean)
Calculates the first L-moment of a given dataset.
double clt(const std::vector< double > &data, int numSamples)
Calculates the standard error of the mean using the Central Limit Theorem.
double spearmans_rho(const std::vector< double > &x, const std::vector< double > &y)
Calculates Spearman's Rank Correlation between two variables.
static double variance(const std::vector< double > &data, double mean)
Calculates the variance of a given dataset, given the mean.
double mean_lehmer(const std::vector< double > &data, double p)
Calculates the Lehmer mean of a given dataset with a specified power.
double Median(std::vector< double > data)
Calculates the median of a given dataset.
double mean_heronian(const std::vector< double > &data)
Calculates the Heronian mean of a given dataset.
static double mean_arith(const std::vector< double > &data)
Calculates the arithmetic mean of a given dataset.
double mean_geo_pow(const std::vector< double > &data, double p)
Calculates the power geometric mean of a given dataset with a specified power.
double percentile(const std::vector< double > &data, double percentile)
Calculates the specified percentile of a given dataset.
double partial_corr(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z)
Calculates the partial correlation coefficient between two variables, controlling for a third variabl...
double skewness(const std::vector< double > &data, double mean, double stddev)
Calculates the skewness of a given dataset.
double iq_range(const std::vector< double > &data)
Calculates the interquartile range of a given dataset.
std::vector< size_t > rank_data(const std::vector< double > &data)
Ranks the data in ascending order.
double mean_heinz(const std::vector< double > &data)
Calculates the Heinz mean of a given dataset.
double mean_cubic(const std::vector< double > &data, double p)
Calculates the cubic generalized mean of a given dataset with a specified power.
double var_coeff(const std::vector< double > &data)
Calculates the coefficient of variation of a given dataset.
double mean_harmonic(const std::vector< double > &data)
Calculates the harmonic mean of a given dataset.
double avg_abs_dev(const std::vector< double > &data)
Calculates the average absolute deviation of a given dataset.
double ppmc(const std::vector< double > &x, const std::vector< double > &y)
Calculates the Pearson Product-Moment Correlation between two variables.
double range(const std::vector< double > &data)
Calculates the range of a given dataset.
double mean_geo(const std::vector< double > &data)
Calculates the geometric mean of a given dataset.