Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120259786
Statistics.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 3, 01:35
Size
1 KB
Mime Type
text/x-c
Expires
Sat, Jul 5, 01:35 (1 d, 7 h)
Engine
blob
Format
Raw Data
Handle
27163252
Attached To
R8820 scATAC-seq
Statistics.cpp
View Options
#include <Statistics.hpp>
#include <cmath> // M_PI, pow(), sqrt(), log(), lgamma()
#include <boost/math/distributions.hpp> // beta_distribution
#include <boost/random.hpp>
double normal_pmf(double x, double mean, double sd)
{ static double pi_2 = 2.*M_PI ;
return ( 1. / ( sd * sqrt(pi_2) )) * exp(-0.5 * pow((x-mean)/sd, 2.0 ) );
}
double poisson_pmf(int x, double lambda)
{ if((x != 0) and (lambda == 0))
{ return 0. ; }
else if((x == 0) and (lambda == 0))
{ return 1. ; }
// if(x + lambda == 0)
// { return 1. ; }
return exp(x * log(lambda) - lgamma(x + 1.0) - lambda);
}
double poisson_cdf(int x, double lambda, bool lower_tail)
{ double prob = 1. ;
if(lambda != 0)
{ boost::math::poisson_distribution<> pois_dist(lambda) ;
prob = cdf(pois_dist, x) ;
}
// prob of an observation as big as x
if(lower_tail)
{ return prob ; }
// prob of an observation at least as big as x (pvalue)
else
{ return 1 - prob ; }
}
double beta_pmf(double x, double alpha, double beta)
{
boost::math::beta_distribution<> beta_dist(alpha, beta) ;
double y = quantile(beta_dist, x) ;
return y ;
}
Event Timeline
Log In to Comment