Install the Mosaic package, if necessary.

install.packages("mosaic")

We are going to follow the Joliet Junior College Math Redesign Program (MRP) scenario presented on page 11.1A-1. Enter the data in Table 1 using the do command. Use the tally command to view the contingency table. Note that putting “Outcome” first in the tally command makes “Outcome” the row variable (so “Course” is the column variable).

library(mosaic)
Algebra <- rbind(
  do(19)*data.frame(Course="MRP",Outcome="Pass"),
  do(14)*data.frame(Course="Traditional",Outcome="Pass"),
  do(5)*data.frame(Course="MRP",Outcome="Fail"),
  do(10)*data.frame(Course="Traditional",Outcome="Fail")
)
tally(~Outcome+Course,data=Algebra)
##        Course
## Outcome MRP Traditional
##    Fail   5          10
##    Pass  19          14

Let’s get the pass rates by course using the tally command.

tally(~Outcome|Course,format="proportion",data=Algebra,margins=TRUE)
##        Course
## Outcome       MRP Traditional
##   Fail  0.2083333   0.4166667
##   Pass  0.7916667   0.5833333
##   Total 1.0000000   1.0000000

Among the students in MRP, the proportion who passed is 0.792; among the students in the traditional course, the proportion who passed is 0.583. The difference in the pass rates is \(\frac{19}{24} - \frac{14}{24}\) = = 0.208.

Note Be careful with rounding.

We want to know if this is evidence to suggest the pass rate in the MRP course is higher than that in the traditional course. We are testing

\(H_0: p_{MRP} = P_{Trad}\)
\(H_1: p_{MRP} > p_{Trad}\)

We will randomly assign course to outcome 5000 times. Then, determine the proportion of random assignments that result in a difference in pass rate of 0.209 or higher.

set.seed(445)    #Use a seed to get the same results. 
Random <- do(5000)*diffprop(Outcome ~ shuffle(Course),data = Algebra)
head(Random,n=4)
##     diffprop
## 1 0.20833333
## 2 0.12500000
## 3 0.04166667
## 4 0.20833333
histogram(~diffprop,data=Random,width=0.10,main="Randomized Difference in Proportions",v=0.208)

prop(~(diffprop >= 0.208),data=Random)
## prop_TRUE 
##    0.1056

The P-value is approximately 0.1056. If course and outcome are not associated, we would expect to see a difference in pass rates of 0.208 or higher in about 10 of every 100 repetitions of this study.