There are many good tutorials on logistic regression in R on the web. A couple tutorials that helped me are here and here. You want to merge the two data sets so that you end up with the number of passes and the number of failures for each school by race. The glm function will perform the logistic regression. The race variable will be interpreted as factors. A summary report will give you the coefficients and the significance of each variable. Halfway through the second tutorial there is a good demonstration on generating probability predictions.
Here is a stab at it with some random data. Additional school parameters can be included by updating the model formula.
# -- Generate some fake data
#random school data for 30 schools
schools.num = 30
schools.data = data.frame(school_id=seq(1,schools.num)
,tot_white=sample(100:300,schools.num,TRUE)
,tot_black=sample(100:300,schools.num,TRUE)
,tot_asian=sample(100:300,schools.num,TRUE)
,school_rev=sample(4e6:6e6,schools.num,TRUE)
)
#total students in each school
schools.data$tot_students = schools.data$tot_white + schools.data$tot_black + schools.data$tot_asian
#sum of all students all schools
tot_students = sum(schools.data$tot_white, schools.data$tot_black, schools.data$tot_asian)
#generate some random failing students
failed.num = as.integer(tot_students * 0.05)
students = data.frame(student_id=sample(seq(1:tot_students), fail.num, FALSE)
,school_id=sample(1:schools.num, fail.num, TRUE)
,race=sample(c('white', 'black', 'asian'), fail.num, TRUE)
)
# -- end fake data
#roll-up the number of failed students by school
#count the number of students using the length function
failed = aggregate(list(failed=students$student_id),by=list(school_id=students$school_id,race=students$race),FUN=length)
#merge the failure data with the school data
schools.test = merge(schools.data,failed,by.x="school_id",by.y="school_id")
#compute the proportion of students by race
schools.test$pct_white = schools.test$tot_white/schools.test$tot_students
schools.test$pct_black = schools.test$tot_black/schools.test$tot_students
schools.test$pct_asian = schools.test$tot_asian/schools.test$tot_students
#Get the number of passed students
schools.test$passed=0
race.totals = c('tot_white','tot_black','tot_asian')
race.factors = c('white','black','asian')
for (i in 1:3){
mask = schools.test$race==race.factors[i]
schools.test$passed[mask] = schools.test[,race.totals[i]][mask] - schools.test$failed[mask]
}
#modify the default base race factor
schools.test$race = relevel(schools.test$race,ref='white')
#compute the logistic regression
fit.formula = cbind(failed,passed)~race+school_rev+pct_white+pct_black+pct_asian
fit = glm(fit.formula, data=schools.test, family=binomial(link='logit'))
print(summary(fit))
print(anova(fit))
par(mfrow=c(2,2))
plot(fit)