/
ConfidenceIntervalMeans.Rmd
52 lines (44 loc) · 1.42 KB
/
ConfidenceIntervalMeans.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
title: "Confidence Interval for Means"
params:
xbar: 12.3
sigma: 4
n: 50
confidence: 0.95
jupyter:
kernelspec:
display_name: R
language: R
name: ir
---
```{r params, include=FALSE}
if(!exists("params")) {
params <- list(xbar = 12.3, sigma=4, n=50, confidence=0.95)
}
xbar<-params$xbar
sigma<-params$sigma
n<-params$n
confidence<-params$confidence
```
```{r computed, include=FALSE}
zstar <- -1*qnorm((1.0-confidence)/2.0)
sqrtOfN <- sqrt(n)
E <- zstar * (sigma)/sqrtOfN
xbarMinusE <- xbar - E
xbarPlusE <- xbar + E
```
Find a `r confidence*100`% confidence interval when the sample mean is $\bar x=`r xbar`$, the standard deviation is $\sigma=`r sigma`$ and the sample size is $n = `r n`$.
First we find the E involved, using the confidence level to compute the appropriate critical z-value:
$$\begin{aligned}
E & = (z^\star)\frac{\sigma}{\sqrt{n}} && \text{(the formula)}\\
& = (`r round(zstar,3)`)(\frac{`r sigma`}{\sqrt{`r n`}}) && \text{(plug in values)}\\
& = (`r round(zstar,3)`)(\frac{`r sigma`}{`r round(sqrtOfN,3)`}) && \\
& = (`r round(zstar,3)`)(`r round(sigma/sqrtOfN,3)`) && \\
& = `r round(E,3)` &&
\end{aligned}$$
Then we find the two endpoints:
$$\begin{aligned}
\bar x - E = `r xbar`-`r round(E,3)` = `r round(xbar-E,3)` \\
\bar x + E = `r xbar`+`r round(E,3)` = `r round(xbar+E,3)`
\end{aligned}$$
So the confidence interval is $(`r round(xbarMinusE,3)`,`r round(xbarPlusE,3)`)$