The North Carolina State University Chemical Engineering Department looked at factors that might affect the pass rates in one of their introductory classes. Below is a two way table that shows the pass rates for students from rural areas, versus students from urban areas.

results <- matrix(c(30, 52, 25, 13), nrow = 2, byrow = TRUE)
colnames(results) = c("Rural", "Urban/Suburban")
rownames(results) = c("Pass", "Failed")
results
##        Rural Urban/Suburban
## Pass      30             52
## Failed    25             13

To make a graph that compares the percent of students that passed in each group, you first need to make a table of column proportions. Then you can make a barplot for that table.

col.props <- prop.table(results, margin = 2) # Use margin = 1 for row proportions, 2 for column proportions. 
barplot(col.props, ylab = "Proportion", legend = T)

Hypothesis Test for Proportions

We can use the R command prop.test() to test the following hypotheses.

prop.test(c(30, 52), c(55, 65))
## 
##  2-sample test for equality of proportions with continuity correction
## 
## data:  c(30, 52) out of c(55, 65)
## X-squared = 7.783, df = 1, p-value = 0.005274
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.43495253 -0.07413838
## sample estimates:
##    prop 1    prop 2 
## 0.5454545 0.8000000

Another Example

Another factor they looked at was gender. Here are the results for gender versus pass rate.