[Rcpp-commits] r1930 - pkg/Rcpp/inst/include/Rcpp/stats
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Aug 6 00:39:26 CEST 2010
Author: dmbates
Date: 2010-08-06 00:39:26 +0200 (Fri, 06 Aug 2010)
New Revision: 1930
Modified:
pkg/Rcpp/inst/include/Rcpp/stats/binom.h
Log:
pbinom and qbinom added but apparently not correctly
Modified: pkg/Rcpp/inst/include/Rcpp/stats/binom.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/binom.h 2010-08-05 22:38:48 UTC (rev 1929)
+++ pkg/Rcpp/inst/include/Rcpp/stats/binom.h 2010-08-05 22:39:26 UTC (rev 1930)
@@ -35,7 +35,7 @@
vec(vec_), n(n_), prob(prob_), log(log_) {}
inline double operator[]( int i) const {
- return ::dbinom( vec[i], n, prob, log ) ;
+ return ::dbinom( vec[i], (double) n, prob, log ) ;
}
inline int size() const { return vec.size(); }
@@ -48,12 +48,66 @@
} ;
+template <bool NA, typename T>
+class PBinom : public Rcpp::VectorBase< REALSXP, NA, PBinom<NA,T> >{
+public:
+ typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE ;
+
+ PBinom( const VEC_TYPE& vec_, int n_, double prob_, bool lower_tail = true, bool log_ = false ) :
+ vec(vec_), n(n_), prob(prob_), lower(lower_tail), log(log_) {}
+
+ inline double operator[]( int i) const {
+ return ::pbinom( vec[i], (double) n, prob, lower, log ) ;
+ }
+
+ inline int size() const { return vec.size(); }
+
+private:
+ const VEC_TYPE& vec ;
+ int n ;
+ double prob ;
+ int lower, log ;
+
+} ;
+
+template <bool NA, typename T>
+class QBinom : public Rcpp::VectorBase< REALSXP, NA, QBinom<NA,T> >{
+public:
+ typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE ;
+
+ QBinom( const VEC_TYPE& vec_, int n_, double prob_, bool lower_tail = true, bool log_ = false ) :
+ vec(vec_), n(n_), prob(prob_), lower(lower_tail), log(log_) {}
+
+ inline double operator[]( int i) const {
+ return ::qbinom( vec[i], (double) n, prob, lower, log ) ;
+ }
+
+ inline int size() const { return vec.size(); }
+
+private:
+ const VEC_TYPE& vec ;
+ int n ;
+ double prob ;
+ int lower, log ;
+
+} ;
+
} // impl
template <bool NA, typename T>
inline impl::DBinom<NA,T> dbinom( const Rcpp::VectorBase<INTSXP,NA,T>& x, int size, double prob, bool log = false ){
return impl::DBinom<NA,T>( x, size, prob, log );
}
+
+template <bool NA, typename T>
+inline impl::PBinom<NA,T> pbinom( const Rcpp::VectorBase<REALSXP,NA,T>& x, int size, double prob, bool lower = false, bool log = false ){
+ return impl::PBinom<NA,T>( x, size, prob, lower, log );
+}
+
+template <bool NA, typename T>
+inline impl::QBinom<NA,T> qbinom( const Rcpp::VectorBase<REALSXP,NA,T>& x, int size, double prob, bool lower = false, bool log = false ){
+ return impl::QBinom<NA,T>( x, size, prob, lower, log );
+}
}
}
More information about the Rcpp-commits
mailing list