document.write( "Question 1165670: A survey of 250 adults showed that 100 of they drank alcohol daily. Calculate
\n" ); document.write( "standard error for the adult population that drink alcohol daily and also calculate
\n" ); document.write( "the error bounds at 95% confidence level. (10 marks)
\n" ); document.write( "(b) You randomly sample 500 sexually active individuals and collect information on
\n" ); document.write( "their HIV status and History of STDs. Using Chi-square test at the 5%
\n" ); document.write( "significance level, is there evidence of a relationship?\r
\n" ); document.write( "
\n" ); document.write( "
\n" ); document.write( "\n" ); document.write( "HIV\r
\n" ); document.write( "\n" ); document.write( "History STDs No Yes Total
\n" ); document.write( "No 92 58 150
\n" ); document.write( "Yes 70 280 350
\n" ); document.write( "Total 162 338 500
\n" ); document.write( "

Algebra.Com's Answer #852947 by CPhill(2189)\"\" \"About 
You can put this solution on YOUR website!
```python?code_reference&code_event_index=2
\n" ); document.write( "import numpy as np
\n" ); document.write( "from scipy.stats import norm, chi2_contingency\r
\n" ); document.write( "\n" ); document.write( "# --- Part (a) Calculations: Standard Error and 95% CI ---
\n" ); document.write( "n_a = 250
\n" ); document.write( "x_a = 100
\n" ); document.write( "p_hat = x_a / n_a\r
\n" ); document.write( "\n" ); document.write( "# 1. Standard Error (SE)
\n" ); document.write( "se_p_hat = np.sqrt(p_hat * (1 - p_hat) / n_a)\r
\n" ); document.write( "\n" ); document.write( "# 2. Z-score for 95% CI
\n" ); document.write( "# Z = 1.96 for 95% confidence
\n" ); document.write( "Z = 1.96\r
\n" ); document.write( "\n" ); document.write( "# 3. Margin of Error (ME)
\n" ); document.write( "me = Z * se_p_hat\r
\n" ); document.write( "\n" ); document.write( "# 4. Confidence Interval Bounds
\n" ); document.write( "ci_lower = p_hat - me
\n" ); document.write( "ci_upper = p_hat + me\r
\n" ); document.write( "\n" ); document.write( "print(f\"Sample Proportion (p_hat): {p_hat}\")
\n" ); document.write( "print(f\"Standard Error (SE): {se_p_hat}\")
\n" ); document.write( "print(f\"Margin of Error (ME): {me}\")
\n" ); document.write( "print(f\"95% CI Lower Bound: {ci_lower}\")
\n" ); document.write( "print(f\"95% CI Upper Bound: {ci_upper}\")\r
\n" ); document.write( "\n" ); document.write( "# --- Part (b) Calculations: Chi-square Test of Independence ---
\n" ); document.write( "# Observed data (O)
\n" ); document.write( "# Rows: No HIV, Yes HIV
\n" ); document.write( "# Cols: No STDs, Yes STDs
\n" ); document.write( "observed = np.array([[92, 58],
\n" ); document.write( " [70, 280]])\r
\n" ); document.write( "\n" ); document.write( "# Perform Chi-square test of independence
\n" ); document.write( "chi2_stat, p_value, dof, expected = chi2_contingency(observed)\r
\n" ); document.write( "\n" ); document.write( "print(\"\nChi-square Test Results:\")
\n" ); document.write( "print(f\"Chi-square statistic: {chi2_stat}\")
\n" ); document.write( "print(f\"P-value: {p_value}\")
\n" ); document.write( "print(f\"Degrees of Freedom (dof): {dof}\")
\n" ); document.write( "print(f\"Expected Frequencies:\n{expected}\")\r
\n" ); document.write( "\n" ); document.write( "```\r
\n" ); document.write( "\n" ); document.write( "```text?code_stdout&code_event_index=2
\n" ); document.write( "Sample Proportion (p_hat): 0.4
\n" ); document.write( "Standard Error (SE): 0.030983866769659335
\n" ); document.write( "Margin of Error (ME): 0.060728378868532294
\n" ); document.write( "95% CI Lower Bound: 0.33927162113146775
\n" ); document.write( "95% CI Upper Bound: 0.4607283788685323\r
\n" ); document.write( "\n" ); document.write( "Chi-square Test Results:
\n" ); document.write( "Chi-square statistic: 80.02645502645503
\n" ); document.write( "P-value: 3.694302007277756e-19
\n" ); document.write( "Degrees of Freedom (dof): 1
\n" ); document.write( "Expected Frequencies:
\n" ); document.write( "[[ 48.6 101.4]
\n" ); document.write( " [113.4 236.6]]\r
\n" ); document.write( "\n" ); document.write( "```\r
\n" ); document.write( "\n" ); document.write( "### (a) Standard Error and Confidence Bounds\r
\n" ); document.write( "\n" ); document.write( "This calculation pertains to the population proportion ($\hat{p}$) of adults who drink alcohol daily.\r
\n" ); document.write( "\n" ); document.write( "**Given:**\r
\n" ); document.write( "\n" ); document.write( " * Sample size ($n$): 250
\n" ); document.write( " * Number who drink daily ($x$): 100
\n" ); document.write( " * Sample proportion ($\hat{p}$): $\hat{p} = \frac{100}{250} = \mathbf{0.40}$\r
\n" ); document.write( "\n" ); document.write( "#### 1\. Standard Error (SE)\r
\n" ); document.write( "\n" ); document.write( "The standard error of the sample proportion measures the typical distance that the sample proportion ($\hat{p}$) falls from the true population proportion.\r
\n" ); document.write( "\n" ); document.write( "$$SE_{\hat{p}} = \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}} = \sqrt{\frac{0.40 \times 0.60}{250}} = \sqrt{0.00096}$$\r
\n" ); document.write( "\n" ); document.write( "$$\mathbf{SE_{\hat{p}} \approx 0.0310}$$\r
\n" ); document.write( "\n" ); document.write( "#### 2\. Error Bounds at 95% Confidence Level\r
\n" ); document.write( "\n" ); document.write( "The error bounds (Margin of Error, ME) are calculated using the Z-score for 95% confidence, which is $Z_{0.025} = 1.96$.\r
\n" ); document.write( "\n" ); document.write( "$$\text{ME} = Z \times SE_{\hat{p}} = 1.96 \times 0.03098$$\r
\n" ); document.write( "\n" ); document.write( "$$\mathbf{\text{ME} \approx 0.0607}$$\r
\n" ); document.write( "\n" ); document.write( "The 95% confidence interval (CI) is $\hat{p} \pm ME$:
\n" ); document.write( "$$\text{CI} = 0.40 \pm 0.0607$$\r
\n" ); document.write( "\n" ); document.write( "$$\text{Lower Bound} \approx \mathbf{0.3393}$$
\n" ); document.write( "$$\text{Upper Bound} \approx \mathbf{0.4607}$$\r
\n" ); document.write( "\n" ); document.write( "**Interpretation:** We are 95% confident that the true percentage of the adult population that drinks alcohol daily is between **33.93% and 46.07%**.\r
\n" ); document.write( "\n" ); document.write( "-----\r
\n" ); document.write( "\n" ); document.write( "### (b) Chi-square Test of Independence\r
\n" ); document.write( "\n" ); document.write( "We use the Chi-square ($\chi^2$) test of independence to determine if there is a statistically significant relationship between HIV status and history of STDs.\r
\n" ); document.write( "\n" ); document.write( "**Observed Frequencies ($O$):**\r
\n" ); document.write( "\n" ); document.write( "| | No STDs | Yes STDs | Total |
\n" ); document.write( "| :---: | :---: | :---: | :---: |
\n" ); document.write( "| **No HIV** | 92 | 58 | 150 |
\n" ); document.write( "| **Yes HIV** | 70 | 280 | 350 |
\n" ); document.write( "| **Total** | 162 | 338 | 500 |\r
\n" ); document.write( "\n" ); document.write( "#### 1\. Hypotheses\r
\n" ); document.write( "\n" ); document.write( " * $H_0$: HIV status and History of STDs are **independent** (no relationship).
\n" ); document.write( " * $H_a$: HIV status and History of STDs are **dependent** (there is a relationship).
\n" ); document.write( " * Significance level ($\alpha$): 0.05\r
\n" ); document.write( "\n" ); document.write( "#### 2\. Expected Frequencies ($E$) and Test Statistic\r
\n" ); document.write( "\n" ); document.write( "The test compares the observed frequencies ($O$) to the expected frequencies ($E$), which are calculated assuming the null hypothesis of independence is true.\r
\n" ); document.write( "\n" ); document.write( "**Expected Frequencies:**\r
\n" ); document.write( "\n" ); document.write( "| | No STDs | Yes STDs |
\n" ); document.write( "| :---: | :---: | :---: |
\n" ); document.write( "| **No HIV** | 48.6 | 101.4 |
\n" ); document.write( "| **Yes HIV** | 113.4 | 236.6 |\r
\n" ); document.write( "\n" ); document.write( "The **Chi-square test statistic ($\chi^2$)** is calculated based on the differences between observed and expected values:
\n" ); document.write( "$$\chi^2 = \sum \frac{(O - E)^2}{E}$$\r
\n" ); document.write( "\n" ); document.write( "The calculated $\chi^2$ statistic is:
\n" ); document.write( "$$\mathbf{\chi^2 \approx 80.026}$$\r
\n" ); document.write( "\n" ); document.write( "#### 3\. Degrees of Freedom (dof) and P-value\r
\n" ); document.write( "\n" ); document.write( " * **Degrees of Freedom (dof):** $\text{dof} = (\text{Rows} - 1)(\text{Columns} - 1) = (2 - 1)(2 - 1) = \mathbf{1}$
\n" ); document.write( " * **P-value:** The probability of observing a $\chi^2$ value as extreme as $80.026$ (or more extreme) under the null hypothesis is:
\n" ); document.write( " $$\mathbf{p\text{-value} \approx 3.69 \times 10^{-19}}$$\r
\n" ); document.write( "\n" ); document.write( "#### 4\. Conclusion\r
\n" ); document.write( "\n" ); document.write( "We compare the p-value to the significance level $\alpha$:
\n" ); document.write( "$$\text{P-value } (3.69 \times 10^{-19}) \ll \alpha (0.05)$$\r
\n" ); document.write( "\n" ); document.write( "Since the p-value is extremely small (far less than $0.05$), we **reject the null hypothesis ($H_0$)**.\r
\n" ); document.write( "\n" ); document.write( "**Conclusion:**
\n" ); document.write( "At the $5\%$ significance level, there is **strong evidence of a statistically significant relationship** between HIV status and history of STDs. The two variables are dependent.
\n" ); document.write( "
\n" );