10  Normal distribution

\[ \distnormal(x; \mu, \sigma^2) \]

posterior mean: \[ \frac{n}{n+\frac{\sigma_0^2}{s_0^2}}\overline{X}+\frac{\frac{\sigma_0^2}{s_0^2}}{n+\frac{\sigma_0^2}{s_0^2}}m. \]

10.1 The empirical theorem

10.2 Python implementation

Click to expand.

We use the norm object from scipy.stats package.

  • scipy.stats.norm(loc=mean, scale=standard_deviation) is to intialize a normal distribution object.
  • pdf(): probablitiy distribution function, both inputs and outputs are numpy arrays.
  • cdf(): cumulative distribution function, both inputs and outputs are numpy arrays.
  • interval(confidence, loc=0, scale=1): confidence interval.
  • ppf(): Percent point function (inverse of cdf), both inputs and outputs are numpy arrays.
  • rvs(size=1): random samplings.
Code
from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(norm.ppf(0.001), norm.ppf(0.999), 100)
y = norm.pdf(x)
plt.plot(x, y)
_ = plt.title("pdf for Normal distribution (0, 1)")

Code
from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(norm.ppf(0.001), norm.ppf(0.999), 100)
y = norm.cdf(x)
plt.plot(x, y)
_ = plt.title("cdf for Normal distribution (0, 1)")

Code
from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(norm.ppf(0.001), norm.ppf(0.999), 100)
y = norm.pdf(x)
plt.plot(x, y)

samples = norm.rvs(size=1000)
plt.hist(samples, bins=20, density=True)
_ = plt.title("histogram of random samplings for Normal distribution (0, 1)")

10.3 R implementation

Click to expand.

safljsdf