Home > Blockchain >  Multinomial regression : how to show all coefficients without L, Q and R?
Multinomial regression : how to show all coefficients without L, Q and R?

Time:10-25

I have this dataframe that I applied multinom function

df = data.frame(x = c('a','a','b','b','c','c','d','d','d','e','e','f','f',
                      'f','f','g','g','g','h','h','h','h','i','i','j','j'),
                y = c(1,2,1,3,1,2,1,4,5,1,2,2,3,4,5,1,1,2,1,2,2,3,2,2,3,4) )
df$y = factor(df$y,ordered = TRUE)


nnet::multinom(y~x, data = df)

when checking the output, I have all the variables with their coefficients (meaning everything is fine)

Coefficients:
    (Intercept)        xb            xc        xd            xe       xf
2 -6.045294e-05 -31.83512  3.800915e-05 -36.67053  3.800915e-05 25.00515
3 -1.613311e 01  16.13310 -1.725649e 01 -21.06832 -1.725649e 01 41.13825
4 -1.692352e 01 -14.71119 -1.428100e 01  16.92351 -1.428100e 01 41.92865
5 -2.129358e 01 -10.49359 -1.002518e 01  21.29353 -1.002518e 01 46.29867
           xg          xh        xi         xj
2  -0.6931261   0.6932295 40.499799 -25.311410
3 -24.0387863  16.1332150 -8.876562  45.191730
4 -20.2673490 -16.0884760 -6.394423  45.982129
5 -15.1755064 -11.8589447 -4.563793  -6.953942


but my original dataframe (will share only the output) that is coded as the dependent and independent variables from the df dataframe (meaning as ordinal factors) and all the analysis is well done but when it comes to interpretation I have this output :

Coefficients:
  (Intercept)   FIES_R.L    FIES_R.Q   FIES_R.C    FIES_R^4     FIES_R^5
2 -0.09594409  -1.303256  0.03325169 -0.1753022 -0.46026668 -0.282463422
3 -0.18587599  -1.469957  0.42005569 -0.2977628  0.00508412  0.003068678
4 -0.58189239  -2.875183  0.33128994 -0.6787992  0.11145099  0.239368520
5 -2.68727952 -10.178604 -5.12515249 -5.8454920 -3.13775961 -1.820629143
    FIES_R^6   FIES_R^7   FIES_R^8
2 -0.2179067 -0.1000471 -0.1489342
3  0.1915476 -0.5483707 -0.2565626
4  0.2585801  0.3821566 -0.2679774
5 -0.5562958 -0.6335412 -0.7205215

I don't want FIES_R.L,FIES_R.Q and FIES_R.C. I want them as : FIES_R_1, FIES_R_2, FIES_R_3, FIES_R_4, FIES_R_5, FIES_R_6, FIES_R_7, FIES_R_8, why I have such an output ? knowing that the two dataframes include ordinal categorical variables and the x variable and the FIES variable include many categories in both dataframes. Thanks

CodePudding user response:

I just figured it out : because the independent variable is an ordinal factor. Meaning FIES in my dataset in an ordinal factor. When I used the argument ordered = FALSE the problem got solved

CodePudding user response:

You can change the coefnames "by hand":

mod = nnet::multinom(y~x, data = df)
mod$vcoefnames = c("(Intercept)", paste0(substr(mod$vcoefnames, 1, 6), "_", 1:8))
  • Related