2

I am going through "Applied Logistic Regression" by Hosmer, Lemeshow and Sturdivant, concretely chapter 8, multinomial logistic regression. I've built a model:

>library(nnet)  
>library(aplore3); data(aps)  
>fit <- multinom(place3 ~ danger, data = aps)     

I got coefficients that match those in the book. My problem is when I try to make predictions: it just stacks everything in the level that is the most frequent in the data, and zero in other levels. I used code:

>preds <- predict(fit, newdata = data.frame(danger = aps$danger),type = "class")   
>table(preds)   
 OutDay    Int    Res    
  508       0      0       

I've searched the web and got to the nice r-bloggers post and the function described there kind of sorted the thing out, with the same fit I got

predictions  
Int OutDay    Res    
132    262    114 

But I searched the web further because I wanted to read more about the use of the predict function with multinom so I ran into some examples like this one on github where the poster uses predict in the straightforward way. I replicated the example and got everything OK.
My final question is if someone can explain when to use the predict with multinom object in the complicated (r-bloggers' post) way and when to use it in the straightforward way. Is the difference that in my example I am trying to get out fitted values for the data that was used to fit the model, or there's more to it?
Thanks!

rquest
  • 21
  • 3
  • 1
    Welcome to working with imbalanced data. Predicting by class depends on the threshold set for the decision criteria. This needs to be carefully tuned when working with real data. – alexwhitworth Sep 16 '16 at 16:51

0 Answers0