Created
December 7, 2016 15:39
-
-
Save tleonardi/3e4d3b591f8329559790229f9f297f40 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/awk -f | |
function logfactorial(n, f, i){ | |
f=0 | |
for(i=1;i<=n;i++){ | |
f+=log(i) | |
} | |
return f | |
} | |
# m: Mean | |
# x: Poisson random var | |
function poisson(m, x, i, e, TOT, lt, ut){ | |
e=exp(1) | |
for(i=0;i<=x;i++){ | |
TOT+=exp(-m + i*log(m) - logfactorial(i)) | |
} | |
# Lower tail probability | |
lt=TOT | |
# Upper tail probability | |
ut=1-TOT | |
return ut | |
} | |
BEGIN{ | |
print poisson(10, 20) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment