1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
9 #define BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
12 #include <boost/mpl/placeholders.hpp>
13 #include <boost/accumulators/framework/accumulator_base.hpp>
14 #include <boost/accumulators/framework/extractor.hpp>
15 #include <boost/accumulators/framework/parameters/sample.hpp>
16 #include <boost/accumulators/numeric/functional.hpp>
17 #include <boost/accumulators/framework/depends_on.hpp>
18 #include <boost/accumulators/statistics/mean.hpp>
19 #include <boost/accumulators/statistics/moment.hpp>
21 namespace boost { namespace accumulators
26 ///////////////////////////////////////////////////////////////////////////////
29 @brief Kurtosis estimation
31 The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the square of the 2nd central
32 moment (the variance) of the samples, minus 3. The term \f$ -3 \f$ is added in order to ensure that the normal distribution
33 has zero kurtosis. The kurtosis can also be expressed by the simple moments:
38 {\widehat{m}_n^{(4)}-4\widehat{m}_n^{(3)}\hat{\mu}_n+6\widehat{m}_n^{(2)}\hat{\mu}_n^2-3\hat{\mu}_n^4}
39 {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
42 where \f$ \widehat{m}_n^{(i)} \f$ are the \f$ i \f$-th moment and \f$ \hat{\mu}_n \f$ the mean (first moment) of the
45 template<typename Sample>
49 // for boost::result_of
50 typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type;
52 kurtosis_impl(dont_care) {}
54 template<typename Args>
55 result_type result(Args const &args) const
58 accumulators::moment<4>(args)
59 - 4. * accumulators::moment<3>(args) * mean(args)
60 + 6. * accumulators::moment<2>(args) * mean(args) * mean(args)
61 - 3. * mean(args) * mean(args) * mean(args) * mean(args)
62 , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
63 * ( accumulators::moment<2>(args) - mean(args) * mean(args) )
70 ///////////////////////////////////////////////////////////////////////////////
76 : depends_on<mean, moment<2>, moment<3>, moment<4> >
80 typedef accumulators::impl::kurtosis_impl<mpl::_1> impl;
84 ///////////////////////////////////////////////////////////////////////////////
89 extractor<tag::kurtosis> const kurtosis = {};
91 BOOST_ACCUMULATORS_IGNORE_GLOBAL(kurtosis)
94 using extract::kurtosis;
96 // So that kurtosis can be automatically substituted with
97 // weighted_kurtosis when the weight parameter is non-void
99 struct as_weighted_feature<tag::kurtosis>
101 typedef tag::weighted_kurtosis type;
105 struct feature_of<tag::weighted_kurtosis>
106 : feature_of<tag::kurtosis>
110 }} // namespace boost::accumulators