User: \section{Q4}
[20pt]: A study was conducted to investigate whether a new type of exercise program can improve the average sleep quality of adults, measured in hours per night, compared to the known average sleep quality of 7.2 hours. Fifteen participants were recruited and asked to follow the new exercise program. Their sleep quality (in hours per night) was recorded and stored in the sleep.xlsx file.

\begin{enumerate}[label = (\roman*)]
    \item {[10pt] Test the hypothesis that the new exercise program improves the average sleep quality by at least 0.3 hours per night at a significance level of 0.01. Write down your null and alternative hypotheses.}

    \item {[10pt] If you re-design the experiment (with the same hypotheses as in (a)), how many par-
ticipants in total are you going to recruit to ensure a power of 0.90? For this question, we
assume the standard deviation of sleep quality is 0.8 hours, and the new exercise program
improves the average sleep quality by 0.5 hours per night.}
\end{enumerate}



\section{Q4}
[20pt]: A study was conducted to investigate whether a new type of exercise program can improve the average sleep quality of adults, measured in hours per night, compared to the known average sleep quality of 7.2 hours. Fifteen participants were recruited and asked to follow the new exercise program. Their sleep quality (in hours per night) was recorded and stored in the sleep.xlsx file.

\begin{enumerate}[label = (\roman*)]
    \item {[10pt] Test the hypothesis that the new exercise program improves the average sleep quality by at least 0.3 hours per night at a significance level of 0.01. Write down your null and alternative hypotheses.}

    \item {[10pt] If you re-design the experiment (with the same hypotheses as in (a)), how many par-
ticipants in total are you going to recruit to ensure a power of 0.90? For this question, we
assume the standard deviation of sleep quality is 0.8 hours, and the new exercise program
improves the average sleep quality by 0.5 hours per night.}
\end{enumerate}



\section{Q4}
[20pt]: A study was conducted to investigate whether a new type of exercise program can improve the average sleep quality of adults, measured in hours per night, compared to the known average sleep quality of 7.2 hours. Fifteen participants were recruited and asked to follow the new exercise program. Their sleep quality (in hours per night) was recorded and stored in the sleep.xlsx file.

\begin{enumerate}[label = (\roman*)]
    \item {[10pt] Test the hypothesis that the new exercise program improves the average sleep quality by at least 0.3 hours per night at a significance level of 0.01. Write down your null and alternative hypotheses.}

    \item {[10pt] If you re-design the experiment (with the same hypotheses as in (a)), how many par-
ticipants in total are you going to recruit to ensure a power of 0.90? For this question, we
assume the standard deviation of sleep quality is 0.8 hours, and the new exercise program
improves the average sleep quality by 0.5 hours per night.}
\end{enumerate}
Assistant:  Let'sLet's address each part of the question step-by-step.

---

### Given Information
- Known average sleep quality (population mean before intervention): \(\mu_0 = 7.2\) hours
- Sample size: \(n = 15\)
- Significance level: \(\alpha = 0.01\)
- Standard deviation (for power analysis): \(\sigma = 0.8\)
- Hypothesized improvement: at least 0.3 hours (for hypothesis test), and 0.5 hours (for power analysis)
- The data file **sleep.xlsx** should contain the sleep quality data of the 15 participants after following the exercise program. (You will need to load this data to perform the test.)

---

## (i) Hypothesis Testing to check if new exercise program improves sleep quality by at least 0.3 hours

---

### Step 1: Define the null and alternative hypotheses

The problem states the goal is to test if the program improves the sleep quality by **at least** 0.3 hours. So the hypotheses can be set up as:

\[
H_0: \mu \leq 7.5 \quad \text{(no improvement or less than 0.3 hours improvement)},
\]
\[
H_a: \mu > 7.5 \quad \text{(improvement of more than 0.3 hours)}.
\]

Explanation: Since improvement of at least 0.3 hours means target sleep quality is \(7.2 + 0.3 = 7.5\) hours. The null hypothesis assumes the mean sleep quality is at most 7.5 (no sufficient improvement), the alternative assumes it is greater than 7.5 (meaning sufficient improvement).

---

### Step 2: Calculate sample mean \(\bar{x}\) and sample standard deviation \(s\)

You will read the data from **sleep.xlsx**, then compute:

\[
\bar{x} = \frac{1}{n} \sum_{i=1}^n x_i,
\]
\[
s = \sqrt{\frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2}
\]

---

### Step 3: Perform a one-sample t-test (right-tailed)

The test statistic is:

\[
t = \frac{\bar{x} - 7.5}{s / \sqrt{n}}
\]

The degrees of freedom is \(df = n-1 = 14\).

---

### Step 4: Determine the critical value

At significance level \(\alpha = 0.01\) for a one-sided t-test with df = 14, the critical t-value \(t_{\alpha, df}\) can be obtained from t-distribution tables or software.

---

### Step 5: Decision

- If \(t > t_{\alpha, df}\), reject \(H_0\), conclude the program significantly improves sleep quality by at least 0.3 hours.
- Else, fail to reject \(H_0\).

---

### Summary for Part (i):

\[
\boxed{
\begin{cases}
H_0: \mu \leq 7.5, \\
H_a: \mu > 7.5.
\end{cases}
}
\]

Perform a one-sided t-test. Based on the data in sleep.xlsx, calculate sample mean and sample standard deviation, then compute the test statistic \(t\). Compare to critical value at \(\alpha=0.01\).

---

## (ii) Power Analysis: Calculate required sample size for desired power

---

### Step 1: Define parameters for sample size calculation

- Significance level: \(\alpha = 0.01\), one-sided test
- Power: \(1 - \beta = 0.90\)
- Effect size (true mean difference): \(\delta = 0.5\) hours improvement
- Standard deviation: \(\sigma = 0.8\)
- Null mean: \(\mu_0 = 7.5\) (since testing improvement of 0.3 hours, the test threshold is 7.5)
- Alternative mean: \(\mu_a = 7.2 + 0.5 = 7.7\)

Effectively, the difference to detect is:

\[
d = \mu_a - \mu_0 = 7.7 - 7.5 = 0.2\text{ hours}
\]

---

### Step 2: Calculate standardized effect size

\[
\text{Effect size} = \frac{d}{\sigma} = \frac{0.2}{0.8} = 0.25
\]

Note: This is the **minimum detectable difference** over the null hypothesis mean (7.5). 

---

### Step 3: Use the formula for sample size for one-sample t-test (approximate with z-distribution)

Sample size formula for a one-sided test:

\[
n = \left( \frac{ z_{1-\alpha} + z_{1-\beta} }{ \delta / \sigma } \right)^2
\]

Where:

- \(z_{1-\alpha}\) is the critical z-value for significance level 0.01 (one-sided)
- \(z_{1-\beta}\) is the z-value for power \(1 - \beta = 0.90\)

Lookup values:

- \(z_{1-0.01} = z_{0.99} \approx 2.33\)
- \(z_{0.90} \approx 1.28\)

---

### Step 4: Calculate sample size \(n\)

\[
n = \left( \frac{2.33 + 1.28}{0.25} \right)^2 = \left( \frac{3.61}{0.25} \right)^2 = (14.44)^2 = 208.5
\]

---

Therefore, you would need approximately **209 participants** in total to ensure a power of 0.90 to detect an improvement of 0.5 hours in average sleep quality at \(\alpha=0.01\).

---

**Note:** Since this is a one-sample test, the total sample size equals the group size because it is a single group measured against a known mean.

---

# **Summary**

| Part | Task | Result |
|-------|------|--------|
| (i) | Hypotheses | \( H_0: \mu \leq 7.5 \), \(H_a: \mu > 7.5\) |
| (i) | Test type | One-sided one-sample t-test at \(\alpha=0.01\) |
| (i) | Test statistic | \( t = \frac{\bar{x} - 7.5}{s/\sqrt{15}} \) |
| (ii) | Sample size formula | \( n = \left( \frac{z_{1-\alpha} + z_{1-\beta}}{\delta/\sigma} \right)^2 \) |
| (ii) | Computed sample size | \( \approx 209 \) participants |

---

If you want, I can help with:

- Performing the t-test if you provide the data from **sleep.xlsx**.
- Writing the code in R/Python to perform these calculations.
- More detailed explanation of assumptions or underlying theory.
User: the sample size formula is not taught, use another formula instead.
Assistant: Understood! If the sample size formula using z-values is not taught, we can compute the required sample size using the concepts of **non-central t-distribution**, or more simply, use the relationship involving the **minimum detectable mean difference**, standard deviation, significance level, power, and corresponding critical t-values — often expressed as:

\[
n = \left( \frac{t_{(1-\alpha, \; n-1)} + t_{(1-\beta, \; n-1)}}{\frac{\delta}{s}} \right)^2
\]

But since the sample size \(n\) is unknown and appears on both sides (degrees of freedom), that formula is implicit and more complex to solve manually.

---

### Alternative approach (approximate using t-distribution quantiles from initial guesses):

1. **Step 1: Set your target effect size:**

\[
\text{Effect size} = \frac{\delta}{\sigma} = \frac{0.5}{0.8} = 0.625
\]

where
- \(\delta = 0.5\) is the actual mean difference to detect,
- \(\sigma = 0.8\) is the assumed standard deviation.

2. **Step 2: Use the approximate sample size formula for one-sample t-test**:

\[
n = \left( \frac{t_{1-\alpha, \; n-1} + t_{1-\beta, \; n-1}}{\text{Effect size}} \right)^2
\]

3. **Step 3: Because \(n\) is unknown, use \(z\)-values to approximate initial \(n\)**:

- \(t_{1-\alpha, \infty} \approx z_{1-\alpha} = 2.33\) (for \(\alpha=0.01\)),
- \(t_{1-\beta, \infty} \approx z_{1-\beta} = 1.28\) (for power = 0.90).

Calculate:

\[
n \approx \left(\frac{2.33 + 1.28}{0.625}\right)^2 = \left(\frac{3.61}{0.625}\right)^2 = (5.78)^2 = 33.4
\]

4. **Step 4: Refine degrees of freedom**:

Since the sample size is about 33, we take \(df = n - 1 = 32\) and look up the t-values:

- \(t_{0.99, 32} \approx 2.43\),
- \(t_{0.90, 32} \approx 1.31\).

Recalculate:

\[
n = \left( \frac{2.43 + 1.31}{0.625} \right)^2 = \left( \frac{3.74}{0.625} \right)^2 = (5.98)^2 = 35.8
\]

Try again with \(n=36\), degrees of freedom 35:

- \(t_{0.99, 35} \approx 2.42\),
- \(t_{0.90, 35} \approx 1.31\),

Calculate:

\[
n = \left( \frac{2.42 + 1.31}{0.625} \right)^2 = (5.97)^2 = 35.6,
\]

Stable around 36.

---

### **Final answer:**

You need approximately **36 participants** to ensure a power of 0.90 with significance level 0.01 to detect an improvement of 0.5 hours, assuming the population standard deviation is 0.8 hours.

---

# **Summary for part (ii) without z-formula:**

| Step | Action | Result |
|-|-|-|
| 1 | Calculate effect size \(\delta/\sigma = 0.625\) | 0.625 |
| 2 | Initial guess with z-values | \(n \approx 33\) |
| 3 | Adjust with t-values for df = approx \(n-1\) | \(n \approx 36\) |

You may conclude:

> **Recruit approximately 36 participants to achieve 90% power at 1% significance level.**

---

If you want, I can also help you write out this process step-by-step in your report or provide example code to compute t-values and sample size using iterative methods.
User: why the n is changed?
Assistant: