Conditional Logistic Regression? Firstly, I am new to all of this.
I am currently trying to predict the chance of different students finishing top of their class. Students will be separated into different groups depending on the class they are in (class id), and obviously only one student can finish top of each class (top of class=1, not top of class=0). I have 5 potential variables based on previous scores in past exams, the student's attendance etc
From the basic research I have done, this seems like it would be a conditional logisitic regression, is that correct?
Is it possible to run a conditional logistic regression when there are a different number of students in each class? For example, class 1 has 35 students, class 2 has 18 students, class 3 has 26 students etc.
If so, what would be the best approach for doing this moving forward, what is the best software/package for using conditional logistic regression? I have found lots of support for logistic regression online but not for conditional logistic regression.
Thanks
 A: As discussed in the comments, you have a dataset of exam scores from previous years. It makes more sense to build a model for predicting a student's final exam score based on various covariates (previous exam scores, attendance, etc.), then use this to predict the probability each student finishes top of their current class.
For simplicity, suppose that you're using a linear regression model for the exam scores. You can estimate the desired probabilities with a simple simulation scheme.
Consider the 35 students from Class 1. If $\hat{y}_i$ is the predicted score for the $i$th student and $\hat{\sigma}_{y_i}$ the associated standard error, you can draw a sample $\tilde{Y}_i^{(1)}\sim\mathcal{N}(\hat{y}_i, \hat{\sigma}_{y_i})$, $i=1,\ldots,35$, from the forecast distribution.
Now repeat the process $N$ times (some large number) and look at how many times each student finishes top of the class.
A: I agree that when there's a continuous outcome followed by ranking, an approach that first predicts the continuous outcome will often be a good idea, because the model gets more information than just a single choice. So, the below is not what I would do in practice, but to theoretically answer the original question, see the below.
However, if one wanted to directly model the "will X get the highest value" as an indicator (1 = highest value, 0 = not), this would still not be a conditional logistic regression. The issue is that the observations in a group are not independent. In your example, one student could be fantastic and predicted to do better than everyone else in their class, but if you add in another similar (or even better) student, then this still reduces their probability of having the highest scores in the class. I.e. this is rather more like a categorical distribution over the students in a class.
A logistic regression with one student as one observation will not capture this correctly, even if you create features like percentile of score, how many students had better previous scores etc. or add a class random effect, because it can still inherently predict that more than 1 student per class gets the best result in the class. Doing this as a conditional logistic regression that conditions on there being just one top result per class does not resolve that. It correctly reflects (and conditions on) that in the training data there happen to only be one top result per class, but when you ask that model to predict there is no immediately obvious way to respect this constraint (which a categorical distribution will respect).
For software to model categorical data, my first thought would be the categorical family of distributions from the brms R package, but you'd still need to find some tricks to somehow reflect the varying numbers of students per class. Perhaps a 0 offset for students that exist and then for "additional virtual students that don't exist" - i.e. the number up to the maximum class size - a huge negative offset on the logit scale would be a brutal but usable option, you'd probably also want no intercept in a model, because the ID number given to students shouldn't matter and you want all prediction to come from the explanatory covariates.
