Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62315 - in sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table: . cells detail factor include include/pearson_chisq pearson_chisq pearson_chisq/common pearson_chisq/independence sample
From: erwann.rogard_at_[hidden]
Date: 2010-05-30 12:04:47


Author: e_r
Date: 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
New Revision: 62315
URL: http://svn.boost.org/trac/boost/changeset/62315

Log:
m
Added:
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/cells.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/cells_count.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/count_matching.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/marginal_cells.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/non_empty_cells_count.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/policy_keyword.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/raise_domain_error.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/second_accumulator.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/size_accumulator.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/check_against_domain.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/domain_error_logger.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/filter.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/keyword.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/vec_levels.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/cells.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/factor.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/pearson_chisq/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/pearson_chisq/common.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/pearson_chisq/independence.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/sample.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/asy_distribution.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/chisq_summand_formula.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/df_formula.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/depends_on.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/df.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/impl.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/lost_df.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/statistic.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/tag.hpp (contents, props changed)
   sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/sample/

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/cells.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/cells.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,207 @@
+///////////////////////////////////////////////////////////////////////////////
+// cells.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_CELLS_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_CELLS_HPP_ER_2010
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_const.hpp>
+
+#include <boost/math/policies/policy.hpp>
+
+#include <boost/fusion/include/at_key.hpp>
+#include <boost/fusion/container/map/detail/extract_keys.hpp> // needed?
+#include <boost/fusion/container/map/detail/subset_traits.hpp>
+#include <boost/fusion/container/map/detail/hashable_map.hpp>
+
+#include <boost/unordered_map.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/framework/parameters/weight.hpp>
+#include <boost/accumulators/framework/detail/unpack_depends_on.hpp>
+
+#include <boost/statistics/detail/non_parametric/contingency_table/detail/policy_keyword.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/detail/raise_domain_error.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/vec_levels.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/domain_error_logger.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/check_against_domain.hpp>
+
+// Usage:
+// typedef cells<mpl::vector<X,Y,Z> > cells_
+// This is a Boost.Accumulator feature specifying a contingency table asso-
+// ciated with variables X, Y, and Z.
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace cells{
+
+ template<typename Keys>
+ struct cells_depends_on{
+ typedef typename factor::vec_levels<Keys>::type vec_levels_;
+ typedef typename boost::accumulators::detail::unpack_depends_on<
+ vec_levels_
+ >::type type;
+ };
+
+ template<typename T,typename Keys>
+ struct cells_traits{
+ typedef boost::fusion::detail::map_subset_traits<T,Keys> inner_traits;
+ typedef typename inner_traits::map subsample_;
+ typedef boost::fusion::detail::hashable_map<
+ subsample_> hashable_subsample_;
+ typedef typename boost::unordered_map<
+ hashable_subsample_,std::size_t> map_;
+
+ };
+
+namespace impl{
+
+ template<typename T,typename Keys>
+ class cells : public boost::accumulators::accumulator_base{
+ typedef boost::accumulators::dont_care dont_care_;
+ typedef std::size_t size_;
+
+ typedef contingency_table::cells::cells_traits<T,Keys> traits_;
+ typedef typename traits_::hashable_subsample_ hashable_subsample_;
+ typedef typename traits_::map_ map_;
+
+ public:
+
+ typedef T sample_type;
+ typedef size_ size_type;
+
+ typedef map_& result_type; // not const bec map[] is non-const
+
+ cells(dont_care_){}
+
+ template<typename A1,typename A2>
+ void operator()(const A1& a1,const A2& a2){
+
+ }
+
+ template<typename Args>
+ void operator()(const Args& args){
+ namespace ns = boost::statistics::detail;
+ typedef boost::math::policies::policy<> pol_;
+ for(long int i = 0; i< args[boost::accumulators::weight]; i++)
+ {
+ this->update_if(
+ hashable_subsample_( args[boost::accumulators::sample] ),
+ args[ boost::accumulators::accumulator ],
+ args[ ns::_policy | pol_() ]
+ );
+ }
+ }
+
+ result_type result(dont_care_)const{
+ return this->map;
+ }
+
+ private:
+ template<typename V,typename A,typename P>
+ void update_if(
+ const V& s,
+ const A& acc,
+ const P& policy
+ ){
+ this->error_logger.reset();
+ boost::fusion::for_each(
+ s,
+ factor::make_check_against_domain( acc, this->error_logger)
+ );
+ if(!this->error_logger.is_error())
+ {
+ ++( this->map )[ s ];
+ }else{
+ namespace ns = contingency_table;
+ static const char* fun = "impl::cells::update_if %1%";
+ ns::raise_domain_error<V>(
+ fun,
+ this->error_logger().c_str(),
+ policy
+ );
+ }
+ }
+
+ mutable map_ map;
+ typedef contingency_table::factor::domain_error_logger error_logger_;
+ error_logger_ error_logger;
+ };
+
+}// impl
+namespace tag
+{
+
+ template<typename Keys>
+ struct cells
+ : contingency_table::cells::cells_depends_on<Keys>::type
+ {
+ typedef typename factor::par_spec< Keys >::type par_spec_;
+
+ struct impl{
+ template<typename T,typename W>
+ struct apply{
+ typedef contingency_table
+ ::cells::impl::cells<T,Keys> type;
+ };
+ };
+ };
+
+}// tag
+namespace result_of{
+namespace extract{
+
+ template<typename Keys,typename AccSet>
+ struct cells
+ : boost::accumulators::detail::extractor_result<
+ AccSet,
+ contingency_table::cells::tag::cells<Keys>
+ >{};
+
+}// extract
+}// result_of
+namespace extract
+{
+
+ // Usage :
+ // cells<Key>(acc,policy)
+ template<typename Keys,typename P,typename AccSet>
+ typename contingency_table::cells::result_of::extract::template
+ cells<Keys,AccSet>::type
+ cells(AccSet const& acc,const P& policy)
+ {
+ typedef contingency_table::cells::tag::cells<Keys> the_tag;
+ return boost::accumulators::extract_result<the_tag>(acc,policy);
+ }
+
+ template<typename Keys,typename AccSet>
+ typename contingency_table::cells::result_of::extract::template
+ cells<Keys,AccSet>::type
+ cells(AccSet const& acc)
+ {
+ typedef boost::math::policies::policy<> policy_;
+ return extract::cells<Keys>(acc,policy_());
+ }
+
+}// extract
+
+using extract::cells;
+
+}// cells
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/cells_count.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/cells_count.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////
+// cells_count.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_CELLS_COUNT_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_CELLS_COUNT_HPP_ER_2010
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/detail/wrapper.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace cells{
+
+ template<typename A>
+ struct cells_count_aux{
+
+ typedef std::size_t size_;
+ typedef void result_type;
+
+ cells_count_aux(const A& acc,size_& n)
+ :acc_( acc ),n_( n ){}
+
+ template<typename Key>
+ void operator()(const boost::statistics::detail::mpl_wrapper<Key>& u){
+ this->n_ *= factor::levels<Key>( this->acc_ ).size();
+ }
+
+ const A& acc_;
+ size_& n_;
+ };
+
+ template<typename Keys,typename AccSet>
+ std::size_t cells_count(AccSet const& acc){
+ namespace ns = statistics::detail;
+ typedef ns::mpl_wrapper<boost::mpl::_> op_;
+ typedef cells::cells_count_aux<AccSet> fun_;
+ std::size_t n = 1;
+ boost::mpl::for_each<Keys,op_>(
+ fun_( acc, n )
+ );
+ return n;
+ }
+
+}// cells
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/count_matching.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/count_matching.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,68 @@
+///////////////////////////////////////////////////////////////////////////////
+// count_matching.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_COUNT_MATCHING_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_COUNT_MATCHING_HPP_ER_2010
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/cells.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/sample/view.hpp>
+#include <boost/mpl/detail/wrapper.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace cells{
+
+ template<typename Keys,typename AccSet,typename T>
+ std::size_t count_matching(AccSet const& acc,const T& sample){
+ return cells::extract::cells<Keys>( acc )[ sample ];
+ }
+
+ // A: accumulator set
+ // S: sample
+ // F: unary functor
+ template<typename A,typename S,typename F>
+ struct count_matching_aux{
+
+ typedef std::size_t size_;
+ typedef void result_type;
+
+ count_matching_aux(const A& a,const S& s, const F& f)
+ :acc( a ), sample( s ), fun( f ){}
+
+ template<typename Keys>
+ void operator()(const statistics::detail::mpl_wrapper<Keys>& u)const{
+ this->fun(
+ cells::count_matching<Keys>(
+ this->acc,
+ this->sample
+ )
+ );
+ }
+
+ private:
+ const A& acc;
+ const S& sample;
+ F fun;
+ };
+
+ template<typename A,typename S,typename F>
+ count_matching_aux<A,S,F>
+ make_count_matching_aux(const A& a,const S& s, const F& f){
+ typedef count_matching_aux<A,S,F> result_;
+ return result_(a, s, f);
+ }
+
+}// cells
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/marginal_cells.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/marginal_cells.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,42 @@
+///////////////////////////////////////////////////////////////////////////////
+// marginal_cells.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_MARGINAL_CELLS_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_MARGINAL_CELLS_HPP_ER_2010
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/vector/vector0.hpp>
+#include <boost/mpl/vector/vector10.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/cells.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace cells{
+
+ template<typename Keys>
+ struct marginal_cells : boost::mpl::fold<
+ Keys,
+ boost::mpl::vector0<>,
+ boost::mpl::push_back<
+ boost::mpl::_1,
+ contingency_table::cells::tag::cells<
+ boost::mpl::vector1<boost::mpl::_2>
+ >
+ >
+ >{};
+
+}// cells
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif
+

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/non_empty_cells_count.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/cells/non_empty_cells_count.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+// non_empty_cells_count.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_NON_EMPTY_CELLS_COUNT_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_CELLS_NON_EMPTY_CELLS_COUNT_HPP_ER_2010
+#include <boost/range.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/cells.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace cells{
+
+ template<typename Keys,typename AccSet>
+ std::size_t non_empty_cells_count(AccSet const& acc){
+ return cells::extract::cells<Keys>(acc).size() ;
+ }
+
+}// cells
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/policy_keyword.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/policy_keyword.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// policy_keyword.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_POLICY_KEYWORD_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_POLICY_KEYWORD_HPP_ER_2010
+#include <boost/parameter/name.hpp>
+
+// TODO move this to a common directory
+
+namespace boost{
+namespace statistics{
+namespace detail{
+
+ BOOST_PARAMETER_NAME((_policy, keyword) policy)
+
+}// detail
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/raise_domain_error.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/raise_domain_error.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,86 @@
+///////////////////////////////////////////////////////////////////////////////
+// raise_domain_error.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_DETAIL_RAISE_DOMAIN_ERROR_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_DETAIL_RAISE_DOMAIN_ERROR_HPP_ER_2010
+#include <boost/math/policies/error_handling.hpp>
+#include <boost/math/policies/policy.hpp>
+
+// Unlike their boost::math::policies counterparts, these error policy actions
+// do not return a value bec. quiet_NaN etc. may not be defined for the
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+
+// fwd_declare
+template <class T>
+T user_domain_error(const char* function, const char* message);
+
+namespace detail{
+
+template <class T>
+inline void raise_domain_error(
+ const char* function,
+ const char* message,
+ const ::boost::math::policies::domain_error<
+ ::boost::math::policies::throw_on_error>&)
+{
+ namespace ns = boost::math::policies::detail;
+ ns::raise_error<std::domain_error, T>(function, message);
+}
+
+template <class T>
+inline void raise_domain_error(
+ const char* ,
+ const char* ,
+ const ::boost::math::policies::domain_error<
+ ::boost::math::policies::ignore_error>&)
+{}
+
+template <class T>
+inline void raise_domain_error(
+ const char* ,
+ const char* ,
+ const ::boost::math::policies::domain_error<
+ ::boost::math::policies::errno_on_error>&)
+{
+ errno = EDOM;
+}
+
+template <class T>
+inline void raise_domain_error(
+ const char* function,
+ const char* message,
+ const ::boost::math::policies::domain_error<
+ ::boost::math::policies::user_error>&)
+{
+ contingency_table::user_domain_error<T>(function, message);
+}
+
+}// detail
+
+template <class T, class Policy>
+inline void raise_domain_error(
+ const char* function,
+ const char* message,
+ const Policy& p
+)
+{
+ typedef typename Policy::domain_error_type policy_type;
+ contingency_table::detail::raise_domain_error<T>(
+ function, message ? message : "Domain Error evaluating function",
+ policy_type());
+}
+
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/second_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/second_accumulator.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,44 @@
+///////////////////////////////////////////////////////////////////////////////
+// second_accumulator.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_DETAIL_SECOND_ACCUMULATOR_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_DETAIL_SECOND_ACCUMULATOR_HPP_ER_2010
+#include <boost/range.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace impl{
+
+ template<typename T>
+ struct second_accumulator
+ {
+ typedef std::size_t result_type;
+
+ second_accumulator(T& init):sum(init){}
+
+ template<typename U>
+ void operator()(const U& u)const{
+ sum += u.second;
+ }
+
+ mutable T& sum;
+ };
+
+ template<typename T>
+ second_accumulator<T> make_second_accumulator(T& init){
+ return second_accumulator<T>(init);
+ }
+
+}// impl
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/size_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/detail/size_accumulator.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,44 @@
+///////////////////////////////////////////////////////////////////////////////
+// size_accumulator.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_DETAIL_SIZE_ACCUMULATOR_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_DETAIL_SIZE_ACCUMULATOR_HPP_ER_2010
+#include <boost/range.hpp>
+
+namespace boost{
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace impl{
+
+ template<typename T>
+ struct size_accumulator
+ {
+ typedef std::size_t result_type;
+
+ size_accumulator(T& init):sum(init){}
+
+ template<typename U>
+ void operator()(const U& u)const{
+ sum += boost::size( u );
+ }
+
+ mutable T& sum;
+ };
+
+ template<typename T>
+ size_accumulator<T> make_size_accumulator(T& init){
+ return size_accumulator<T>(init);
+ }
+
+}// impl
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/check_against_domain.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/check_against_domain.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,66 @@
+///////////////////////////////////////////////////////////////////////////////
+// check_against_domain.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_CHECK_AGAINST_DOMAIN_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_CHECK_AGAINST_DOMAIN_HPP_ER_2010
+#include <boost/fusion/include/at_key.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace factor{
+
+ template<typename A,typename E>
+ struct check_against_domain{
+
+ typedef void result_type;
+
+ check_against_domain(const A& acc, const E& error_logger)
+ :acc_(acc),error_logger_(error_logger){}
+
+ template<typename T>
+ void operator()(const T& pair)const
+ {
+ typedef typename T::first_type key_;
+ typedef typename T::second_type data_;
+ namespace ns = contingency_table::factor;
+
+ // See domain_error_logger for justification of fully qualified.
+ this->impl<key_,data_>(
+ pair.second,
+ ns::extract::levels<key_>( this->acc_ )
+ );
+ }
+
+ private:
+ template<typename Key,typename T,typename L>
+ void impl(const T& data,const L& levels)const{
+ if( levels.count( data ) != 1 )
+ {
+ this->error_logger_.template add<Key,T>( data );
+ }
+ }
+ mutable const A& acc_;
+ mutable const E& error_logger_;
+ };
+
+template<typename A,typename E>
+contingency_table::factor::check_against_domain<A,E>
+make_check_against_domain(const A& acc,const E& error_logger){
+ typedef contingency_table::factor::check_against_domain<A,E> checker_;
+ return checker_(acc,error_logger);
+}
+
+}// factor
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/domain_error_logger.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/domain_error_logger.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,61 @@
+///////////////////////////////////////////////////////////////////////////////
+// domain_error_logger.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_DOMAIN_ERROR_LOGGER_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_DOMAIN_ERROR_LOGGER_HPP_ER_2010
+#include <string>
+#include <boost/format.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace factor{
+
+class domain_error_logger{
+ typedef std::string str_;
+ typedef boost::format f_;
+
+ public:
+
+ domain_error_logger():is_error_(false){}
+
+ // Call add<Key,T>(data), not add<Key>(data) (strings would otherwise get
+ // converted to const char* or smthg like that).
+ template<typename Key,typename T>
+ void add(const T& data)const{
+ static const str_ str ="(%1%,%2%)";
+ if(this->is_error()){
+ this->log_ += ",";
+ }else{
+ this->is_error_ = true;
+ }
+ this->log_ += ( f_(str) % typeid(T).name() % data ).str();
+ }
+
+ void reset(){ this->is_error_ = false; }
+
+ bool is_error()const{ return this->is_error_; }
+ str_ operator()()const{
+ static const str_ pre = "(key,level) = { ";
+ static const str_ suf = " }";
+ return pre + this->log_ + suf;
+ }
+
+ private:
+ mutable bool is_error_;
+ mutable str_ log_;
+
+};
+
+}// factor
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/filter.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/filter.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////////
+// filter.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_FILTER_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_FILTER_HPP_ER_2010
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/contains.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace factor{
+
+ template<typename Keys>
+ struct filter{
+
+ template<typename Key>
+ struct contains : boost::mpl::contains<Keys, Key>{};
+
+ template<typename T>
+ struct apply : boost::mpl::bool_<false>{};
+
+ template<typename Key>
+ struct apply< factor::tag::levels<Key> > : contains<Key>{};
+ };
+
+}// factor
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/keyword.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/keyword.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,61 @@
+///////////////////////////////////////////////////////////////////////////////
+// keyword.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_KEYWORD_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_KEYWORD_HPP_ER_2010
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/vector/vector0.hpp>
+
+#include <boost/parameter/keyword.hpp>
+#include <boost/parameter/parameters.hpp>
+
+#include <boost/parameter/detail/unpack_parameters.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace factor{
+
+ template<typename Key>
+ struct kwd{
+ typedef kwd<Key> tag_;
+ static ::boost::parameter::keyword<tag_> & instance;
+ };
+
+ template<typename Key>
+ ::boost::parameter::keyword< kwd<Key> > &
+ kwd<Key>::instance = ::boost::parameter::keyword< kwd<Key> >::get();
+
+ template<typename Keys>
+ struct par_spec{
+
+ typedef typename boost::mpl::fold<
+ Keys,
+ boost::mpl::vector0<>,
+ boost::mpl::push_back<
+ boost::mpl::_1,
+ boost::parameter::required<
+ factor::kwd<boost::mpl::_2>
+ >
+ >
+ >::type vec_required;
+
+ typedef typename boost::parameter::detail::unpack_parameters<
+ vec_required
+ >::type type;
+
+ };
+
+}// factor
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,157 @@
+///////////////////////////////////////////////////////////////////////////////
+// levels.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_LEVELS_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_LEVELS_HPP_ER_2010
+#include <vector>
+#include <boost/config.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_const.hpp>
+#include <boost/range.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/unordered_set.hpp>
+#include <boost/fusion/include/at_key.hpp>
+#include <boost/fusion/include/pair.hpp>
+#include <boost/parameter/name.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/keyword.hpp>
+
+// Source : http://www.ats.ucla.edu/stat/R/modules/factor_variables.htm
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace factor{
+
+BOOST_PARAMETER_NAME(map_of_levels);
+
+ template<typename K,typename T>
+ struct levels_traits{
+ typedef typename boost::fusion::result_of::at_key<T,K>::type ref_;
+ typedef typename boost::remove_reference<ref_>::type qual_;
+ typedef typename boost::remove_const<qual_>::type val_;
+ typedef boost::unordered_set<val_> set_;
+ };
+
+namespace impl{
+
+ template<typename Key,typename T>
+ class levels : public boost::accumulators::accumulator_base
+ {
+ typedef boost::accumulators::dont_care dont_care_;
+ typedef factor::levels_traits<Key,T> traits_;
+ typedef typename traits_::set_ set_;
+ typedef factor::kwd<Key> kwd_;
+
+ public:
+ typedef Key key_type;
+ typedef typename traits_::val_ data_type;
+
+ typedef T sample_type;
+ typedef set_& result_type;
+
+ levels(dont_care_){}
+
+ template<typename Args>
+ explicit levels(const Args& args)
+ :storage(
+ make_set(
+ args[ _map_of_levels | set_() ]
+ )
+ )
+ {
+ // TODO allow either the above OR kwd_::instance. For now
+ // this does not compile
+ }
+
+ void operator()(dont_care_)const{}
+
+ result_type result(dont_care_)const{
+ return this->storage;
+ }
+
+ private:
+ static set_ make_set(const set_& s){ return s; }
+
+ template<typename M>
+ static set_ make_set(const M& map,typename M::fusion_tag* = 0){
+ return make_set_impl( boost::fusion::at_key<Key>(map) );
+ }
+
+ template<typename L>
+ static set_ make_set_impl(const L& levels){
+ return set_(
+ boost::begin( levels ),
+ boost::end( levels )
+ );
+ }
+
+ mutable set_ storage;
+ };
+
+}// impl
+
+namespace tag
+{
+ template<typename Key>
+ struct levels
+ : boost::accumulators::depends_on<>
+ {
+
+ //typedef factor::tpl_keyword<Key> keyword_;
+
+ struct impl{
+ template<typename T,typename W>
+ struct apply{
+ typedef factor::impl::levels<Key,T> type;
+ };
+ };
+
+ };
+
+}// tag
+
+namespace result_of{
+
+ template<typename Key,typename AccSet>
+ struct factor
+ : boost::accumulators::detail::extractor_result<
+ AccSet, factor::tag::levels<Key> >{};
+
+}// result_of
+
+namespace extract
+{
+
+ template<typename Key,typename AccSet>
+ typename factor::result_of::template
+ factor<Key,AccSet>::type
+ levels(AccSet const& acc)
+ {
+ typedef factor::tag::levels<Key> the_tag;
+ return boost::accumulators::extract_result<the_tag>(acc);
+ }
+
+}// extract
+
+using extract::levels;
+
+}// factor
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif
+

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/vec_levels.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/factor/vec_levels.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////////
+// vec_levels.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_VEC_LEVELS_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_FACTOR_VEC_LEVELS_HPP_ER_2010
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/vector/vector0.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace factor{
+
+ template<typename Keys>
+ struct vec_levels : boost::mpl::fold<
+ Keys,
+ boost::mpl::vector0<>,
+ boost::mpl::push_back<
+ boost::mpl::_1,
+ contingency_table::factor::tag::levels<boost::mpl::_2>
+ >
+ >{};
+
+
+}// factor
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/cells.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/cells.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// cells.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_CELLS_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_CELLS_HPP_ER_2010
+
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/cells.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/non_empty_cells_count.hpp>
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/factor.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/factor.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,18 @@
+///////////////////////////////////////////////////////////////////////////////
+// factor.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_FACTOR_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_FACTOR_HPP_ER_2010
+
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/check_against_domain.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/domain_error_logger.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/levels.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/filter.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/keyword.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/vec_levels.hpp>
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/pearson_chisq/common.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/pearson_chisq/common.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// common.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_PEARSON_CHISQ_COMMON_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_PEARSON_CHISQ_COMMON_HPP_ER_2010
+
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/df_formula.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/asy_distribution.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/chisq_summand_formula.hpp>
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/pearson_chisq/independence.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/pearson_chisq/independence.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// independence.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_PEARSON_CHISQ_INDEPENDENCE_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_PEARSON_CHISQ_INDEPENDENCE_HPP_ER_2010
+
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/df.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/statistic.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/tag.hpp>
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/sample.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/include/sample.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// sample.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_SAMPLE_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_INCLUDE_SAMPLE_HPP_ER_2010
+
+#include <boost/statistics/detail/non_parametric/contingency_table/sample/view.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/sample/hash.hpp>
+//#include <boost/statistics/detail/non_parametric/contingency_table/sample/check_against_domain.hpp>
+//#include <boost/statistics/detail/non_parametric/contingency_table/sample/domain_error_logger.hpp>
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/asy_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/asy_distribution.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,59 @@
+///////////////////////////////////////////////////////////////////////////////
+// asy_distribution.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_ASY_DISTRIBUTION_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_ASY_DISTRIBUTION_HPP_ER_2010
+#include <boost/math/distributions/chi_squared.hpp>
+#include <boost/math/policies/policy.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+namespace result_of{
+
+ template<typename T1,typename Policy = boost::math::policies::policy<> >
+ struct asy_distribution{
+ typedef boost::math::chi_squared_distribution<T1,Policy> type;
+ };
+
+}
+
+ template<typename T1,typename AccSet,typename H0,typename Policy>
+ typename pearson_chisq::result_of::asy_distribution<T1,Policy>::type
+ asy_distribution(
+ const AccSet& acc,
+ const H0& hypothesis,
+ const Policy& pol
+ )
+ {
+ typename pearson_chisq::result_of::asy_distribution<
+ T1,Policy>::type result_;
+ return result_(
+ pearson_chisq::df( hypothesis )
+ );
+ }
+
+ template<typename T1,typename AccSet,typename H0>
+ typename pearson_chisq::result_of::asy_distribution<T1>::type
+ asy_distribution(const AccSet& acc,const H0& hypothesis){
+ typedef boost::math::policies::policy<> pol_;
+ return pearson_chisq::asy_distribution(
+ acc,
+ hypothesis,
+ pol_()
+ );
+ }
+
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/chisq_summand_formula.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/chisq_summand_formula.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,35 @@
+///////////////////////////////////////////////////////////////////////////////
+// chisq_summand.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_CHISQ_SUMMAND_FORMULA_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_CHISQ_SUMMAND_FORMULA_HPP_ER_2010
+#include <boost/numeric/conversion/converter.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+
+ template<typename T1,typename T2,typename T3>
+ T1 chisq_summand_formula(const T2& expected_n, const T3& observed_n)
+ {
+ typedef boost::numeric::converter<T1,T2> conv2_;
+ typedef boost::numeric::converter<T1,T3> conv3_;
+ T1 summand = conv2_::convert( expected_n )
+ - conv3_::convert( observed_n );
+ summand *= summand;
+ return summand / conv2_::convert( expected_n );
+ }
+
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/df_formula.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/df_formula.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,40 @@
+///////////////////////////////////////////////////////////////////////////////
+// df_formula.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_DF_FORMULA_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_DF_FORMULA_HPP_ER_2010
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+
+// http://wapedia.mobi/en/Pearson%27s_chi-square_test
+
+// General formula
+// df = ( N1 - 1 ) - N2
+// N1 = # cells in table
+// N2 = # of estimated probabilities under H0 a.k.a lost df under H0
+//
+// For example, test of independence in dimension = 2
+// Known result : df = (r − 1)(c − 1) = rc -r -c + 1
+// By formula : df = ( rc - 1 ) - ( (r-1) + (c-1) ) = rc -r -c + 1
+
+ template<typename Int>
+ Int df_formula(Int number_of_cells,Int lost_df)
+ {
+ return (number_of_cells - 1) - lost_df;
+ }
+
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/depends_on.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/depends_on.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,48 @@
+///////////////////////////////////////////////////////////////////////////////
+// depends_on.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_DEPENDS_ON_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_DEPENDS_ON_HPP_ER_2010
+#include <boost/mpl/push_back.hpp>
+#include <boost/accumulators/statistics/detail/weighted_count.hpp>
+#include <boost/accumulators/framework/detail/unpack_depends_on.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/marginal_cells.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+namespace independence_aux{
+
+ template<typename Keys>
+ struct depends_on{
+ typedef typename cells::marginal_cells<Keys>::type marginal_;
+ typedef contingency_table::cells::tag::cells<Keys> joint_;
+// typedef boost::accumulators::tag::count count_;
+ typedef boost::accumulators::tag::weighted_count weighted_count_;
+ typedef typename boost::mpl::push_back<
+ typename boost::mpl::push_back<
+ marginal_,
+ joint_
+ >::type,
+ weighted_count_
+ >::type dependencies_;
+
+ typedef typename boost::accumulators::detail::unpack_depends_on<
+ dependencies_
+ >::type type;
+ };
+
+}// independence_aux
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/df.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/df.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,36 @@
+///////////////////////////////////////////////////////////////////////////////
+// df.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_DF_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_DF_HPP_ER_2010
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/cells_count.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/df_formula.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/lost_df.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+
+ template<typename Keys,typename AccSet>
+ long df(AccSet const& acc,tag::independence<Keys> hypothesis){
+ namespace ns = contingency_table::cells;
+ return pearson_chisq::df_formula<long>(
+ ns::cells_count<Keys>( acc ),
+ lost_df( acc, hypothesis )
+ );
+ }
+
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif
+

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/impl.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/impl.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,44 @@
+///////////////////////////////////////////////////////////////////////////////
+// impl.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_IMPL_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_IMPL_HPP_ER_2010
+#include <boost/accumulators/framework/accumulator_base.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+namespace impl{
+
+ template<typename Keys>
+ class independence : public boost::accumulators::accumulator_base
+ {
+ typedef boost::accumulators::dont_care dont_care_;
+
+ public:
+
+ typedef void result_type;
+
+ independence(dont_care_){}
+
+ void operator()(dont_care_)const{}
+
+ result_type result(dont_care_)const{}
+
+ };
+
+}// impl
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif
+

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/lost_df.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/lost_df.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,72 @@
+///////////////////////////////////////////////////////////////////////////////
+// lost_df.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_LOST_DF_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_LOST_DF_HPP_ER_2010
+#include <boost/range.hpp>
+#include <boost/accumulators/framework/depends_on.hpp> //contains_feature_of
+#include <boost/accumulators/framework/accumulator_set.hpp> //visit_if
+#include <boost/mpl/detail/wrapper.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/factor/vec_levels.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/tag.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+
+namespace independence_aux{
+
+ template<typename A>
+ struct lost_df_accumulator{
+
+ lost_df_accumulator(const A& acc,std::size_t& df)
+ :acc_(acc),df_(df){}
+
+ template<typename Key>
+ void operator()(const statistics::detail::mpl_wrapper<Key>& wrapper)const{
+ namespace ns = contingency_table::factor::extract;
+ this->df_ += (ns::levels<Key>( this->acc_ ).size() - 1);
+ }
+
+ private:
+ const A& acc_;
+ mutable std::size_t& df_;
+ };
+
+
+ template<typename A>
+ independence_aux::lost_df_accumulator<A>
+ make_lost_df_accumulator(const A& acc,std::size_t& df){
+ return independence_aux::lost_df_accumulator<A>(acc,df);
+ }
+
+}// independence_aux
+
+ template<typename Keys,typename AccSet>
+ std::size_t lost_df(
+ AccSet const& acc,
+ pearson_chisq::tag::independence<Keys> hypothesis
+ )
+ {
+ namespace ns = boost::statistics::detail;
+ typedef ns::mpl_wrapper<boost::mpl::_> op_;
+ std::size_t result = 0;
+ boost::mpl::for_each<Keys,op_>(
+ independence_aux::make_lost_df_accumulator(acc, result)
+ );
+ return result;
+ }
+
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/statistic.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/statistic.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,126 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistic.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_STATISTIC_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_STATISTIC_HPP_ER_2010
+#include <cmath>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/vector/vector10.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/foreach.hpp>
+#include <boost/range.hpp>
+#include <boost/accumulators/statistics/detail/weighted_count.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/common/chisq_summand_formula.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/cells.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/cells/count_matching.hpp>
+
+// Under independence, in dimension = 2
+// p_{j1,j2} = p_{j1} * p{j2}
+
+// Warning : this is incomplete / Wrong.
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+namespace independence_aux{
+
+ template<typename T1,typename Keys,typename AccSet>
+ struct chisq_summand
+ {
+
+ typedef std::size_t size_;
+ typedef typename boost::mpl::size<Keys>::type keys_count_;
+
+ template<typename N>
+ chisq_summand(const AccSet& a, const N& total_count)
+ : acc( a ) , denom(
+ pow( total_count, keys_count_::value - 1)
+ ){}
+
+ template<typename C>
+ T1 operator()(const C& cell)const
+ {
+ namespace ns = boost::statistics::detail;
+ typedef ns::mpl_wrapper<
+ boost::mpl::vector1< boost::mpl::_ >
+ > op_;
+ typedef boost::numeric::converter<T1,size_> conv_;
+ size_ n = 1;
+ boost::mpl::for_each<Keys,op_>(
+ cells::make_count_matching_aux(acc, cell.first, prod_fun( n ) )
+ );
+ return chisq_summand_formula<T1>(
+ conv_::convert( n ) / conv_::convert( denom ),
+ cell.second
+ );
+ }
+
+ struct prod_fun{
+
+ prod_fun(size_& n) : n_( n ){}
+
+ template<typename T>
+ void operator()(const T& k)const{
+ this->n_ *= k;
+ }
+
+ mutable size_& n_;
+ };
+
+ const AccSet& acc;
+ size_ denom;
+
+ };
+
+}// independence_aux
+
+ template<typename T1,typename Keys,typename AccSet>
+ T1 statistic(
+ const AccSet& acc,
+ pearson_chisq::tag::independence<Keys> hypothesis
+ )
+ {
+ namespace ns = pearson_chisq::independence_aux;
+ typedef typename contingency_table::cells::result_of::extract::cells<
+ Keys,AccSet>::type ref_cells_;
+ typedef typename boost::remove_reference<ref_cells_>::type cells_;
+ typedef typename boost::range_reference<cells_>::type ref_cell_;
+ typedef ns::chisq_summand<T1,Keys,AccSet> summand_;
+ typedef std::size_t size_;
+
+ ref_cells_ ref_cells = cells::extract::cells<Keys>( acc );
+ size_ n_obs = boost::accumulators::extract::weighted_count( acc );
+
+ summand_ summand(acc, n_obs);
+ typedef boost::numeric::converter<T1,size_> conv_;
+
+ T1 result = conv_::convert( 0 );
+ BOOST_FOREACH(ref_cell_ ref_cell, ref_cells )
+ {
+ result += summand( ref_cell );
+ }
+
+ return result;
+ }
+
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif

Added: sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/tag.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_parametric/boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/tag.hpp 2010-05-30 12:04:44 EDT (Sun, 30 May 2010)
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////////
+// tag.hpp //
+// //
+// Copyright 2010 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_TAG_HPP_ER_2010
+#define BOOST_STATISTICS_DETAIL_NON_PARAMETRIC_CONTINGENCY_TABLE_PEARSON_CHISQ_INDEPENDENCE_TAG_HPP_ER_2010
+
+#include <boost/mpl/always.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/impl.hpp>
+#include <boost/statistics/detail/non_parametric/contingency_table/pearson_chisq/independence/depends_on.hpp>
+
+namespace boost {
+namespace statistics{
+namespace detail{
+namespace contingency_table{
+namespace pearson_chisq{
+namespace tag
+{
+ template<typename Keys>
+ struct independence
+ : independence_aux::template depends_on<Keys>::type
+ {
+ typedef boost::mpl::always<
+ pearson_chisq::impl::independence<Keys>
+ > impl;
+ };
+
+}// tag
+}// pearson_chisq
+}// contingency_table
+}// detail
+}// statistics
+}// boost
+
+#endif
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk