Practice 12 Conducting One and Two-proportion Tests in R

12.1 Directions


In this practice exercise, you will conduct conduct one and two-proportion tests in R.

12.2 A closer look at the code


12.2.1 One-sample Proportion test

About 42.3% of Californians and 19.6% of all Americans over age five speak a language other than English. A researcher conducts a survey of 1,500 Wisconsin residents of which 7.3% could speak a language other than English. Conduct a hypothesis test to determine if the percent of the Wisconsin residents who speak a language other than English is different from 42.3%.

12.2.1.1 What do we know?

The following is given in the question:

  1. The null hypothesis is \(P_{WI} = 0.423\)
  2. The sample proportion for WI is 0.073
  3. The sample size is 1,500

Let’s put this into r:

n <- 1500
p.WI <- 0.073
p.null <- 0.423

12.2.1.2 Conduct the test

To conduct a test, we need the to use the prop.test().

prop.test() needs the following arguments

  • x the number of successes
  • n the number of trials
  • alternative which can be set to “two.sided” for \(=/\ne\) hypothesis tests, “greater” for \(=/>\) hypothesis tests, or “less” for \(=/<\) hypothesis tests.
  • conf.level the confidence level of the returned confidence interval
prop.test(x=p.WI*n,n=n,p=p.null,alternative = "two.sided", conf.level = 0.95)
## 
##  1-sample proportions test with continuity correction
## 
## data:  p.WI * n out of n, null probability p.null
## X-squared = 751.42, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.423
## 95 percent confidence interval:
##  0.06059296 0.08764350
## sample estimates:
##     p 
## 0.073

With a p-value of \(2.2e-16\), we reject the null hypothesis.

BONUS if alternative = "two.sided" then the 95 percent confidence interval: returned by prop.test() is the confidence interval for the sample proportion.

12.2.2 Two-sample Proportion test

Two types of medication for hives are being tested to determine if there is a difference in the proportions of adult patient reactions. Twenty out of a random sample of 200 adults given medication A still had hives 30 minutes after taking the medication. Twelve out of another random sample of 200 adults given medication B still had hives 30 minutes after taking the medication. Test at a 1% level of significance.

12.2.2.1 What do we know?

The following is given in the question:

  1. The null hypothesis is \(P_{WI} = 0.423\)
  2. The sample proportion for WI is 0.073
  3. The sample size is 1,500

Let’s put this into r:

p.A <- 20     # Number of adults given medication A who still had hives 30 minutes after taking the medication.
n.A <- 200    # Number of adults given medication A 
p.B <- 12     # Number of adults given medication B who still had hives 30 minutes after taking the medication.
n.B <- 200    # Number of adults given medication B
alpha <- 0.01 # 1% level of significance

12.2.2.2 Conduct the test

To conduct a test, we need the to use the prop.test() and the c() command

prop.test(x=c(p.A,p.B),n=c(n.A,n.B),alternative = "two.sided", conf.level = 1-alpha)
## 
##  2-sample test for equality of proportions with continuity correction
## 
## data:  c(p.A, p.B) out of c(n.A, n.B)
## X-squared = 1.6644, df = 1, p-value = 0.197
## alternative hypothesis: two.sided
## 99 percent confidence interval:
##  -0.03469035  0.11469035
## sample estimates:
## prop 1 prop 2 
##   0.10   0.06
With a p-value of 0.197, we fail to reject the null hypothesis and conclude that there is insufficient evidence to conclude there is a significant difference between the sample proportions. ## Now you try

Use R to complete the following activities (this is just for practice you do not need to turn anything in).

Researchers conducted a study of smartphone use among adults. A cell phone company claimed that iPhone smartphones are more popular with whites (non-Hispanic) than with African Americans. The results of the survey indicate that of the 232 African American cell phone owners randomly sampled, 5% have an iPhone. Of the 1,343 white cell phone owners randomly sampled, 10% own an iPhone. Test at the 5% level of significance. Is the proportion of white iPhone owners greater than the proportion of African American iPhone owners? (See EXAMPLE 10.10)