<jupyter_start><jupyter_text>Probability and Statistics  imports<jupyter_code>from numpy.random import uniform, normal, gamma, lognormal, randn
import scipy.stats  as stats
import numpy as np
import matplotlib.pyplot as plt
import seaborn<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(.08,.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 = randn(100,2)
rho = 0.5
x[:,1] = rho * x[:,0] + np.sqrt(1-rho**2) * x[:,1]
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.22360999194198228, 'fraction_numerical': 0.053585817888799354, 'mean_word_length': 8.892430278884461, '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': '418224', 'license': 'CC0-1.0', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1169, 'n_words': 125, 'path': 'solutions/chapter18/probability_and_statistics_functions.ipynb', 'repo_name': 'ColdTeapot273K/python-for-econometrics-statistics-data-analysis', 'size': '2482'}