# Binary Choice Model
setwd("C:/Course16/EC510/R")
grade<-read.table("http://web.pdx.edu/~crkl/ec510/data/grade.txt",header=T,nrows=32)
summary(grade)
with(grade,table(GRADE))

# linear probability model
m1<-lm(GRADE~GPA+TUCE+PSI,data=grade)
summary(m1)
# confusion table with mean threshold
GRADE.m1<-ifelse(m1$fitted<mean(m1$fitted),0,1)
table(grade$GRADE,GRADE.m1)

# logit model
m2<-glm(GRADE~GPA+TUCE+PSI,family=binomial(link="logit"),data=grade)
summary(m2)
# confusion table with mean threshold
GRADE.m2<-ifelse(m2$fitted<mean(m2$fitted),0,1)
table(grade$GRADE,GRADE.m2)

# probit model
m3<-glm(GRADE~GPA+TUCE+PSI,family=binomial(link="probit"),data=grade)
summary(m3)
# confusion table with mean threshold
GRADE.m3<-ifelse(m3$fitted<mean(m3$fitted),0,1)
table(grade$GRADE,GRADE.m3)

cbind(m1$fitted,m2$fitted,m3$fitted)
cbind(grade$GRADE,GRADE.m1,GRADE.m2,GRADE.m3)
table(grade$GRADE,GRADE.m1,GRADE.m2,GRADE.m3)
