Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonicanada/dcd8347b344fabae01d81fea33270d1b to your computer and use it in GitHub Desktop.
Save tonicanada/dcd8347b344fabae01d81fea33270d1b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"sample_size_n = 200\n",
"sample_mean_from_binomial = get_sample_parameter_from_variable(400, \n",
" sample_size_n, \n",
" df, \n",
" 'mean', \n",
" 'binomial')\n",
"sample_median_from_normal = get_sample_parameter_from_variable(400, \n",
" sample_size_n, \n",
" df, \n",
" 'median', \n",
" 'normal')\n",
"sample_std_from_uniform = get_sample_parameter_from_variable(400, \n",
" sample_size_n, \n",
" df, \n",
" 'std', \n",
" 'uniform')\n",
"#Here we compute \"manually\" the standard error\n",
"sample_mean_from_binomial_std = np.std(sample_mean_from_binomial)\n",
"sample_median_from_normal_std = np.std(sample_median_from_normal)\n",
"sample_std_from_uniform_std = np.std(sample_std_from_uniform)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"#Here we compute standard error using the expressions\n",
"sample_mean_from_binomial_se = df.binomial.std()/np.sqrt(sample_size_n)\n",
"sample_median_from_normal_se = 1.2533 * (df.normal.std()/np.sqrt(sample_size_n))\n",
"sample_std_from_uniform_se = df.uniform.std() / np.sqrt(2*(sample_size_n-1))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"binomialdist_example (mean, n=200)\": {\n",
" \"computed_se\": 0.0504901583850754,\n",
" \"formula_se\": 0.05815619602703747\n",
" },\n",
" \"normaldist_example (median, n=200)\": {\n",
" \"computed_se\": 0.004247561325654817,\n",
" \"formula_se\": 0.004343732383749954\n",
" },\n",
" \"uniformdist_example (std, n=200)\": {\n",
" \"computed_se\": 0.013055146058296654,\n",
" \"formula_se\": 0.02204320895687334\n",
" }\n",
"}\n"
]
}
],
"source": [
"#Comparing results of computing SE \"manually\" versus formula\n",
"se = {\n",
" f\"binomialdist_example (mean, n={sample_size_n})\": {\n",
" \"computed_se\": sample_mean_from_binomial_std,\n",
" \"formula_se\": sample_mean_from_binomial_se\n",
" },\n",
" f\"normaldist_example (median, n={sample_size_n})\": {\n",
" \"computed_se\": sample_median_from_normal_std,\n",
" \"formula_se\": sample_median_from_normal_se\n",
" },\n",
" f\"uniformdist_example (std, n={sample_size_n})\": {\n",
" \"computed_se\": sample_std_from_uniform_std,\n",
" \"formula_se\": sample_std_from_uniform_se\n",
" }\n",
"}\n",
"print(json.dumps(se, indent=4))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment