I am trying to write my own predict() function for a logistic regression to understand its function better. Right now I have figured out how to write my own predict function for nominal data. However, I am struggling when it comes to categorical data: i.e., I'd like to type in own_predict_function(object, newdata = data.frame(are = 400, gpa = 2.5, rank = '4'))
and get a result. In this example, rank is the categorical variable with levels 1,2,3,4.
I have already built my own logistic regression that gives the following output for y ~ gre + gpa + rank
If I use the inbuilt function predict(), I only have to factorize the variable rank and then the inbuilt function automatically knows that predict(object, new data = data.frame(rank = "4"))
corresponds to the regression coefficient of rank4. Do you have any advice/hint on how to write your own code for that? I really appreciate your help.