15 inline void normalize_weights(std::vector<double>& w)
18 double s = utils::sum(w);
19 for (
size_t i = 0; i < w.size(); i++)
27 inline double ktau(std::vector<double> x,
28 std::vector<double> y,
29 std::vector<double> weights = std::vector<double>())
31 utils::check_sizes(x, y, weights);
34 utils::sort_all(x, y, weights);
37 double ties_x = utils::count_tied_pairs(x, weights);
38 double ties_both = utils::count_joint_ties(x, y, weights);
42 utils::merge_sort(y, weights, num_d);
45 double ties_y = utils::count_tied_pairs(y, weights);
48 if (weights.size() == 0)
49 weights = std::vector<double>(x.size(), 1.0);
50 double num_pairs = utils::perm_sum(weights, 2);
51 double num_c = num_pairs - (num_d + ties_x + ties_y - ties_both);
52 double tau = num_c - num_d;
53 tau /= std::sqrt((num_pairs - ties_x) * (num_pairs - ties_y));
59 inline double ktau_stat_adjust(
60 std::vector<double> x,
61 std::vector<double> y,
62 std::vector<double> weights)
64 utils::check_sizes(x, y, weights);
67 utils::sort_all(x, y, weights);
70 double pair_x = utils::count_tied_pairs(x, weights);
71 double trip_x = utils::count_tied_triplets(x, weights);
72 double v_x = utils::count_ties_v(x, weights);
75 utils::sort_all(y, x, weights);
78 double pair_y = utils::count_tied_pairs(y, weights);
79 double trip_y = utils::count_tied_triplets(y, weights);
80 double v_y = utils::count_ties_v(y, weights);
83 if (weights.size() == 0)
84 weights = std::vector<double>(x.size(), 1.0);
85 double s = utils::sum(weights);
86 double s2 = utils::perm_sum(weights, 2);
87 double s3 = utils::perm_sum(weights, 3);
88 double r = s / utils::sum(utils::pow(weights, 2));
89 double v_0 = 2 * s2 * (2 * s) * std::pow(r, 3);
90 double v_1 = 2 * pair_x * 2 * pair_y / (2 * 2 * s2) * std::pow(r, 2);
91 double v_2 = 6 * trip_x * 6 * trip_y / (9 * 6 * s3) * std::pow(r, 3);
92 double v = (v_0 - std::pow(r, 3) * (v_x - v_y)) / 18 + (v_1 + v_2);
93 return std::pow(r, 2) * std::sqrt((s2 - pair_x) * (s2 - pair_y) / v);
Weighted dependence measures.
Definition: bbeta.hpp:11