wdm

A header-only C++ library for weighted dependence measures

Provides efficient implementations of weighted dependence measures and related independence tests:

  • Pearsons's rho
  • Spearmans's rho
  • Kendall's tau
  • Blomqvist's beta
  • Hoeffding's D

All measures are computed in O(n log n) time, where n is the number of observations.

Functionality

The library provides:

  • a function wdm() to compute the weighted dependence measures,
  • a class Indep_test to perform a test for independence based on asymptotic p-values.

For details, see the API documentation and the example below.

Dependencies

The library only requires C++11.

For projects already using the Eigen linear algebra library, there are convenience wrappers that can be made available via

1 #include <wdm/eigen.hpp>

Including the library in other projects

There are two options:

  1. Either copy the header files in include/ to your project.
  2. Install the headers globally using the CMake project. To do that go to the root repository of this repo and run:
    1 mkdir build && cd build # open build folder
    2 cmake .. && sudo make install # install library
    3 cd .. && rm -rf build # leave and remove build folder
    To use the library in your project, just add target_link_libraries(your_proj_name wdm) to your_proj_name/CMakeLists.txt.

You can then include the main header in your source code:

1 #include <wdm.hpp>

Example

1 #include "wdm.hpp"
2 
3 // input vectors
4 std::vector<double> x{1, 3, 2, 5, 3, 2, 20, 15};
5 std::vector<double> y{2, 12, 4, 7, 8, 14, 17, 6};
6 
7 // weights
8 std::vector<double> w{1, 1, 2, 2, 1, 0, 0.5, 0.3};
9 
10 std::cout <<
11  "unweighted Kendall's tau: " << wdm::wdm(x, y, "kendall") << std::endl;
12 std::cout <<
13  "weighted Kendall's tau: " << wdm::wdm(x, y, "kendall", w) << std::endl;
14 
15 // weighted independence test
16 wdm::Indep_test test(x, y, "kendall", w);
17 std::cout << "statistic: " << test.statistic() << std::endl;
18 std::cout << "p-value: " << test.p_value() << std::endl;
1 unweighted Kendall's tau: 0.2965
2 weighted Kendall's tau: 0.550633
3 statistic: 1.71047
4 p-value: 0.0871793