Skip to content

Commit 3ba79f2

Browse files
authored
Add files via upload
1 parent 940d767 commit 3ba79f2

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "Point_Estimates.ipynb",
7+
"version": "0.3.2",
8+
"provenance": []
9+
},
10+
"kernelspec": {
11+
"name": "python3",
12+
"display_name": "Python 3"
13+
}
14+
},
15+
"cells": [
16+
{
17+
"cell_type": "code",
18+
"metadata": {
19+
"id": "j1cQgMzxLqxN",
20+
"colab_type": "code",
21+
"colab": {
22+
"base_uri": "https://localhost:8080/",
23+
"height": 34
24+
},
25+
"outputId": "fde15623-382f-48db-e42d-df4f5fd8a3ac"
26+
},
27+
"source": [
28+
"%matplotlib inline \n",
29+
"import numpy as np\n",
30+
"import pandas as pd\n",
31+
"import scipy.stats as stats\n",
32+
"import matplotlib.pyplot as plt\n",
33+
"import random\n",
34+
"import math\n",
35+
"np.random.seed(10)\n",
36+
"population_ages1 = stats.poisson.rvs(loc=18, mu=35, size=150000)\n",
37+
"population_ages2 = stats.poisson.rvs(loc=18, mu=10, size=100000)\n",
38+
"population_ages = np.concatenate((population_ages1, population_ages2))\n",
39+
"\n",
40+
"population_ages.mean()"
41+
],
42+
"execution_count": 2,
43+
"outputs": [
44+
{
45+
"output_type": "execute_result",
46+
"data": {
47+
"text/plain": [
48+
"43.002372"
49+
]
50+
},
51+
"metadata": {
52+
"tags": []
53+
},
54+
"execution_count": 2
55+
}
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"metadata": {
61+
"id": "Stlpz09vLqxh",
62+
"colab_type": "code",
63+
"colab": {}
64+
},
65+
"source": [
66+
"np.random.seed(6)\n",
67+
"sample_ages = np.random.choice(a= population_ages,size=500)"
68+
],
69+
"execution_count": 0,
70+
"outputs": []
71+
},
72+
{
73+
"cell_type": "code",
74+
"metadata": {
75+
"id": "80mLxWv1Lqxq",
76+
"colab_type": "code",
77+
"colab": {
78+
"base_uri": "https://localhost:8080/",
79+
"height": 34
80+
},
81+
"outputId": "9e21fac5-721b-48e3-f9e0-89dfc23c910c"
82+
},
83+
"source": [
84+
"print ( sample_ages.mean() )"
85+
],
86+
"execution_count": 5,
87+
"outputs": [
88+
{
89+
"output_type": "stream",
90+
"text": [
91+
"42.388\n"
92+
],
93+
"name": "stdout"
94+
}
95+
]
96+
},
97+
{
98+
"cell_type": "code",
99+
"metadata": {
100+
"id": "oxYfwI5qLqx1",
101+
"colab_type": "code",
102+
"colab": {
103+
"base_uri": "https://localhost:8080/",
104+
"height": 34
105+
},
106+
"outputId": "2835e1a1-9b6a-4236-fa27-216fa148e499"
107+
},
108+
"source": [
109+
"population_ages.mean() - sample_ages.mean()"
110+
],
111+
"execution_count": 9,
112+
"outputs": [
113+
{
114+
"output_type": "execute_result",
115+
"data": {
116+
"text/plain": [
117+
"0.614372000000003"
118+
]
119+
},
120+
"metadata": {
121+
"tags": []
122+
},
123+
"execution_count": 9
124+
}
125+
]
126+
}
127+
]
128+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "confidence_interval_margin_of_error.ipynb",
7+
"version": "0.3.2",
8+
"provenance": []
9+
},
10+
"kernelspec": {
11+
"name": "python3",
12+
"display_name": "Python 3"
13+
}
14+
},
15+
"cells": [
16+
{
17+
"cell_type": "code",
18+
"metadata": {
19+
"id": "qE_pk1w3Luqb",
20+
"colab_type": "code",
21+
"colab": {
22+
"base_uri": "https://localhost:8080/",
23+
"height": 119
24+
},
25+
"outputId": "c99b445c-c0a4-4963-879c-b303182fda1d"
26+
},
27+
"source": [
28+
"import numpy as np\n",
29+
"import scipy.stats as stats\n",
30+
"import math\n",
31+
"\n",
32+
"np.random.seed(10)\n",
33+
"population_ages1 = stats.poisson.rvs(loc=18, mu=35, size=150000)\n",
34+
"population_ages2 = stats.poisson.rvs(loc=18, mu=10, size=100000)\n",
35+
"population_ages = np.concatenate((population_ages1, population_ages2))\n",
36+
"\n",
37+
"sample_size = 1000\n",
38+
"sample = np.random.choice(a= population_ages, size = sample_size)\n",
39+
"sample_mean = sample.mean()\n",
40+
"z_critical = stats.norm.ppf(q = 0.975) # Get the z-critical value*\n",
41+
"print(\"z-critical value:\") # Check the z-critical value\n",
42+
"print(z_critical) \n",
43+
"\n",
44+
"pop_stdev = population_ages.std() # Get the population standard deviation\n",
45+
"margin_of_error = z_critical * (pop_stdev/math.sqrt(sample_size))\n",
46+
"\n",
47+
"print(\"Margin of Error:\")\n",
48+
"print(margin_of_error)\n",
49+
"\n",
50+
"confidence_interval = (sample_mean - margin_of_error,\n",
51+
" sample_mean + margin_of_error) \n",
52+
"\n",
53+
"print(\"Confidence interval:\")\n",
54+
"print(confidence_interval)"
55+
],
56+
"execution_count": 3,
57+
"outputs": [
58+
{
59+
"output_type": "stream",
60+
"text": [
61+
"z-critical value:\n",
62+
"1.959963984540054\n",
63+
"Margin of Error:\n",
64+
"0.8199359311731705\n",
65+
"Confidence interval:\n",
66+
"(42.39706406882683, 44.03693593117317)\n"
67+
],
68+
"name": "stdout"
69+
}
70+
]
71+
}
72+
]
73+
}

0 commit comments

Comments
 (0)