--- title: "STAT 516 Homework 1" author: "Your classmate" date: "01/28/2026" format: html editor: visual --- ```{r} hr <- c(80, 118, 92, 84, 78, 84, 76, 82, 76, 88, 108, 90, 90, 90, 86, 70, 68, 46, 98, 56, 84, 80, 78, 66, 60) ``` # 1) ```{r} qqnorm(hr) qqline(hr) ``` # 2) ```{r} xbar <- mean(hr) sn2 <- var(hr) sn <- sd(hr) ``` The mean of the sample is $\bar X_n = `r xbar`$, the variance is $S_n^2 = `r round(sn2, 4)`$, and the standard deviation is $S_n = `r round(sn, 4)`$. # 3) For a sample with a known standard deviation, the confidence interval of the mean is found by the formula $$ (1-\alpha)100\% \text{ C.I.} = \bar X_n \pm z_{\alpha/2}\frac{\sigma}{\sqrt{n}} $$ ```{r} alpha <- 1 - 0.99; n <- length(hr); sigma <- 16 MoE <- qnorm(1-alpha/2) * sigma / sqrt(n) ``` The $99\% \text{ C.I.}$ of the sample ($\sigma = 16$) is $`r xbar` \pm `r round(MoE, 4)`$. # 4) For a sample with an unknown standard deviation (i.e., using $S_n$ to estimate $\sigma$), the confidence interval of the mean is found by the formula $$ (1-\alpha)100\% \text{ C.I.} = \bar X_n \pm t_{n-1,\ \alpha/2}\frac{S_n}{\sqrt{n}} $$ ```{r} alpha <- 1 - 0.99 sn <- sd(hr) MoE <- qt(1-alpha/2, n-1)*(sn/sqrt(n)) ``` The $99\% \text{ C.I.}$ of the sample is $`r xbar` \pm `r round(MoE, 4)`$. # 5) The minimum number of samples needed to obtain a desired margin of error, $M^*$, is determined by the formula $$ n = \Bigg\lceil \bigg(z_{\alpha/2}\frac{\sigma}{M^*} \bigg)^2 \Bigg\rceil $$ ```{r} MoEs <- 2 alpha <- 1 - 0.95 sigma <- sd(hr) n1 <- ceiling( (qnorm(1-alpha/2) * (sn/MoEs)) ^2 ) ``` Using $S_n = `r round(sn, 4)`$ to estimate $\sigma$, we find that number of samples needed is at least $n =`r n1`$. # 6) ## i) $$ H_0: \mu \le 80 \text{ bpm} $$ $$ H_1: \mu > 80 \text{ bpm} $$ ## ii) $$ T_{stat} = \frac{\bar X_n - \mu_0}{S_n /\sqrt{n}}\\ $$ ```{r} mu0 <- 80 sn <- sd(hr) ts <- (xbar - mu0) / (sn/sqrt(n) ) ``` $$ T_{stat} = `r ts` $$ ## iii) For a one-sided test, $$ \text{Critical Value} = t_{n-1,\ \alpha} $$ ```{r} alpha <- 0.05 tc <- qt(1-alpha, n-1) ``` $$ t_{n-1,\ \alpha} = `r tc` $$ ## iv) We reject $H_0$ if $T_{stat} > t_{n-1,\ \alpha}$. ```{r} ts > tc ``` $T_{stat} \ngtr t_{n-1,\ \alpha}$. Therefore, we fail to reject $H_0$ and conclude that the mean heart rate of this population of students is not significantly greater than 80 bpm. ## v) For a right-tailed test, $$ p = P(T > T_{stat}) $$ ```{r} pval <- pt(-ts, n-1) ``` $$ p = `r pval` $$ # 7) ## i) $$ H_0: \mu = 82 \text{ bpm} $$ $$ H_1: \mu \ne 82 \text{ bpm} $$ ## ii) $$ T_{stat} = \frac{\bar X_n - \mu_0}{S_n /\sqrt{n}}\\ $$ ```{r} mu0 <- 82 ts <- (xbar - mu0) / (sn/sqrt(n) ) ``` $$ T_{stat} = `r ts` $$ ## iii) For a two-sided test, $$ \text{Critical Value} = t_{n-1,\ \alpha/2} $$ ```{r} alpha <- 0.10 tc <- qt(1-alpha/2, n-1) ``` $$ t_{n-1,\ \alpha/2} = `r tc` $$ ## iv) We reject $H_0$ if $|T_{stat}| > t_{n-1,\ \alpha/2}$. ```{r} abs(ts) > tc ``` $|T_{stat}| \ngtr t_{n-1,\ \alpha/2}$.Therefore, we fail to reject $H_0$ and conclude that the mean heart rate of this population of students is not significantly different from 82 bpm. ## v) For a two-tailed test, $$ p = 2*P(T > |T_{stat}|) $$ ```{r} pval <- 2*pt(-abs(ts), n-1) ``` $$ p = `r pval` $$ # 8) For a one-tailed test, $$ n = \Bigg\lceil \sigma^2\bigg(\frac{z_{\alpha}+z_{\beta^*}}{\mu^*-\mu_0} \bigg)^2 \Bigg\rceil $$ ```{r} sigma <- sd(hr) alpha <- 0.05 beta <- 1 - 0.90 za <- qnorm(1-alpha) zb <- qnorm(1-beta) mus <- 77 mu0 <- 75 n_8 <- ceiling(sigma^2 * (za + zb)^2 / (mus - mu0)^2) ``` Given that the true mean of the sample is at least $77 \text{ bpm}$, the number of samples needed to confirm that $\mu > 75 \text{ bpm}$ at significance level $\alpha = 0.05$ and power $\gamma = 0.90$ is $n = `r n_8`$. # 9) For a two-tailed test, $$ n = \Bigg\lceil \sigma^2\bigg(\frac{z_{\alpha/2}+z_{\beta^*}}{\mu^*-\mu_0} \bigg)^2 \Bigg\rceil $$ ```{r} sigma <- sd(hr) alpha <- 0.01 beta <- 1 - 0.80 za <- qnorm(1-alpha/2) zb <- qnorm(1-beta) mus <- 78+2 mu0 <- 78 n_9 <- ceiling(sigma^2 * (za + zb)^2 / (mus - mu0)^2) ``` Given that the true mean of the sample is at least $2 \text{ bpm}$ from $78 \text{ bpm}$, the number of samples needed to confirm that $\mu \ne 78 \text{ bpm}$ at significance level $\alpha = 0.01$ and power $\gamma = 0.80$ is $n = `r n_9`$.