1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #ifndef BOOST_HISTOGRAM_UTILITY_CLOPPER_PEARSON_INTERVAL_HPP
- #define BOOST_HISTOGRAM_UTILITY_CLOPPER_PEARSON_INTERVAL_HPP
- #include <boost/histogram/fwd.hpp>
- #include <boost/histogram/utility/binomial_proportion_interval.hpp>
- #include <boost/math/distributions/beta.hpp>
- #include <cmath>
- namespace boost {
- namespace histogram {
- namespace utility {
- template <class ValueType>
- class clopper_pearson_interval : public binomial_proportion_interval<ValueType> {
- public:
- using value_type = typename clopper_pearson_interval::value_type;
- using interval_type = typename clopper_pearson_interval::interval_type;
-
- explicit clopper_pearson_interval(confidence_level cl = deviation{1}) noexcept
- : alpha_half_{static_cast<value_type>(0.5 - 0.5 * static_cast<double>(cl))} {}
- using binomial_proportion_interval<ValueType>::operator();
-
- interval_type operator()(value_type successes, value_type failures) const noexcept {
-
-
-
- const value_type total = successes + failures;
- if (successes == 0) return {0, 1 - std::pow(alpha_half_, 1 / total)};
- if (failures == 0) return {std::pow(alpha_half_, 1 / total), 1};
-
-
-
- math::beta_distribution<value_type> beta_a(successes, failures + 1);
- const value_type a = math::quantile(beta_a, alpha_half_);
- math::beta_distribution<value_type> beta_b(successes + 1, failures);
- const value_type b = math::quantile(beta_b, 1 - alpha_half_);
- return {a, b};
- }
- private:
- value_type alpha_half_;
- };
- }
- }
- }
- #endif
|