I use the multinom()
function from the nnet package to run the multinomial logistic regression in R. The nnet package does not include p-value calculation and t-statistic calculation. I found a way to calculate the p-values using the two tailed z-test from this page. To give one example of calculating a test statistic for a multinom logit (not really a t-stat, but an equivalent) I calculate the Wald's statistic:
mm<-multinom(Empst ~ Agegroup + Marst + Education + State,
data = temp,weight=Weight)
W <- (summary(mm1)$coefficients)^2/(summary(mm1)$standard.errors)^2
I take the square of a coefficient and divide by the square of the coefficient's standard error. However, the likelihood-ratio test is the preferable measure of a goodness of fit for the logistic regressions. I do not know how to write code that will calculate the likelihood ratio statistic for each coefficient due to the incomplete understanding of the likelihood function. What would be the way to calculate the likelihood-ratio statistic for each coefficient using the output from the multinom()
function? Thanks for your help.
Let's look at predicting
Sepal.Length
from the iris dataset usingSpecies
(a categorical variable) andPetal.Length
(a continuous variable). Let's start by converting our factor variable into multiple binary variables usingmodel.matrix
and building our neural network:Now we can run a likelihood ratio test for a variable in our model:
To run the likelihood ratio test for all your variables, I guess you could just use a loop and run for each variable name. I've extracted just the p-values in this loop.
Use the
Anova
function in thecar
package for the likelihood-ratio test of each term in your model.From the response of @jolisber i extracted a function so anyone can do this and store the values in a df. Well, i stored the full character vector in the df.
However i cant get the first element (variable) p-value. I dont know why. And i cant ignore the [-1] in model_lmm$coefnames. EDITED. I edited i=0 to i=1; forgot that R vectors start at that :D.
Hope this works for everyone :D
EDIT 2
Also did 1 so it can store in a df.