Data Science and Computing with Python for Pilots and Flight Test Engineers
Probability Distributions and Table Values
Probability and Value Tables for Distributions
Introduction
The class ProbabilityTables below implements methods to compute the values in the tables for the \(z\)-, Student’s \(t\)-, and \(\chi^2\)-distributions, as they can be found, for instance in Chapter 6, Appendices 1-3 of the (at the time of writing online freely available) textbook National Test Pilot School, Math & Physics for Flight Testers, Professional Course, Volume I, Mojave, California, 2021. (Note that the \(z\)- distribution in our course is simply the normalized, standard Gaussian (normal) distribution with mean \(\mu=0\) and standard deviation \(\sigma=1\), and not Fisher’s \(z\)-distribution.)
“Prob” is the probability in the \(z\) table and the index of \(t\), or $\chi^2$ in the header of all the columns, while \(\nu\) (nu) denotes the degrees of freedom. \(\alpha\) (alpha) is the significance, i.e. \(\mathrm{prob} = 1 – \alpha\).
Probability Density Functions (PDFs)
Normal (Gaussian) Distribution
The probability density function of the Gaussian (normal) distribution in one dimension with (arithmetic) mean \(\mu\) and standard deviation \(\sigma\) is given by
$$ f(x) = \frac{1}{\sqrt{2\pi}\sigma} e^{\frac{(x-\mu)^2}{2\sigma^2}} $$
\(f(x)\) is the probability of a value in the interval \([x, x+dx]\) to occur on a drawing (with \(dx\) being small).
Student’s t-Distribution
The probability density function (PDF) of Student’s t-distribution is given by
$$ f(t) = \frac{\Gamma\left(\frac{\nu+1}{2}\right)}{\sqrt{\pi\nu}\,\Gamma\left(\frac{\nu}{2}\right)}\left(1+\frac{t^2}{\nu}\right)^{-(\nu+1)/2} $$
where \(\nu\) is the number of degrees of freedom and \(\Gamma\) is the gamma function.
This may also be written as
$$ f(t) = \frac{1}{\sqrt{\nu}B\left(\frac{1}{2},\frac{\nu}{2}\right)}\left(1+\frac{t^2}{\nu}\right)^{-(\nu+1)/2} $$
where \(B\) is the Beta function.
For integer valued degrees of freedom, we have for \(\nu>1\):
If \(\nu\) is even:
$$ \frac{\Gamma\left(\frac{\nu+1}{2}\right)}{\sqrt{\pi\nu}\,\Gamma\left(\frac{\nu}{2}\right)} = \frac{(\nu-1)(\nu-3) \cdots 5 \cdot 3}{2\sqrt{\nu}(\nu-2)(\nu-4)\cdots 4 \cdot 2} $$
If \(\nu\) is odd:
$$ \frac{\Gamma\left(\frac{\nu+1}{2}\right)}{\sqrt{\pi\nu}\,\Gamma\left(\frac{\nu}{2}\right)} = \frac{(\nu-1)(\nu-3) \cdots 4 \cdot 2}{\pi\sqrt{\nu}(\nu-2)(\nu-4)\cdots 5 \cdot 3} $$
Binomial Distribution
Probability of an event occurring \(n\) times out of \(N\) tries, if the probability of a the event occurring on each try is equal to \(p\) (and the probability of the event not occurring on a try is \(q=1-p\), is given by
$$ P(n) = \frac{N!}{n!(N-n)!}p^nq^{N-n} $$
It forms a discrete probability distribution called the binomial distribution.
Code
The class ProbabilityTables below implements the calculation of values from probability tables for the above distributions – tables such as those that can be found in the textbook National Test Pilot School, Math & Physics for Flight Testers, Professional Course, Volume 1, Mojave, California, 2021 in Chapter 6, Appendices 1-3.
class ProbabilityTables:
# Direct table readouts:
# Normal Distribution (Gaussian):
def normal_table_z(self, prob):
""" Percent Point Function (inverse of cumulative probability distribution function):
Returns z for a given probability by integrating the Gaussian probability distribution function
from minus infinity to z. """
z = st.norm.ppf(q=prob)
return z
def normal_table_probability(self, z):
""" Cumulative Probability Distribution Function: Returns integrated (cumulative) probability
of the Gaussian probability distribution function from minus infinity to the selected z value. """
probability = st.norm.cdf(x=z)
return probability
# Student's t Distribution (use for small samples n<30 with unknown sigma):
def student_t_table(self, nu, prob):
""" Returns t from table t_prob in NTPS Manual for nu=n-1 degrees of freedom. """
t = st.t.ppf(q=prob, df=nu)
return t
# Chi-Squared Distribution (use to estimate variability of standard deviation
# (either of sample, s, or of the underlying distribution, sigma):
def chi2_table(self, nu, prob):
""" Returns t for one-tail / upper tail. """
t = st.chi2.ppf(q=prob, df=nu)
return t
# Border values for 1-tailed and 2-tailed probabilities, given significance alpha = 1 - probability:
# Normal (Gaussian) Distribution:
def normal_table_onetail(self, alpha):
z = self.normal_table_z(1.0-alpha)
return z
def normal_table_twotail(self, alpha):
z = self.normal_table_z(1.0-alpha/2.0)
return [-z, z]
# Student's t Distribution:
def student_t_table_onetail(self, nu, alpha):
""" Returns t for one-tail / upper tail. """
t = self.student_t_table(nu, 1.0-alpha)
return t
def student_t_table_twotail(self, nu, alpha):
""" Returns t for one-tail / upper tail. """
t = self.student_t_table(nu, 1.0-alpha/2.0)
return [-t, t]
# Chi-Squared Distribution:
def chi2_table_onetail(self, nu, alpha):
chi = self.chi2_table(nu, 1.0-alpha) # upper cutoff (there is no lower cutoff here).
return chi
def chi2_table_twotail(self, nu, alpha):
chi_1 = self.chi2_table(nu, alpha/2.0) # lower cutoff.
chi_2 = self.chi2_table(nu, 1-alpha/2.0) # upper cutoff.
return [chi_1, chi_2]
# Binomial Distribution:
def binomial_distribution_pdf(self, n, N, p):
""" Binomial Probability Distribution Function. Note that n and N must be integers, and
the probability p of an even occuring 0<=p<=1. """
q = 1-p
pdf = math.factorial(N)/(math.factorial(n)*math.factorial(N-n))*p**n*q**(N-n)
return pdf
def binomial_distribution_cdf(self, x, N, p):
""" Sum of binomial pdf over all n smaller than x. Note that x and N must be integers. """
prob = 0.0
for n in range(0, x+1):
pdf = self.binomial_distribution_pdf(n, N, p)
prob = prob + pdf
return prob
Usage Examples
Below is an example usage of the above tables. Compare the example usage below to manual readouts from the table, so you see how it works. These calls are regularly made by other problem solving methods in the Statistics Part of this course (you may therefore not need to have to make these calls directly for solving individual problems, but you should still be familiar).
Direct Table Readouts
Some direct table readouts for \(z\)- (i.e. normalized normal (Gaussian)), Student’s \(t\)-, and \(\chi^2\)-distribution tables are performed below. Compare the results, for instance, to the corresponding entries in the probability tables in National Test Pilot School, Math & Physics for Flight Testers, Professional Course, Volume 1, Mojave, California, 2021 in Chapter 6, Appendices 1-3
Normal (Gaussian) Distribution
tb = ProbabilityTables()
tb.normal_table_z(prob=0.95)
1.6448536269514722
tb = ProbabilityTables()
tb.normal_table_probability(z=1.0)
0.8413447460685429
Student’s t-Distribution
Returns \(t\) value for \(\nu=n-1\) degrees of freedom from Student’s t-distribution table.
tb = ProbabilityTables()
tb.student_t_table(nu=5, prob=0.995)
4.032142983557536
\(\chi^2\)-Distribution
tb = ProbabilityTables()
tb.chi2_table(nu=10, prob=0.999)
29.58829844507442