{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPwQNT9g+XYbgYV8kl2p2UU"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"id":"frr1YmcW88B3","executionInfo":{"status":"ok","timestamp":1717755610510,"user_tz":-330,"elapsed":2359,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}}},"outputs":[],"source":["import numpy as np\n","import scipy.stats as st\n","import pandas as pd\n","import matplotlib.pyplot as plt\n","from statsmodels.stats.proportion import proportions_ztest"]},{"cell_type":"code","source":["print(\"State the null and alternative hypotheses for this problem\\n \")\n","print(\"\\tH0: p = 0.74\")\n","print(\"\\tH1: p =! 0.74 \\n\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"h_Rwki-N9BdH","executionInfo":{"status":"ok","timestamp":1717755610510,"user_tz":-330,"elapsed":19,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}},"outputId":"c1afd0b2-9e42-4ab2-9a65-cbfd6b09ad4d"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["State the null and alternative hypotheses for this problem\n"," \n","\tH0: p = 0.74\n","\tH1: p =! 0.74 \n","\n"]}]},{"cell_type":"code","source":["alpha = 0.05\n","sample_success = 251\n","sample_size = 346\n","null_hypothesis = 0.74\n","stat, p_value = proportions_ztest(count=sample_success, nobs=sample_size, value=null_hypothesis, alternative='two-sided')\n","print('z_stat: %0.3f, p_value: %0.3f' % (stat, p_value))\n","if p_value< alpha:\n","   print (\"Reject null hypothesis\")\n","else:\n","   print (\"Do not Reject null hypothesis\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"IErrnxqX9BgO","executionInfo":{"status":"ok","timestamp":1717755610511,"user_tz":-330,"elapsed":15,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}},"outputId":"edca76a3-8700-426d-9a98-ec0dc901016e"},"execution_count":3,"outputs":[{"output_type":"stream","name":"stdout","text":["z_stat: -0.607, p_value: 0.544\n","Do not Reject null hypothesis\n"]}]},{"cell_type":"code","source":["zcrit95U = st.norm.ppf(q = 0.975)\n","zcrit95L = st.norm.ppf(q = 0.025)\n","mu = 0\n","variance = 1\n","sigma = variance**.5\n","x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100)\n","plt.plot(x, st.norm.pdf(x, mu, sigma))\n","plt.title('Upper Tail T-Test')\n","lineheight = np.linspace(0,.30)\n","xL = len(lineheight) * [zcrit95L]         # X ranges for plotting\n","xU = len(lineheight) * [zcrit95U]\n","xt = len(lineheight) * [stat]\n","plt.plot(xL, lineheight, 'r', label=\"Lower Z Value\")\n","plt.plot(xU, lineheight,'r', label=\"Upper Z Value\")\n","plt.plot(xt, lineheight,'b', label=\"Z Stat\")\n","plt.legend()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":469},"id":"9yTEy2wj9BjH","executionInfo":{"status":"ok","timestamp":1717755610511,"user_tz":-330,"elapsed":12,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}},"outputId":"00a9e0dd-b69b-4132-ac25-a12da2e5d47b"},"execution_count":4,"outputs":[{"output_type":"execute_result","data":{"text/plain":["<matplotlib.legend.Legend at 0x78fa6b89aef0>"]},"metadata":{},"execution_count":4},{"output_type":"display_data","data":{"text/plain":["<Figure size 640x480 with 1 Axes>"],"image/png":"[encoded data, 39356 characters]\n"},"metadata":{}}]},{"cell_type":"code","source":["zcrit95U = st.norm.ppf(q = 0.975)\n","zcrit95L = st.norm.ppf(q = 0.025)\n","fig, ax = plt.subplots()\n","x= np.arange(-4,4,0.001)\n","ax.plot(x, st.norm.pdf(x))\n","ax.set_title(\"Two Tail Test of Porportions\")\n","ax.set_xlabel('Z Values')\n","ax.set_ylabel('pdf(x)')\n","ax.grid(False)\n","# for fill_between\n","px=np.arange(-4,zcrit95L,0.01)\n","px1=np.arange(zcrit95U,4,0.01)\n","ax.set_ylim(0,0.5)\n","ax.fill_between(px,st.norm.pdf(px),alpha=0.5, color='g')\n","ax.fill_between(px1,st.norm.pdf(px1),alpha=0.5, color='g')\n","lineheight = np.linspace(0,.33)\n","xz = len(lineheight) * [stat]\n","plt.plot(xz, lineheight,'b', label=\"Z Stat\")\n","plt.xlabel('Z Values')\n","plt.legend()\n","plt.show()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":472},"id":"3HT75Hie9Bl-","executionInfo":{"status":"ok","timestamp":1717755611581,"user_tz":-330,"elapsed":1076,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}},"outputId":"14a46736-520d-40cc-9c06-6a494bb5e8b3"},"execution_count":5,"outputs":[{"output_type":"display_data","data":{"text/plain":["<Figure size 640x480 with 1 Axes>"],"image/png":"[encoded data, 34024 characters]\n"},"metadata":{}}]},{"cell_type":"code","source":[],"metadata":{"id":"gthdmJ9X9Bom","executionInfo":{"status":"ok","timestamp":1717755611581,"user_tz":-330,"elapsed":6,"user":{"displayName":"Amit Sachan","userId":"17076119069500437280"}}},"execution_count":5,"outputs":[]}]}