<jupyter_start><jupyter_text>Probability and Statistics  imports<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
import seaborn
from numpy.random import gamma, lognormal, normal, randn, uniform<jupyter_output><empty_output><jupyter_text>Exercise 1<jupyter_code>a = normal(0, 1, size=(1000,))
b = normal(3, 3, size=(1000,))
c = uniform(0, 1, size=(1000,))
d = uniform(-1, 1, size=(1000,))
e = gamma(1, 2, size=(1000,))
f = lognormal(0.08, 0.2, size=(1000,))<jupyter_output><empty_output><jupyter_text>Exercise 2<jupyter_code>stats.kstest(a, stats.norm(loc=0, scale=1).cdf)
stats.kstest(b, stats.norm(loc=3, scale=3).cdf)
stats.kstest(c, stats.uniform(loc=0, scale=1).cdf)
stats.kstest(d, stats.uniform(loc=-1, scale=2).cdf)
stats.kstest(e, stats.gamma(1, scale=2).cdf)<jupyter_output><empty_output><jupyter_text>Exercise 3<jupyter_code>x = randn(1)
x
print("np.random.seed():")
np.random.seed()
x = randn(1)
x<jupyter_output><empty_output><jupyter_text>Exercise 4<jupyter_code>state = np.random.get_state()
x = randn(2, 1)
print("x:")
x
print("np.random.set_state(state):")
np.random.set_state(state)
x = randn(2, 1)
print("x:")
x<jupyter_output><empty_output><jupyter_text>Exercise 5<jupyter_code>def summary_stats(x):
    return x.mean(), x.std(), stats.skew(x), stats.kurtosis(x) + 3


x = randn(100)
print("summary_stats(x):")
summary_stats(x)<jupyter_output><empty_output><jupyter_text>Exercise 6<jupyter_code>x = stats.multivariate_normal(cov=[[1, -0.5], [-0.5, 1]]).rvs(100)
print("stats.pearsonr(x[:,0],x[:,1]):")
stats.pearsonr(x[:, 0], x[:, 1])
print("stats.spearmanr(x[:,0],x[:,1]):")
stats.spearmanr(x[:, 0], x[:, 1])
print("stats.kendalltau(x[:,0],x[:,1]):")
stats.kendalltau(x[:, 0], x[:, 1])<jupyter_output><empty_output><jupyter_text>Exercise 7<jupyter_code>gam = stats.gamma(1, scale=2)
print("gam.median():")
gam.median()
print("np.median(gam.rvs(10000)):")
np.median(gam.rvs(10000))<jupyter_output><empty_output><jupyter_text>Exercise 8<jupyter_code>x = np.linspace(0, 1 - (1.0 / 1000), 1000) + 1.0 / 2000
plt.figure(1)
u = np.sort(stats.norm(loc=0, scale=1).cdf(a))
plt.plot(x, u, x, x)
plt.figure(2)
u = np.sort(stats.norm(loc=3, scale=3).cdf(b))
plt.plot(x, u, x, x)
plt.figure(3)
u = np.sort(stats.uniform(loc=0, scale=1).cdf(c))
plt.plot(x, u, x, x)
plt.figure(4)
u = np.sort(stats.uniform(loc=-1, scale=2).cdf(d))
plt.plot(x, u, x, x)
plt.figure(5)
u = np.sort(stats.gamma(1, scale=2).cdf(e))
plt.plot(x, u, x, x)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21728786677240286, 'fraction_numerical': 0.05273592386994449, 'mean_word_length': 7.581632653061225, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '664157', 'license': 'CC0-1.0', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1151, 'n_words': 174, 'path': 'solutions/chapter19/probability_and_statistics_functions.ipynb', 'repo_name': 'bashtage/python-for-econometrics-statistics-data-analysis', 'size': '2522'}