# Author: david@openintro.org (David Diez) # License: Creative Commons Attribution-ShareAlike 4.0 # https://creativecommons.org/licenses/by-sa/4.0/ # # Simulation and Analysis Context # # When a course has an especially high fail rate, faculty # sometimes investigate ways to improve the rate. One strategy # is to gate the class using a preparedness test. # # Suppose we examine a particular course with a high fail rate # where about 25% of students fail the course, and the faculty # last semester had each student take a pre-course test. # The faculty notice that students who performed poorly on # the test seemed to fail at higher rates than students who # scored very well, and they decided that the test will be # worth implementing as a preparedness test for the next # semester. However, they still have a problem: what score # must students get before they are allowed to enter the course? # # The faculty decide that students must have at least # an 80% chance of passing based on the preparedness test. # In other words, the faculty want to determine the score S # such that, if a student gets score S, the student has # an 80% chance of passing. They would also expect that # students who score much higher than S would pass at an # even higher rate. # _____ Load & Plot Class Data _____ # d <- read.csv("pretest_pass-class_data.csv") head(d) dim(d) hist(d$score) table(d$pass) boxplot(d$score ~ d$pass) color <- ifelse(d$pass == 1, "black", "red") plot(d$score, jitter(d$pass), col = color) # _____ Build Model _____ # model <- glm(pass ~ score, data = d, family = binomial) summary(model) # _____ Plot the Model _____ # plot(d$score, d$pass, col = color) d.new <- data.frame(score = seq(0, 100)) fitted <- predict(model, d.new, type = "response", se.fit = TRUE) lower <- fitted$fit - 1.96 * fitted$se.fit upper <- fitted$fit + 1.96 * fitted$se.fit lines(d.new$score, fitted$fit) lines(d.new$score, lower, lty = 3) lines(d.new$score, upper, lty = 3) abline(h = 0.8, lty = 2) cbind(d.new, fitted$fit, lower, upper)