Created
November 28, 2017 05:19
-
-
Save jarhill0/af251879e57a917a6e2cf8ca27548bbb to your computer and use it in GitHub Desktop.
my z-table in python
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
from math import sqrt, erf, erfc | |
from scipy.special import erfinv, erfcinv | |
class Table: | |
def __init__(self, precision=4): | |
self.precision = precision | |
def below(self, z_score): | |
return round(0.5 + 0.5 * erf(z_score / sqrt(2)), self.precision) | |
def above(self, z_score): | |
return round(0.5 * erfc(z_score / sqrt(2)), self.precision) | |
def lower_percentage(self, percentage): | |
return round(sqrt(2) * erfinv((percentage - 0.5) / 0.5), self.precision) | |
def upper_percentage(self, percentage): | |
return round(sqrt(2) * erfcinv(percentage / 0.5), self.precision) | |
def __repr__(self): | |
return 'Math.Table({})'.format(self.precision) | |
if __name__ == '__main__': | |
z = Table() | |
print(z.below(0.5)) | |
print(z.above(0.5)) | |
print(z.lower_percentage(0.25)) | |
print(z.upper_percentage(0.25)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment