Foundations of Probability in Python
Alexander A. Ramírez M.
CEO @ Synergy Vision
$$ $$
In Python this can be done in a couple of lines:
# Import norm
from scipy.stats import norm
# Calculate the probability density
# with pdf
norm.pdf(-1, loc=0, scale=1)
0.24197072451914337
loc
parameter specifies the mean and scale
parameter specifies the standard deviation.
$$ $$
$$ $$
$$ $$
$$ $$
$$ $$
$$ $$
# Calculate cdf of -1
norm.cdf(-1)
0.15865525393145707
# Calculate cdf of 0.5
norm.cdf(0.5)
0.6914624612740131
# Calculate ppf of 0.2
norm.ppf(0.2)
-0.8416212335729142
# Calculate ppf of 55%
norm.ppf(0.55)
0.12566134685507416
# Calculate cdf of value 0
norm.cdf(0)
0.5
# Calculate ppf of probability 50%
norm.ppf(0.5)
0
$$ $$
$$ $$
# Create our variables
a = -1
b = 1
# Calculate the probability between
# two values, subtracting
norm.cdf(b) - norm.cdf(a)
0.6826894921370859
$$ $$
$$ $$
# Create our variable
a = 1
# Calculate the complement
# of cdf() using sf()
norm.sf(a)
0.15865525393145707
$$ $$
$$ $$
# Create our variables
a = -2
b = 2
# Calculate tail probability
# by adding each tail
norm.cdf(a) + norm.sf(b)
0.04550026389635839
$$ $$
$$ $$
# Create our variables
a = -2
b = 2
# Calculate tail probability
# by adding each tail
norm.cdf(a) + norm.sf(b)
0.04550026389635839
$$ $$
$$ $$
# Create our variable
alpha = 0.95
# Calculate the interval
norm.interval(alpha)
(-1.959963984540054, 1.959963984540054)
Foundations of Probability in Python