Question 1163125
```python?code_reference&code_event_index=2
import math
from scipy.stats import norm

def calculate_p_value(n, p0, x=None, p_hat=None):
    if p_hat is None:
        p_hat = x / n
    
    # Standard Error
    se = math.sqrt(p0 * (1 - p0) / n)
    
    # Test statistic z
    z = (p_hat - p0) / se
    
    # Round z to 2 decimal places as per instructions
    z_rounded = round(z, 2)
    
    # Lower-tailed p-value
    p_val = norm.cdf(z_rounded)
    
    return {
        "p_hat": round(p_hat, 6),
        "se": round(se, 6),
        "z": round(z, 6),
        "z_rounded": z_rounded,
        "p_value": round(p_val, 4)
    }

p0 = 0.47

results = {
    "a": calculate_p_value(n=118, p0=p0, x=46),
    "b": calculate_p_value(n=311, p0=p0, x=112),
    "c": calculate_p_value(n=53, p0=p0, p_hat=0.38),
    "d": calculate_p_value(n=430, p0=p0, p_hat=0.38)
}

import json
print(json.dumps(results, indent=2))


```
```text?code_stdout&code_event_index=2
{
  "a": {
    "p_hat": 0.389831,
    "se": 0.045946,
    "z": -1.744871,
    "z_rounded": -1.74,
    "p_value": 0.0409
  },
  "b": {
    "p_hat": 0.360129,
    "se": 0.028301,
    "z": -3.8822,
    "z_rounded": -3.88,
    "p_value": 0.0001
  },
  "c": {
    "p_hat": 0.38,
    "se": 0.068557,
    "z": -1.312785,
    "z_rounded": -1.31,
    "p_value": 0.0951
  },
  "d": {
    "p_hat": 0.38,
    "se": 0.024069,
    "z": -3.739296,
    "z_rounded": -3.74,
    "p_value": 0.0001
  }
}

```
To compute the p-values for these lower-tailed hypothesis tests, we use the following steps:
1.  **Calculate the sample proportion ($\hat{p}$):** $\hat{p} = \frac{x}{n}$ (if not already given).
2.  **Calculate the standard error ($SE$):** $SE = \sqrt{\frac{p_0(1 - p_0)}{n}}$ where $p_0 = 0.47$.
3.  **Calculate the test statistic ($z$):** $z = \frac{\hat{p} - p_0}{SE}$.
4.  **Find the p-value:** Since $H_A: p < 0.47$, the p-value is $P(Z \leq z_{rounded})$.

Here are the step-by-step calculations for each part:

### a. $x = 46$; $n = 118$
* **Sample Proportion ($\hat{p}$):** $46 / 118 \approx 0.3898$
* **Standard Error ($SE$):** $\sqrt{\frac{0.47 \times 0.53}{118}} \approx 0.0459$
* **Test Statistic ($z$):** $\frac{0.3898 - 0.47}{0.0459} \approx -1.74$
* **p-value:** $P(Z \leq -1.74) = \mathbf{0.0409}$

### b. $x = 112$; $n = 311$
* **Sample Proportion ($\hat{p}$):** $112 / 311 \approx 0.3601$
* **Standard Error ($SE$):** $\sqrt{\frac{0.47 \times 0.53}{311}} \approx 0.0283$
* **Test Statistic ($z$):** $\frac{0.3601 - 0.47}{0.0283} \approx -3.88$
* **p-value:** $P(Z \leq -3.88) = \mathbf{0.0001}$ (approx.)

### c. $\bar{p} = 0.38$; $n = 53$
* **Sample Proportion ($\hat{p}$):** $0.38$
* **Standard Error ($SE$):** $\sqrt{\frac{0.47 \times 0.53}{53}} \approx 0.0686$
* **Test Statistic ($z$):** $\frac{0.38 - 0.47}{0.0686} \approx -1.31$
* **p-value:** $P(Z \leq -1.31) = \mathbf{0.0951}$

### d. $\bar{p} = 0.38$; $n = 430$
* **Sample Proportion ($\hat{p}$):** $0.38$
* **Standard Error ($SE$):** $\sqrt{\frac{0.47 \times 0.53}{430}} \approx 0.0241$
* **Test Statistic ($z$):** $\frac{0.38 - 0.47}{0.0241} \approx -3.74$
* **p-value:** $P(Z \leq -3.74) = \mathbf{0.0001}$ (approx.)

---
**Final Answers:**
* a. **0.0409**
* b. **0.0001**
* c. **0.0951**
* d. **0.0001**