Created
January 17, 2023 09:03
-
-
Save yogeshchappewar/86460817767b9a82763059aca2037c3a to your computer and use it in GitHub Desktop.
Confidence Interval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.276322Z", | |
"end_time": "2023-01-16T11:56:42.292582Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "from scipy import stats\nimport pandas as pd\nimport numpy as np\n", | |
"execution_count": 7, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.292582Z", | |
"end_time": "2023-01-16T11:56:42.325748Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "glaxo_df=pd.read_csv('glaxo_df.csv')\nprint(glaxo_df) ", | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": " Date Date.1 Close gain\n0 2010-01-05 2010-01-05 1616.80 -0.005444\n1 2010-01-06 2010-01-06 1638.50 0.013422\n2 2010-01-07 2010-01-07 1648.70 0.006225\n3 2010-01-08 2010-01-08 1639.80 -0.005398\n4 2010-01-11 2010-01-11 1629.45 -0.006312\n... ... ... ... ...\n1733 2016-12-26 2016-12-26 2723.50 -0.001283\n1734 2016-12-27 2016-12-27 2701.75 -0.007986\n1735 2016-12-28 2016-12-28 2702.15 0.000148\n1736 2016-12-29 2016-12-29 2727.90 0.009529\n1737 2016-12-30 2016-12-30 2729.80 0.000697\n\n[1738 rows x 4 columns]\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.327462Z", | |
"end_time": "2023-01-16T11:56:42.340862Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "glaxo_df_ci = stats.norm.interval(0.95,\nglaxo_df.gain.mean(), glaxo_df.gain.std())\nprint( 'Gain at 95% confidence interval is:', np.round(glaxo_df_ci, 4)) ", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Gain at 95% confidence interval is: [-0.0258 0.0266]\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:58:33.376953Z", | |
"end_time": "2023-01-16T11:58:33.393451Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "glaxo_df_ci = stats.norm.interval(0.90,glaxo_df.gain.mean(), glaxo_df.gain.std())\nprint( 'Gain at 90% confidence interval is:', np.round(glaxo_df_ci, 4)) ", | |
"execution_count": 20, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Gain at 90% confidence interval is: [-0.0216 0.0224]\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:58:51.677889Z", | |
"end_time": "2023-01-16T11:58:51.693767Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "glaxo_df_ci = stats.norm.interval(0.99,glaxo_df.gain.mean(), glaxo_df.gain.std())\nprint( 'Gain at 99% confidence interval is:', np.round(glaxo_df_ci, 4)) ", | |
"execution_count": 21, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Gain at 99% confidence interval is: [-0.034 0.0348]\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T12:00:00.826738Z", | |
"end_time": "2023-01-16T12:00:00.859057Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "beml_df=pd.read_csv('beml_df.csv')\n\nbeml_df_ci = stats. norm.interval(0.95,beml_df.gain.mean(),beml_df.gain.std())\nprint( 'Gain at 95% confidence interval is:', np.round(beml_df_ci, 4)) ", | |
"execution_count": 22, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Gain at 95% confidence interval is: [-0.0515 0.0521]\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.428487Z", | |
"end_time": "2023-01-16T11:56:42.457732Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# to find z-score value\nstats.norm.ppf(0.975)", | |
"execution_count": 13, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 13, | |
"data": { | |
"text/plain": "1.959963984540054" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.460250Z", | |
"end_time": "2023-01-16T11:56:42.474207Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "stats.norm.ppf(0.995) ", | |
"execution_count": 14, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 14, | |
"data": { | |
"text/plain": "2.5758293035489004" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.476731Z", | |
"end_time": "2023-01-16T11:56:42.490260Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "stats.norm.ppf(0.95) ", | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 15, | |
"data": { | |
"text/plain": "1.6448536269514722" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.495946Z", | |
"end_time": "2023-01-16T11:56:42.506594Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "stats.norm.ppf(0.90) ", | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 16, | |
"data": { | |
"text/plain": "1.2815515655446004" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.507932Z", | |
"end_time": "2023-01-16T11:56:42.529037Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "stats.t.ppf(0.975,139) ", | |
"execution_count": 17, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 17, | |
"data": { | |
"text/plain": "1.977177724476122" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.531608Z", | |
"end_time": "2023-01-16T11:56:42.540036Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "stats.t.interval(0.95,1737 ,glaxo_df.gain.mean() , glaxo_df.gain.std()) ", | |
"execution_count": 18, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 18, | |
"data": { | |
"text/plain": "(-0.025818392673533995, 0.026590474838718584)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-01-16T11:56:42.542132Z", | |
"end_time": "2023-01-16T11:56:42.555836Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "stats.t.interval(0.95,1737 ,beml_df.gain.mean() , beml_df.gain.std()) ", | |
"execution_count": 19, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 19, | |
"data": { | |
"text/plain": "(-0.05156885177136771, 0.052110347929482194)" | |
}, | |
"metadata": {} | |
} | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.9.13", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "Confidence Interval", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment