<- c(145, 165, 134, 167, 158, 176, 156, 189, 143, 123)
obs <- replicate(1000, {
mboot <- sample(obs, size=10, replace=TRUE)
x mean(x)
})hist(mboot)
## 95% confidence interval
quantile(mboot, c(0.025, 0.975))
2.5% 97.5%
144.6 167.5
Exercise 1 You measure the Hb value in 10 50-year old men and get the following observations; 145, 165, 134, 167, 158, 176, 156, 189, 143, 123 g/L.
<- c(145, 165, 134, 167, 158, 176, 156, 189, 143, 123)
obs <- replicate(1000, {
mboot <- sample(obs, size=10, replace=TRUE)
x mean(x)
})hist(mboot)
## 95% confidence interval
quantile(mboot, c(0.025, 0.975))
2.5% 97.5%
144.6 167.5
<- mean(obs)) (m
[1] 155.6
<- var(obs)) (v
[1] 395.1556
<- sd(obs)) (s
[1] 19.87852
The sample size is small (\(n=10\)) and the population standard deviation unknown, hence we use the t-statistic;
\[T = \frac{\bar X - \mu}{\frac{s}{\sqrt{n}}}\] and compute the 95% confidence interval as
\[\mu = m \pm t_{\alpha/2} \frac{s}{\sqrt{n}}\]
<- length(obs)
n <- qt(0.975, df=9)
t ##95% confidence interval
c(m - t*s/sqrt(n), m + t*s/sqrt(n))
[1] 141.3798 169.8202
Exercise 2 The 95% confidence interval for a proportion can be computed using the formula \(\pi = p \pm z SE,\) where \(\pi\) is the population prportion, \(p\) the sample proportion and the standard error \(SE = \sqrt{\frac{p(1-p)}{n}}\). \(z=1.96\) for a 95% confidence interval.
We study the proportion of pollen allergic people in Uppsala and in a random sample of size 100 observe 42 pollen allergic people.
See lecture notes
Calculate a 90% confidence interval instead. Or sample more people than 100.
Change the z number,
\[\pi = p \pm z SE\]
For a 90% confidence interval use z=1.64
<- 0.42
p <- 100
n <- sqrt(p*(1-p)/n)
SE <- qnorm(0.95)
z c(p - z*SE, p + z*SE)
[1] 0.3388168 0.5011832
<- qnorm(0.995)
z c(p - z*SE, p + z*SE)
[1] 0.2928678 0.5471322
Exercise 3 A scale has a normally distributed error with mean 0 and standard deviation 2.3 g. You measure an object 10 times and observe the mean weight 43 g.
The measured weight is a random variable \(X \sim N(\mu, \sigma)\). You know that \(\sigma = 2.3\), \(\mu\) is the weight of the object.
## 95% confidence interval
<- 42
m <- 2.3
sigma <- 10
n <- qnorm(0.975)
z c(m - z*sigma/sqrt(10), m + z*sigma/sqrt(10))
[1] 40.57447 43.42553
<- qnorm(0.95)
z c(m - z*sigma/sqrt(10), m + z*sigma/sqrt(10))
[1] 40.80366 43.19634
Exercise 4 You observe 150 students at BMC of which 25 are smokers. Compute a 95% confidence interval for the proportion of smokers among BMC students.
Point estimate of proportion smokers; \(p=25/150=1/6\).
\(\pi = p \pm z SE\)
<- 25/150
p <- 150
n <-qnorm(0.975)
z <- sqrt(p*(1-p)/n)
SE ## 95% CI
c(p - z*SE, p + z*SE)
[1] 0.1070269 0.2263065