Search code examples
rplotlogistic-regressioncoefficientsmultinomial

Plot coefficients from a multinomial logistic regression model


I have a multinomial logistic regression model built using multinom() function from nnet package in R. I have a 7 class target variable and I want to plot the coefficients that the variables included in the model have for each class of my dependent variable.

For a binary logistic regression I used coefplot() function from arm package, but I don't know how to do this for a multiclass problem.

I want my plots to look like this: Example of plot


Solution

  • Given that you're able to get your data like this:

    coeff <- factor(1:7,labels=c("inc", "lwg", "hcyes", "wcyes","age", "k618", "k5"))
    values <- c(-0.1,0.6,0.15,0.8,-0.05,-0.05,-1.5)
    upper <- c(-0.1,1,.6,1.3,-.05,.1,-1)
    lower <- c(-0.1,.2,-.2,.3,-.05,-.2,-2)
    
    df <- data.frame(coeff,values,upper,lower)
    
    

    Then all you have to do is run:

    library(ggplot2)
    
    ggplot(df, aes(x=coeff, y=values, ymin=lower, ymax=upper)) + 
      geom_pointrange() + 
      geom_hline(yintercept=0, linetype=2)+
      coord_flip() 
    
    

    The result should look like this:

    You can experiment with certain options to get it to look identical to your example