Friday, November 13, 2020

Probit Model

 require(aod)

require(ggplot2)


mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")


## convert rank to a factor (categorical variable)

mydata$rank <- factor(mydata$rank)


## view first few rows


head(mydata)


summary(mydata)


xtabs(~rank + admit, data = mydata) #


myprobit <- glm(admit ~ gre + gpa + rank, family = binomial(link = "probit"), 

                data = mydata)


## model summary

summary(myprobit)


confint(myprobit)


wald.test(b = coef(myprobit), Sigma = vcov(myprobit), Terms = 4:6)


l <- cbind(0, 0, 0, 1, -1, 0) #FOR 4:6 IS 6 VALUE TAKEN

wald.test(b = coef(myprobit), Sigma = vcov(myprobit), L = l)


newdata <- data.frame(gre = rep(seq(from = 200, to = 800, length.out = 100), 

                                4 * 4), gpa = rep(c(2.5, 3, 3.5, 4), each = 100 * 4), rank = factor(rep(rep(1:4, 

                                                                                                            each = 100), 4)))


head(newdata)


newdata[, c("p", "se")] <- predict(myprobit, newdata, type = "response", se.fit = TRUE)[-3]


ggplot(newdata, aes(x = gre, y = p, colour = rank)) + geom_line() + facet_wrap(~gpa)


## change in deviance

with(myprobit, null.deviance - deviance)


## change in degrees of freedom

with(myprobit, df.null - df.residual)


## chi square test p-value

with(myprobit, pchisq(null.deviance - deviance, df.null - df.residual, lower.tail = FALSE))


logLik(myprobit)


0 comments:

Post a Comment