Session13 Ordered Logit

pdf

School

Syracuse University *

*We aren’t endorsed by this school

Course

651

Subject

Statistics

Date

Feb 20, 2024

Type

pdf

Pages

6

Uploaded by PresidentLapwing3845

Report
Ordered Logit Copyright © Don Harter 2019-2023 1 Ordered Logit Data Download the GradSchool spreadsheet from BlackBoard or copy from the G: drive. This data is a UCLA dataset from https://stats.idre.ucla.edu/stata/dae/ordered-logistic-regression/ which looks at factors that influence whether a student applies to graduate school. A survey was done which collected the following information: Will you apply to grad school? very likely (2), somewhat likely (1), unlikely (0) Does a parent have a graduate degree? Yes (1), No (0) Is your undergraduate school public? Yes Public (1), No Private (0) What is your GPA? GPA on a 4.0 scale Why Ordered Logit Logit only allows two options: Ordered Logit allows more the two options: Are you admitted to Masters program? GRE score GPA Yes P(Y=1) No P(Y=0) Income What size fries would you like today? Age Large P(Y=2) Medium P(Y=1) Small P(Y=0)
Ordered Logit Copyright © Don Harter 2019-2023 2 Ordered Logit When there are more than two possible outcomes, logit and probit will not work. For three or more outcomes, the most popular techniques are ordered logit, ordered probit, multinomial logit, multinomial probit, and neural networks. Ordered logit and probit are only used when there is a meaningful order. Examples of problems where ordered logit would work include: What size drink does someone order at McDonalds? Small, Medium, Large What size TV does someone buy at BestBuy? 50 inch, 60 inch, 70 inch What medal does someone win at the Olympics? Gold, Silver, Bronze Which of the following could use ordered logit. Explain why. Which car does someone buy? Toyota, Honda, Chevrolet Which car does someone buy? Toyota Avalon, Toyota Camry, Toyota Corolla Which fruit does someone buy at Wegmans? Apples, Oranges, Bananas Because there are three outcomes to the question “Will you apply to grad school?”, logit and probit will not work. Ordered logit allows more than two outcomes, as long as they have a natural order. If you have more than 5 outcomes, some researcher suggest that you use linear regression. (https://www.statisticshowto.datasciencecentral.com/ordered-logistic-regression/) Installing the necessary modules In the R GUI command screen, copy and run each of the following commands. install.packages("Rcmdr") install.packages("foreign") install.packages("ggplot2") install.packages("MASS") install.packages("Hmisc") install.packages("reshape2") library(Rcmdr) library(foreign) library(ggplot2) library(MASS) library(Hmisc) library(reshape2)
Ordered Logit Copyright © Don Harter 2019-2023 3 Loading the data 1. Using Rcmdr, load the GradSchool data by clicking on Data, Import data, from text file 2. For data set name, enter GradSchool 3. For Field Separator, click on Commas 4. Click OK 5. Locate the file, then click Open. Running Ordered Logit This procedure is documented on the UCLA website: https://stats.idre.ucla.edu/r/dae/ordinal-logistic-regression/ 1. To run Ordered Logit, we will not use Rcmdr, but enter commands directly into R 2. To make this easier, copy the commands from the electronic version of this document 3. To run ordered logit, run the command: m <- polr(ApplyDecision ~ ParentEduc + Public + GPA, data = GradSchool, Hess=TRUE) 4. To print the model, run the command: summary(m) 5. The results will be: Call: polr(formula = ApplyDecision ~ ParentEduc + Public + GPA, data = GradSchool, Hess = TRUE) Coefficients: Value Std. Error t value ParentEduc 1.04769 0.2658 3.9418 Public -0.05879 0.2979 -0.1974 GPA 0.61594 0.2606 2.3632 Intercepts: Value Std. Error t value 0-unlikely|1-somewhat likely 2.2039 0.7795 2.8272 1-somewhat likely|2-very likely 4.2994 0.8043 5.3453 Residual Deviance: 717.0249 AIC: 727.0249 6. To calculate the p values, enter the following commands in order to create a table of coefficients, calculate p-values, the merge the table of coefficients with the p-values (ctable <- coef(summary(m)))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Ordered Logit Copyright © Don Harter 2019-2023 4 7. The results will be: > (ctable <- coef(summary(m))) Value Std. Error t value ParentEduc 1.04769010 0.2657894 3.9418050 Public -0.05878572 0.2978614 -0.1973593 GPA 0.61594057 0.2606340 2.3632399 0-unlikely|1-somewhat likely 2.20391473 0.7795455 2.8271792 1-somewhat likely|2-very likely 4.29936315 0.8043267 5.3452947 8. Now calculate the p-values, then merging coefficients and p-values by entering the following two commands p <- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE) * 2 (ctable <- cbind(ctable, "p value" = p)) 9. The results will be: > p <- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE) * 2 > (ctable <- cbind(ctable, "p value" = p)) Value Std. Error t value ParentEduc 1.04769010 0.2657894 3.9418050 Public -0.05878572 0.2978614 -0.1973593 GPA 0.61594057 0.2606340 2.3632399 0-unlikely|1-somewhat likely 2.20391473 0.7795455 2.8271792 1-somewhat likely|2-very likely 4.29936315 0.8043267 5.3452947 p value ParentEduc 0.00008087071504 Public 0.84354636402255 GPA 0.01811593663406 0-unlikely|1-somewhat likely 0.00469600407196 1-somewhat likely|2-very likely 0.00000009027008 10. Next, create newdata which combines the old data and predictions by entering the following commands newdat <- data.frame( ParentEduc = rep(0:1, 200), Public = rep(0:1, each = 200), GPA = rep(seq(from = 1.9, to = 4, length.out = 100), 4)) newdat <- cbind(newdat, predict(m, newdat, type = "probs"))
Ordered Logit Copyright © Don Harter 2019-2023 5 11. Display the data and predictions by entering head(newdat) 12. The results will be: > head(newdat) ParentEduc Public GPA 0-unlikely 1-somewhat likely 2-very likely 1 0 0 1.900000 0.7376186 0.2204577 0.04192370 2 1 0 1.921212 0.4932185 0.3945673 0.11221424 3 0 0 1.942424 0.7325300 0.2244841 0.04298593 4 1 0 1.963636 0.4866885 0.3984676 0.11484395 5 0 0 1.984848 0.7273792 0.2285470 0.04407383 6 1 0 2.006061 0.4801630 0.4023098 0.11752712 13. Now format the data so we can graph the probabilities by entering lnewdat <- melt(newdat, id.vars = c("ParentEduc", "Public", "GPA"), variable.name = "Level", value.name="Probability") 14. Display the new data and predictions by entering head(lnewdat) 15. The results will be: > head(lnewdat) ParentEduc Public GPA Level Probability 1 0 0 1.900000 0-unlikely 0.7376186 2 1 0 1.921212 0-unlikely 0.4932185 3 0 0 1.942424 0-unlikely 0.7325300 4 1 0 1.963636 0-unlikely 0.4866885 5 0 0 1.984848 0-unlikely 0.7273792 6 1 0 2.006061 0-unlikely 0.4801630
Ordered Logit Copyright © Don Harter 2019-2023 6 16. Finally plot the results by entering ggplot(lnewdat, aes(x = GPA, y = Probability, colour = Level)) + geom_line() + facet_grid(ParentEduc ~ Public, labeller="label_both")
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help