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_SKEWNESS_HPP_EAN_28_10_2005
9 #define BOOST_ACCUMULATORS_STATISTICS_SKEWNESS_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_fwd.hpp>
19 #include <boost/accumulators/statistics/moment.hpp>
20 #include <boost/accumulators/statistics/mean.hpp>
23 namespace boost { namespace accumulators
28 ///////////////////////////////////////////////////////////////////////////////
31 @brief Skewness estimation
33 The skewness of a sample distribution is defined as the ratio of the 3rd central moment and the \f$ 3/2 \f$-th power
34 of the 2nd central moment (the variance) of the samples 3. The skewness can also be expressed by the simple moments:
39 {\widehat{m}_n^{(3)}-3\widehat{m}_n^{(2)}\hat{\mu}_n+2\hat{\mu}_n^3}
40 {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^{3/2}}
43 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
46 template<typename Sample>
50 // for boost::result_of
51 typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type;
53 skewness_impl(dont_care)
57 template<typename Args>
58 result_type result(Args const &args) const
61 accumulators::moment<3>(args)
62 - 3. * accumulators::moment<2>(args) * mean(args)
63 + 2. * mean(args) * mean(args) * mean(args)
64 , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
65 * std::sqrt( accumulators::moment<2>(args) - mean(args) * mean(args) )
72 ///////////////////////////////////////////////////////////////////////////////
78 : depends_on<mean, moment<2>, moment<3> >
82 typedef accumulators::impl::skewness_impl<mpl::_1> impl;
86 ///////////////////////////////////////////////////////////////////////////////
91 extractor<tag::skewness> const skewness = {};
93 BOOST_ACCUMULATORS_IGNORE_GLOBAL(skewness)
96 using extract::skewness;
98 // So that skewness can be automatically substituted with
99 // weighted_skewness when the weight parameter is non-void
101 struct as_weighted_feature<tag::skewness>
103 typedef tag::weighted_skewness type;
107 struct feature_of<tag::weighted_skewness>
108 : feature_of<tag::skewness>
112 }} // namespace boost::accumulators