Below are the commands and answers for the in-class handout.
Find the proportion of students in the sample who changed majors:
399/950
## [1] 0.42
So \(\hat{p}=.042\).
Find the standard error for \(\hat{p}\):
sqrt(.42*(1-.42)/950)
## [1] 0.01601315
So \(SE_{\hat{p}}=.016\).
Find \(z^*\) for the 90% confidence interval:
xqnorm(.95)
## P(X <= 1.64485362695147) = 0.95
## P(X > 1.64485362695147) = 0.05
## [1] 1.644854
So \(z^*=1.645\).
Find the margin of error for the 90% confidence interval:
1.645*.016
## [1] 0.02632
So \(m=.02632\)
Find the 90% confidence interval for \(p\):
.42-.02632
## [1] 0.39368
.42+.02632
## [1] 0.44632
The 90% confidence interval for \(p\) is \((.39368, .44632)\).
The 90% confidence interval in terms of percentages is \((39.368%, 44.632%)\).
.39368*37500
## [1] 14763
.44632*37500
## [1] 16737
The 90% confidence interval in terms of number of students is \((14763, 16737)\).
We will use the formula \(\left(\frac{z^*}{m}\right)^2p^*(1-p^*)\), where \(p^*\) is a guessed value for the proportion of successes in the future sample. For this example we can use \(p^*=\hat{p}=.42\):
(1.645/.02)^2*.42*(1-.42)
## [1] 1647.969
We should use a sample of \(1648\) students to obtain a margin of error of approximately \(.02\).
\(H_0: p=.45\)
\(H_a: p<.45\)
Compute the \(z\) statistic:
(.42-.45)/sqrt(.45*(1-.45)/950)
## [1] -1.858641
So \(z=-1.85641\).
Find the corresponding \(P\)-value:
xpnorm(-1.859)
##
## If X ~ N(0,1), then
##
## P(X <= -1.859) = P(Z <= -1.859) = 0.0315
## P(X > -1.859) = P(Z > -1.859) = 0.9685
## [1] 0.03151357
The \(P\)-value is \(.0315\).
The \(P\)-value is less than \(.05\), which means that we have enough evidence at the 5% significance level supporting the claim of the tour guide.
prop.test(399, 950, p=.45, alternative="less")
##
## 1-sample proportions test with continuity correction
##
## data: 399 out of 950
## X-squared = 3.3344, df = 1, p-value = 0.03392
## alternative hypothesis: true p is less than 0.45
## 95 percent confidence interval:
## 0.0000000 0.4470594
## sample estimates:
## p
## 0.42
The \(P\)-value from the test is different from the \(P\)-value we found.
prop.test(399, 950, p=.45, conf.level=.9)
##
## 1-sample proportions test with continuity correction
##
## data: 399 out of 950
## X-squared = 3.3344, df = 1, p-value = 0.06785
## alternative hypothesis: true p is not equal to 0.45
## 90 percent confidence interval:
## 0.3934041 0.4470594
## sample estimates:
## p
## 0.42
The 90% confidence interval from the test is also not quite the same as the interval we found.
Repeat the test with the continuity correction turned off:
prop.test(399, 950, p=.45, alternative="less", correct=F)
##
## 1-sample proportions test without continuity correction
##
## data: 399 out of 950
## X-squared = 3.4545, df = 1, p-value = 0.03154
## alternative hypothesis: true p is less than 0.45
## 95 percent confidence interval:
## 0.00000 0.44653
## sample estimates:
## p
## 0.42
The \(P\)-value in the output is the same as the value we found in question 2.
prop.test(399, 950, p=.45, correct=F)
##
## 1-sample proportions test without continuity correction
##
## data: 399 out of 950
## X-squared = 3.4545, df = 1, p-value = 0.06308
## alternative hypothesis: true p is not equal to 0.45
## 95 percent confidence interval:
## 0.3889986 0.4516458
## sample estimates:
## p
## 0.42
The 90% confidence interval in the output is the same as the one we found in question 1.
We can use the \(P\)-value from the test inside the xqnorm command to find the value of the \(z\) statistic.
xqnorm(.03154)
## P(X <= -1.85862719226929) = 0.03154
## P(X > -1.85862719226929) = 0.96846
## [1] -1.858627
So \(z=-1.8586\) which is almost the same as in question 2.