{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# IntroStat Week 4 \n", "\n", "Simulation of the Central Limit Theorem (by examples)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy.stats as stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Data from a uniform distribution" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n=10\n", "k=1000\n", "u = stats.uniform.rvs(loc=0, scale=30, size=(n,k))\n", "\n", "mean_values = u.mean(axis=0)\n", "\n", "plt.hist(mean_values, density=True)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now increase n to 2,3,6,30" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Data from an exponential distribution" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n=30\n", "k=1000\n", "u = stats.expon.rvs(loc=0, scale=30, size=(n,k))\n", "mean_values = u.mean(axis=0)\n", "\n", "plt.hist(mean_values, density=True)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now increase n to 2,3,6,30" ] } ], "metadata": { "kernelspec": { "display_name": "pernille", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 2 }