-
-
Save grassa/1184362 to your computer and use it in GitHub Desktop.
equations(1) from Hohenlohe, et. al. 2010 http://www.plosgenetics.org/article/info:doi/10.1371/journal.pgen.1000862
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 <stdio.h> | |
#include <math.h> | |
long fact(int n){ | |
if(n == 0){ | |
return 1; | |
} | |
else{ | |
return n * fact(n-1); | |
} | |
} | |
double laa( int n1, int n2, int n3, int n4, float e ){ | |
int nsum; | |
double sampling; | |
double aa; | |
nsum = n1 + n2 + n3 + n4; | |
sampling = fact(nsum) / ( fact( n1 ) * fact( n2 ) * fact( n3 ) * fact( n4 ) ); | |
aa = ((sampling) * ( pow(( 1.0 - ( (3*e)/4) ),n1) ) * ( pow((e/4),(n2 + n3 + n4)) )); | |
return aa; | |
} | |
double lab( int n1, int n2, int n3, int n4, float e ){ | |
int nsum; | |
double sampling; | |
double ab; | |
nsum = n1 + n2 + n3 + n4; | |
sampling = fact(nsum) / ( fact( n1 ) * fact( n2 ) * fact( n3 ) * fact( n4 ) ); | |
ab = ((sampling) * ( pow(( 0.5 - (e/4) ),(n1 + n2)) ) * ( pow((e/4),(n3 + n4)) )); | |
return ab; | |
} | |
main(){ | |
int na; | |
int nt; | |
int ng; | |
int nc; | |
float e; | |
na = 5; | |
nt = 1; | |
ng = 0; | |
nc = 0; | |
e = 0.001; | |
double aa; | |
double ab; | |
aa = laa(na,nt,ng,nc,e); | |
ab = lab(na,nt,ng,nc,e); | |
printf("%e\t%e\n", aa, ab ); | |
/* sampling = fact(nS) / ( fact(n1) * fact(n2) * fact(n3) * fact(n4) ); */ | |
/* $L11 = $sampling * ( ( 1 - ((3*$E)/4) )**$n1 ) * ( ($E/4)**($n2 + $n3 + $n4) ); */ | |
/* $L12 = $sampling * ( ( 0.5 - ($E/4) )**($n1 + $n2) ) * ( ($E/4)**($n3 + $n4) ); */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lines 45, 47, and 49 of https://gist.github.com/1090505, implemented in c.