21 remove_incomplete(std::vector<double>& x,
22 std::vector<double>& y,
23 std::vector<double>& w)
25 size_t complete_count = 0;
26 for (
size_t i = 0; i < x.size(); ++i) {
27 bool row_has_nan = (std::isnan(x[i]) || std::isnan(y[i]));
29 row_has_nan = (row_has_nan || std::isnan(w[i]));
31 x[complete_count] = x[i];
32 y[complete_count] = y[i];
34 w[complete_count] = w[i];
39 x.resize(complete_count);
40 y.resize(complete_count);
42 w.resize(complete_count);
46 any_nan(
const std::vector<double>& x)
48 for (
size_t i = 0; (i < x.size()); i++) {
57 validate_weights(
const std::vector<double>& weights)
61 double weight_sum = 0.0;
62 for (
const auto& weight : weights) {
63 if (!std::isfinite(weight) || weight < 0.0)
64 throw std::runtime_error(
"weights must be finite and nonnegative.");
67 if (!std::isfinite(weight_sum) || weight_sum <= 0.0)
68 throw std::runtime_error(
"weights must have a finite, positive sum.");
72 preproc(std::vector<double>& x,
73 std::vector<double>& y,
74 std::vector<double>& weights,
78 if (!methods::is_supported(method))
79 throw std::runtime_error(
"method not implemented.");
82 utils::remove_incomplete(x, y, weights);
83 utils::validate_weights(weights);
84 if (x.size() < methods::get_min_nobs(method))
87 std::stringstream msg;
88 if (utils::any_nan(x) || utils::any_nan(y) || utils::any_nan(weights)) {
89 msg <<
"there are missing values in the data; "
90 <<
"try remove_missing = TRUE";
92 utils::validate_weights(weights);
93 if (x.size() < methods::get_min_nobs(method))
94 msg <<
"need at least " << methods::get_min_nobs(method)
97 if (!msg.str().empty())
98 throw std::runtime_error(msg.str());
Weighted dependence measures.
Definition: wdm.hpp:19