12.3.101 two proportion z-test
The numbers of successes and the sample sizes for independent simple random samples from two populations are provided for a left-tailed test and an 80% confidence interval. Complete parts (a) through (d). \(x_1 = 20, n_1 = 50,x_2 = 23, n_2 = 50, \alpha =.10\)
(a). Determine the sample proportion. We use the formula \(\hat{p}= \frac{x}{n}\)
x1 = 20
n1 = 50
p1 = x1/n1
p1## [1] 0.4
\(\hat{p_1} = .4\)
x2 = 23
n2 = 50
p2 = x2/n2
p2## [1] 0.46
round(p2,3)## [1] 0.46
\(\hat{p_2} = .46\)
p = (x1 + x2)/(n1+n2)
p## [1] 0.43
round(p,3)## [1] 0.43
\(\hat{p} = .43\)
(b) Decide whether using the two-proportions z-procedures is appropriate.
There are two conditions for two-proportions z test:
simple random sample
\(x_1,n_1-x_1,x_2,n_2-x_2,\) are 5 are greater
The first condition is passed since the question specifies a simple random sample
To check the second condition we can run
x1 >= 5## [1] TRUE
n1 - x1 >= 5## [1] TRUE
x2 >= 5## [1] TRUE
n2 - x2 >= 5## [1] TRUE
(c).If appropriate, use the two-proportions z-test to conduct the required hypothesis test.What are the hypotheses for this test?. Since this is a left-tailted test, we have
\(H_0:p_1=p_2, H_a:p_1<p_2\)
To compute test statistic z we use the formula \(z=\frac{\hat{p_1}-\hat{p_2}}{\sqrt{\hat{p_p}(1-\hat{p_p})}.\sqrt{(\frac{1}{n_1})+(\frac{1}{n_2})}}\)
z = (p1 -p2)/(sqrt(p*(1-p)) * sqrt(1/n1+1/n2))
z## [1] -0.6059679
Round to two decimal places
round(z,2)## [1] -0.61
Identify the critical value(s), if appropriate. Select the correct choice below and, if necessary, fill in the answer box to complete your answer.
It is a left-tailed test with \(\alpha = .1\), so the area to the left of critical value = .1
To find negative critical value, we run
round(qnorm(.1),2)## [1] -1.28
Since \(-z_{\alpha}=-1.28< z = -.61\) the test statistic does not lie in rejected region. We do not have enough evidence to reject hypothesis.
(d) If appropriate, use the two-proportions z-interval procedure to find the specified confidence interval. Select the correct choice below and, if necessary, fill in the answer boxes to complete your answer.
The 80% confidence interval is from… to…
First approach we calculate confidence interval using margin of error
To calculate margin of error we use formula \(E=z_{\alpha/2}.\sqrt{\frac{\hat{p_1}(1-\hat{p1})}{n_1}+\frac{\hat{p_2}(1-\hat{p2})}{n_2}}\)
Since the confidence level is .8, we have \(\alpha = .2\) and \(\alpha/2=.1\)
alpha = .2
zalpha2 = abs(qnorm(alpha/2))
E = zalpha2 * sqrt(p1*(1-p1)/n1 + p2*(1-p2)/n2)
E## [1] 0.1266598
To calculate the confidence interval, we use the formula \((\hat{p_1}-\hat{p_2}) \pm E\)
(p1-p2) + E## [1] 0.06665983
(p1-p2) - E## [1] -0.1866598
Round to three decimal places
round((p1-p2) + E, 3)## [1] 0.067
round((p1-p2) - E, 3)## [1] -0.187
Second approach: find confidence interval directly without using margin of error E
To calculate the confidence interval, we use the formula \((\hat{p_1}-\hat{p_2}) \pm z_{\alpha/2}.\sqrt{\frac{\hat{p_1}(1-\hat{p_1})}{n_1}+\frac{\hat{p_2}(1-\hat{p_2})}{n_2}}\)
alpha = .2
zalpha2 = abs(qnorm(alpha/2))
(p1-p2) + zalpha2 * sqrt(p1*(1-p1)/n1 + p2*(1-p2)/n2)## [1] 0.06665983
(p1-p2) - zalpha2 * sqrt(p1*(1-p1)/n1 + p2*(1-p2)/n2)## [1] -0.1866598
Round to three decimal places
round((p1-p2) + zalpha2 * sqrt(p1*(1-p1)/n1 + p2*(1-p2)/n2),3)## [1] 0.067
round((p1-p2) - zalpha2 * sqrt(p1*(1-p1)/n1 + p2*(1-p2)/n2),3)## [1] -0.187
Notes: confidence interval is a range of data that contain unknown population and critical value is where we split the data to rejected and non-rejected region
Hope that helps!