28 #ifndef WILCOXONRANKSUMTEST_H 29 #define WILCOXONRANKSUMTEST_H 31 #include <boost/math/special_functions/binomial.hpp> 32 #include <boost/math/special_functions/erf.hpp> 58 return( m_value < rhs.
m_value );
69 double frequency(
double u,
int sampleSizeA,
int sampleSizeB ) {
70 if( u < 0. || sampleSizeA < 0 || sampleSizeB < 0 )
73 if( u == 0 && sampleSizeA >= 0 && sampleSizeB >= 0 )
76 return(
frequency( u - sampleSizeB, sampleSizeA - 1, sampleSizeB ) +
frequency( u, sampleSizeA, sampleSizeB - 1 ) );
79 template<
typename SampleType>
84 std::vector<Element> combinedSample( x.size() + y.size() );
86 for(
unsigned int i = 0; i < x.size(); i++ ) {
87 combinedSample[i].m_value = x.at( i );
90 for(
unsigned int i = 0; i < y.size(); i++ ) {
91 combinedSample[i + x.size()].m_value = y.at( i );
95 std::sort( combinedSample.begin(), combinedSample.end() );
97 std::pair< std::vector<Element>::iterator, std::vector<Element>::iterator > p;
98 std::vector<Element>::iterator it = combinedSample.begin();
100 while( it != combinedSample.end() ) {
101 p = std::equal_range( it, combinedSample.end(), *it );
110 while( it != p.second ) {
111 it->m_rank = rank + c/2.;
123 for( it = combinedSample.begin(); it != combinedSample.end(); ++it ) {
134 double uA = wA - x.size() * ( x.size() + 1 ) / 2.;
135 double uB = wB - y.size() * ( y.size() + 1 ) / 2.;
140 std::cout <<
"ua: " << uA <<
", ub: " << uB << std::endl;
142 double cases = boost::math::binomial_coefficient<double>( x.size() + y.size(), x.size() );
143 if( cases < 0 || cases > 1000000 ) {
144 std::cout <<
"Normal approximation" << std::endl;
146 double mu = (0.5 * x.size()) * y.size();
147 double sigma = ::sqrt( ( ( x.size() + 1.0) * x.size() ) * y.size() / 12.0 );
148 double Za = (uA - mu) / sigma;
149 double Zb = (uB - mu) / sigma;
150 pA = 0.5 * boost::math::erfc(-Za / M_SQRT2);
151 pB = 0.5 * boost::math::erfc(-Zb / M_SQRT2);
157 result.m_pH1 = 1.-pA;
158 result.m_pH2 = 1.-pB;
165 template<
typename Stream>
172 #endif // WILCOXONRANKSUMTEST_H