# Logistic regression? multiple categorical and ordinal values to predict binary outcome

I have two hypothetical examples I would love help with:

1) Let's assume you're analyzing the relationship between 10000 high school students' graduation outcome (Y/N; binary) with the letter grades (A-F; ordinal) from each subject (categorical label) they took. Not all students were required to take the same classes, so some students don't have letter grades for certain subjects.

Which model would determine if a high grade in one subject is a better predictor of graduation outcome (and which subject)? Based on my research over the last 3 hours... I was thinking a logistic regression, but I usually do all of this with a calculator and a ton of scratch paper, so I'm not following a ton of the online material regarding Python and r.

2) Building off of this example let's assume there are components of each subject, so in addition to your letter grade in the subject, you also have a letter grade for the component.

Let's take the subject of Math as an example. The components of Math that also receive a letter grade are:

• Algebra
• Lattice multiplication

• Data visualization

• PEMDAS understanding

This is across each subject, but not every component has a letter grade and not all the components are the same. Each subject has a varying number of components.

How could I determine if/which component was the largest predictor of graduation outcome?

Any help is appreciated because I am so tired of thinking about this on my own for hours!

• You are calculating statistics on 10000 students manually using paper and a calculator? You must have a lot of time on your hands. Yes, generally modelling binary outcomes can be well described with a logistic model. All of those components sound like you might want to first perform a factor analysis on the individual components and then load the factor loadings into a model. Or you could possibly perform some sort of hierarchical mixed model with components nested within subjects. May 20, 2017 at 6:23
• jk. I just wanted to acknowledge the sample size wasn't an issue. thanks for the guidance! looking into this now. May 20, 2017 at 6:44
• LOL. No problem. I'd prepare a more complete answer but don't have the time now, but I figured this would give you a good start. Plus I figured a little late night humor couldn't hurt -- or at late night here on the East Coast of the US... May 20, 2017 at 6:50

From what I understand in your question you don't want to predict the graduation outcome but rather check which subject (your variables) grade has the most impact on graduation (As for your question regarding if high grade causes more graduation you can easily make a table or plot for that and check, As expected you'll see people getting higher grades have more Y). To check variable importance/impact there are many ways :

1. Model Specific Methods: These are the methods that check variable impact based on the model built. E.g :
• t-statistic for linear models like logistic regression you said
• In random forest there is an importance function
• Recursive Partitioning, it is the reduction in loss function for each of your variables
• Importance function in xgboost
• varImp function in Multivariate Adaptive Regression Splines(MARS)

And there are more.

1. Second category is model independent tests to check which variable has the most impact:
• The most basic test is to check correlation of the predictors (subject) with your response variable(Y/N). You can see check cor b/w categorical and numeric/categorical columns using the hetcor function in the polycor package in R

• Chi Squares Tests

• Information gain tests

You can google these methods to know more about them and you'll easily find tutorials on how to apply them in R/Python.

As for your second question to do component analysis, I suggest breaking down Math into different columns using one hot encoding(dummy), it will give you 0 if he has not taken the component and 1 if he has, and there will be corresponding graduation outcome for that.( You can find how to do it in R/Python easily on google). Then apply the tests that I said above for each subject individually.

For the first analysis(subject importance one) , I have a question, You said not all people have taken all the subjects, So some values will be missing, what is the amount of those missing values (percentage) in each column. You may have to do imputation if it is large, otherwise just delete them.

As your dependent variable (i.e., graduation) is binary (0/1) you should perform a logistic regression. This will measure the effect of your independent variables (e.g., student's grade, age, gender, etc.) on the probability to graduate. If your data are "structured" (e.g., the students belong to schools themselves nested within geo areas), then you should consider running hierarchical regression (e.g., mixed effects logistic).

In your case I am more concerned by the availability of the information for each student ("Not all students were required to take the same classes, so some students don't have letter grades for certain subjects"). This is an issue if you want to estimate the effect of "letter grade" on graduation, because in standard logistic regression this will be treated as missing values and your corresponding observation will be "automatically" removed from the data set. When you specify your independent variables, try to include only the ones which have a value for most of the students. For example, in your case you could first try to estimate a Logit model linking Proba{Graduation} with "type of classes" => For each subject and each student, you should be able to code a binary variable indicating whether the student took the subject.