{
 "cells": [
  {"cell_type":"markdown","metadata":{},"source":["# Joint distributions, the CLT, and bootstrap\n","Explore dependence and repeated-sampling behavior."]},
  {"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["import numpy as np\n","import matplotlib.pyplot as plt\n","rng = np.random.default_rng(2026)\n","for n in [1, 2, 5, 30]:\n","    means = rng.exponential(1, size=(12000,n)).mean(axis=1)\n","    plt.hist(means, bins=60, density=True, alpha=.45, label=f'n={n}')\n","plt.xlim(0,4); plt.legend(); plt.xlabel('sample mean'); plt.show()"]},
  {"cell_type":"markdown","metadata":{},"source":["## Correlation is not dependence\n","Here $Y=X^2$. The variables are dependent, yet symmetry drives linear correlation toward zero."]},
  {"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["x = rng.uniform(-1,1,3000); y = x*x\n","print('correlation:', np.corrcoef(x,y)[0,1])\n","plt.scatter(x,y,s=7,alpha=.25,color='#2a8c82'); plt.show()"]},
  {"cell_type":"markdown","metadata":{},"source":["## Bootstrap a median\n","Replace the sample below with your own data and compare the bootstrap distribution with the original histogram."]},
  {"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["sample = rng.lognormal(.2,.8,80)\n","boot = np.array([np.median(rng.choice(sample, len(sample), replace=True)) for _ in range(5000)])\n","print('median:', np.median(sample), 'bootstrap SE:', boot.std())"]}
 ],
 "metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3"}},
 "nbformat":4,"nbformat_minor":5
}
