9 #include "wdm/bbeta.hpp"
10 #include "wdm/cxi.hpp"
11 #include "wdm/hoeffd.hpp"
12 #include "wdm/ktau.hpp"
13 #include "wdm/methods.hpp"
14 #include "wdm/nan_handling.hpp"
15 #include "wdm/prho.hpp"
16 #include "wdm/srho.hpp"
49 wdm(std::vector<double> x,
50 std::vector<double> y,
52 std::vector<double> weights = std::vector<double>(),
53 bool remove_missing =
true,
54 std::vector<int> seeds = std::vector<int>())
56 utils::check_sizes(x, y, weights);
58 if (utils::preproc(x, y, weights, method, remove_missing) ==
"return_nan")
59 return std::numeric_limits<double>::quiet_NaN();
61 if (methods::is_hoeffding(method))
62 return impl::hoeffd(x, y, weights);
63 if (methods::is_kendall(method))
64 return impl::ktau(x, y, weights);
65 if (methods::is_pearson(method))
66 return impl::prho(x, y, weights);
67 if (methods::is_spearman(method))
68 return impl::srho(x, y, weights);
69 if (methods::is_blomqvist(method))
70 return impl::bbeta(x, y, weights);
71 if (methods::is_chatterjee(method)) {
72 auto xi_and_std = impl::cxi(x, y, weights,
false,
"max", seeds);
73 return std::get<0>(xi_and_std);
75 throw std::runtime_error(
"method not implemented.");
132 std::vector<double> y,
134 std::vector<double> weights = std::vector<double>(),
135 bool remove_missing =
true,
137 std::vector<int> seeds = std::vector<int>(),
138 bool y_continuous =
true)
142 utils::check_sizes(x, y, weights);
143 if (utils::preproc(x, y, weights,
method, remove_missing) ==
"return_nan") {
144 n_eff_ = utils::effective_sample_size(x.size(), weights);
145 estimate_ = std::numeric_limits<double>::quiet_NaN();
146 statistic_ = std::numeric_limits<double>::quiet_NaN();
147 p_value_ = std::numeric_limits<double>::quiet_NaN();
149 n_eff_ = utils::effective_sample_size(x.size(), weights);
150 if (methods::is_chatterjee(
method)) {
151 auto stats = impl::cxi(x, y, weights,
true,
"max", seeds, y_continuous);
152 estimate_ = std::get<0>(stats);
154 (std::get<3>(stats) - std::get<2>(stats)) / std::get<1>(stats);
156 estimate_ =
wdm(x, y,
method, weights,
false);
158 compute_test_stat(estimate_,
method, n_eff_, x, y, weights);
165 std::string
method()
const {
return method_; }
171 double n_eff()
const {
return n_eff_; }
183 inline double compute_test_stat(
double estimate,
186 const std::vector<double>& x,
187 const std::vector<double>& y,
188 const std::vector<double>& weights)
197 if (methods::is_hoeffding(
method)) {
199 }
else if (methods::is_kendall(
method)) {
200 stat =
estimate * impl::ktau_stat_adjust(x, y, weights);
201 }
else if (methods::is_pearson(
method)) {
203 }
else if (methods::is_spearman(
method)) {
205 }
else if (methods::is_blomqvist(
method)) {
208 throw std::runtime_error(
"method not implemented.");
214 inline double compute_p_value(
double statistic,
220 if (methods::is_hoeffding(
method)) {
222 throw std::runtime_error(
"must provide n_eff for method 'hoeffd'.");
224 throw std::runtime_error(
225 "only two-sided test available for Hoeffding's D.");
235 throw std::runtime_error(
"alternative not implemented.");
243 std::string alternative_;
double p_value() const
Returns the asymptotic p-value.
Definition: wdm.hpp:180
Indep_test(std::vector< double > x, std::vector< double > y, std::string method, std::vector< double > weights=std::vector< double >(), bool remove_missing=true, std::string alternative="two-sided", std::vector< int > seeds=std::vector< int >(), bool y_continuous=true)
Definition: wdm.hpp:131
std::string method() const
Returns the requested method name.
Definition: wdm.hpp:165
double estimate() const
Returns the estimated dependence measure.
Definition: wdm.hpp:174
double statistic() const
Returns the method-specific transformed test statistic.
Definition: wdm.hpp:177
double n_eff() const
Returns Kish's effective sample size after missing-value removal.
Definition: wdm.hpp:171
std::string alternative() const
Returns the requested alternative hypothesis.
Definition: wdm.hpp:168
Weighted dependence measures.
Definition: wdm.hpp:19
double wdm(std::vector< double > x, std::vector< double > y, std::string method, std::vector< double > weights=std::vector< double >(), bool remove_missing=true, std::vector< int > seeds=std::vector< int >())
Definition: wdm.hpp:49