rp-valuemultinomialmlogit

P-value in nnet: multinom() . P-value Wald test extracted, but ¿how i extract it by LIkehood ratio?


I got a multinomial model, which goes like this:

I got a bunch of observations (patients) that have 1 of 5 classes: Control, A_severe, A_low, B_severe, and B_low.

So I tried to fit a multinom model with the package nnet, and I extracted the Wald test p-values as follows:

multinom_wout20_1 = multinom(formula_wout20_base,data=wout_20_training, maxit=10000)
summary(multinom_wout20_1)

Coefs:

exp(coef(multinom_wout20_1))

Z Values

z_wout <- summary(multinom_wout20_1)$coefficients/summary(multinom_wout20_1)$standard.errors
z_wout

And we get the p-values:

# 2-tailed z test
p_wout <- (1 - pnorm(abs(z_wout), 0, 1)) * 2
p_wout

And then I passed them to a custom variable to see them as letters (more intuitive)

## Function to Pass our values to letters.
sign_levels_df_letter <- function(df) {
  df <- ifelse(df >.80, "Z", ifelse(df >.50, "FFF",
             ifelse( df >.30, "FF",
               ifelse(df >.10 , "F", 
               ifelse(df <= 0.0001, "AAA",
                      ifelse(df <= .0005,"AA+",
                             ifelse(df <= .001,"AA",
                                           ifelse(df <= .005, "A+",
                                                  ifelse (df<= .01, "A",
                                                            ifelse(df<= .05, "A-",
                                                                   ifelse(df <=.07, "B",
                                                                          ifelse(df <=.10, "C", NA
                                           
                                           ))))))))))))
                 
    
  return(df)
}
aux_pwout0 = sign_levels_df_letter(p_wout) ; aux_pwout0

Which I suppose is the same (cause they coincide its symbiology with *, ***, and **) if I use the package stargazer

library(stargazer)
stargazer(multinom_wout20_1, type= "text" )   #   "html", out="multi1.htm")

But as seen in the response of this thread:

multinomial logistic regression in R: multinom in nnet package result different from mlogit in mlogit package?

There is some problems with using Wald instead of LogLikehood. ¿How can get the Likelihood Ratio test p-value from my model?

I don't mind using other function for my data, but mlogit from the package mloget requires me to pass my data into a wide format, which is not as easy as it seems but I suppose I could extract from:

R: how to format my data for multinomial logit?

If some user of this last function could tell me if there is some secret function that automates this, that also solves my problem.


Solution

  • Allright, i got it.

    From this post i extracted a function to get the p-values of Likehood in nnet:multinom models, and i post it also as a response.

    https://stackoverflow.com/a/60835647/10465155

    You can see it just below.

    
    likehoodmultinom_p <- function(model_lmm) 
    {
    
      i <- 1
    
      variables <-c("No funciona")
      values <- c("No funciona") 
    
    
      for (var in model_lmm$coefnames[-1]) { 
    
      variables[i] =paste(var)
      values[i]= lrtest(model_lmm, var)[[5]][2]
      i=i+1
       ## Contributed to stack at: 
      }
      return (data.frame(variables,values))
    }