Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / accumulators / statistics / skewness.hpp @ 2486

History | View | Annotate | Download (3.4 kB)

1 2486 sjacqu01
///////////////////////////////////////////////////////////////////////////////
2 2486 sjacqu01
// skewness.hpp
3 2486 sjacqu01
//
4 2486 sjacqu01
//  Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost
5 2486 sjacqu01
//  Software License, Version 1.0. (See accompanying file
6 2486 sjacqu01
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 2486 sjacqu01
8 2486 sjacqu01
#ifndef BOOST_ACCUMULATORS_STATISTICS_SKEWNESS_HPP_EAN_28_10_2005
9 2486 sjacqu01
#define BOOST_ACCUMULATORS_STATISTICS_SKEWNESS_HPP_EAN_28_10_2005
10 2486 sjacqu01
11 2486 sjacqu01
#include <limits>
12 2486 sjacqu01
#include <boost/mpl/placeholders.hpp>
13 2486 sjacqu01
#include <boost/accumulators/framework/accumulator_base.hpp>
14 2486 sjacqu01
#include <boost/accumulators/framework/extractor.hpp>
15 2486 sjacqu01
#include <boost/accumulators/framework/parameters/sample.hpp>
16 2486 sjacqu01
#include <boost/accumulators/numeric/functional.hpp>
17 2486 sjacqu01
#include <boost/accumulators/framework/depends_on.hpp>
18 2486 sjacqu01
#include <boost/accumulators/statistics_fwd.hpp>
19 2486 sjacqu01
#include <boost/accumulators/statistics/moment.hpp>
20 2486 sjacqu01
#include <boost/accumulators/statistics/mean.hpp>
21 2486 sjacqu01
22 2486 sjacqu01
23 2486 sjacqu01
namespace boost { namespace accumulators
24 2486 sjacqu01
{
25 2486 sjacqu01
26 2486 sjacqu01
namespace impl
27 2486 sjacqu01
{
28 2486 sjacqu01
    ///////////////////////////////////////////////////////////////////////////////
29 2486 sjacqu01
    // skewness_impl
30 2486 sjacqu01
    /**
31 2486 sjacqu01
        @brief Skewness estimation
32 2486 sjacqu01

33 2486 sjacqu01
        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 2486 sjacqu01
        of the 2nd central moment (the variance) of the samples 3. The skewness can also be expressed by the simple moments:
35 2486 sjacqu01

36 2486 sjacqu01
        \f[
37 2486 sjacqu01
            \hat{g}_1 =
38 2486 sjacqu01
                \frac
39 2486 sjacqu01
                {\widehat{m}_n^{(3)}-3\widehat{m}_n^{(2)}\hat{\mu}_n+2\hat{\mu}_n^3}
40 2486 sjacqu01
                {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^{3/2}}
41 2486 sjacqu01
        \f]
42 2486 sjacqu01

43 2486 sjacqu01
        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
44 2486 sjacqu01
        \f$ n \f$ samples.
45 2486 sjacqu01
    */
46 2486 sjacqu01
    template<typename Sample>
47 2486 sjacqu01
    struct skewness_impl
48 2486 sjacqu01
      : accumulator_base
49 2486 sjacqu01
    {
50 2486 sjacqu01
        // for boost::result_of
51 2486 sjacqu01
        typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type;
52 2486 sjacqu01
53 2486 sjacqu01
        skewness_impl(dont_care)
54 2486 sjacqu01
        {
55 2486 sjacqu01
        }
56 2486 sjacqu01
57 2486 sjacqu01
        template<typename Args>
58 2486 sjacqu01
        result_type result(Args const &args) const
59 2486 sjacqu01
        {
60 2486 sjacqu01
            return numeric::fdiv(
61 2486 sjacqu01
                        accumulators::moment<3>(args)
62 2486 sjacqu01
                        - 3. * accumulators::moment<2>(args) * mean(args)
63 2486 sjacqu01
                        + 2. * mean(args) * mean(args) * mean(args)
64 2486 sjacqu01
                      , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
65 2486 sjacqu01
                        * std::sqrt( accumulators::moment<2>(args) - mean(args) * mean(args) )
66 2486 sjacqu01
                   );
67 2486 sjacqu01
        }
68 2486 sjacqu01
    };
69 2486 sjacqu01
70 2486 sjacqu01
} // namespace impl
71 2486 sjacqu01
72 2486 sjacqu01
///////////////////////////////////////////////////////////////////////////////
73 2486 sjacqu01
// tag::skewness
74 2486 sjacqu01
//
75 2486 sjacqu01
namespace tag
76 2486 sjacqu01
{
77 2486 sjacqu01
    struct skewness
78 2486 sjacqu01
      : depends_on<mean, moment<2>, moment<3> >
79 2486 sjacqu01
    {
80 2486 sjacqu01
        /// INTERNAL ONLY
81 2486 sjacqu01
        ///
82 2486 sjacqu01
        typedef accumulators::impl::skewness_impl<mpl::_1> impl;
83 2486 sjacqu01
    };
84 2486 sjacqu01
}
85 2486 sjacqu01
86 2486 sjacqu01
///////////////////////////////////////////////////////////////////////////////
87 2486 sjacqu01
// extract::skewness
88 2486 sjacqu01
//
89 2486 sjacqu01
namespace extract
90 2486 sjacqu01
{
91 2486 sjacqu01
    extractor<tag::skewness> const skewness = {};
92 2486 sjacqu01
93 2486 sjacqu01
    BOOST_ACCUMULATORS_IGNORE_GLOBAL(skewness)
94 2486 sjacqu01
}
95 2486 sjacqu01
96 2486 sjacqu01
using extract::skewness;
97 2486 sjacqu01
98 2486 sjacqu01
// So that skewness can be automatically substituted with
99 2486 sjacqu01
// weighted_skewness when the weight parameter is non-void
100 2486 sjacqu01
template<>
101 2486 sjacqu01
struct as_weighted_feature<tag::skewness>
102 2486 sjacqu01
{
103 2486 sjacqu01
    typedef tag::weighted_skewness type;
104 2486 sjacqu01
};
105 2486 sjacqu01
106 2486 sjacqu01
template<>
107 2486 sjacqu01
struct feature_of<tag::weighted_skewness>
108 2486 sjacqu01
  : feature_of<tag::skewness>
109 2486 sjacqu01
{
110 2486 sjacqu01
};
111 2486 sjacqu01
112 2486 sjacqu01
}} // namespace boost::accumulators
113 2486 sjacqu01
114 2486 sjacqu01
#endif