bivariate_statistics.qbk 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. [/
  2. Copyright 2018 Nick Thompson
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:bivariate_statistics Bivariate Statistics]
  8. [heading Synopsis]
  9. ``
  10. #include <boost/math/statistics/bivariate_statistics.hpp>
  11. namespace boost{ namespace math{ namespace statistics {
  12. template<class Container>
  13. auto covariance(Container const & u, Container const & v);
  14. template<class Container>
  15. auto means_and_covariance(Container const & u, Container const & v);
  16. template<class Container>
  17. auto correlation_coefficient(Container const & u, Container const & v);
  18. }}}
  19. ``
  20. [heading Description]
  21. This file provides functions for computing bivariate statistics.
  22. [heading Covariance]
  23. Computes the population covariance of two datasets:
  24. std::vector<double> u{1,2,3,4,5};
  25. std::vector<double> v{1,2,3,4,5};
  26. double cov_uv = boost::math::statistics::covariance(u, v);
  27. The implementation follows [@https://doi.org/10.1109/CLUSTR.2009.5289161 Bennet et al].
  28. The data is not modified. Requires a random-access container.
  29. Works with real-valued inputs and does not work with complex-valued inputs.
  30. The algorithm used herein simultaneously generates the mean values of the input data /u/ and /v/.
  31. For certain applications, it might be useful to get them in a single pass through the data.
  32. As such, we provide `means_and_covariance`:
  33. std::vector<double> u{1,2,3,4,5};
  34. std::vector<double> v{1,2,3,4,5};
  35. auto [mu_u, mu_v, cov_uv] = boost::math::statistics::means_and_covariance(u, v);
  36. [heading Correlation Coefficient]
  37. Computes the [@https://en.wikipedia.org/wiki/Pearson_correlation_coefficient Pearson correlation coefficient] of two datasets /u/ and /v/:
  38. std::vector<double> u{1,2,3,4,5};
  39. std::vector<double> v{1,2,3,4,5};
  40. double rho_uv = boost::math::statistics::correlation_coefficient(u, v);
  41. // rho_uv = 1.
  42. The data must be random access and cannot be complex.
  43. If one or both of the datasets is constant, the correlation coefficient is an indeterminant form (0/0) and definitions must be introduced to assign it a value.
  44. We use the following: If both datasets are constant, then the correlation coefficient is 1.
  45. If one dataset is constant, and the other is not, then the correlation coefficient is zero.
  46. [heading References]
  47. * Bennett, Janine, et al. ['Numerically stable, single-pass, parallel statistics algorithms.] Cluster Computing and Workshops, 2009. CLUSTER'09. IEEE International Conference on. IEEE, 2009.
  48. [endsect]
  49. [/section:bivariate_statistics Bivariate Statistics]