--- title: "Lec 01 code" format: html --- ## Example Here is some data and the normal QQ plot: ```{r} wt <- c(41,34,40,44,33,42,52,38,32,31,31,35, 39,44,42,42,35,33,40,48,51,32,41,35, 38,48,37,35,42,41,40,47,40,46,33,38, 51,39,40) qqnorm(wt) ``` Here we construct a confidence interval for the mean which assumes $\sigma = 5$ is known. ```{r} n <- length(wt) xbar <- mean(wt) alpha <- 0.05 za2 <- qnorm(1-alpha/2) sigma <- 5 lo <- xbar - za2 * sigma / sqrt(n) up <- xbar + za2 * sigma / sqrt(n) ``` The sample mean is $\bar X_n = `r xbar`$. The confidence interval is $[`r lo`,`r up`]$. Now we construct a confidence interval without assuming $\sigma$ is known. ```{r} sn <- sd(wt) ta2 <- qt(1-alpha/2,n-1) lot <- xbar - ta2 * sn/sqrt(n) upt <- xbar + ta2 * sn/sqrt(n) ``` This confidence interval is $[`r lot`, `r upt`]$.