Created
May 28, 2015 21:12
-
-
Save wckdouglas/de53b659c08e0a25b592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Rcpp.h> | |
using namespace Rcpp; | |
double getProb(double p, int success, int fail){ | |
double e = success * log(p) + fail * log(1-p); | |
return e; | |
} | |
//[[Rcpp::export]] | |
NumericVector probOfProb(NumericVector p, int success, int fail){ | |
int size = p.size(); | |
IntegerVector a = seq_len(success), b = seq_len(fail), c = seq_len(fail+success); | |
NumericVector result(size), b1 = log(a), b2 = log(b), b3 = log(c); | |
double c1 = sum(b1), c2 = sum(b2), c3 = sum(b3); | |
double d = c1 + c2 - c3; | |
for (int i = 0 ; i < size; i++){ | |
result[i] = exp(getProb(p[i],success,fail) - d); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment