Search code examples
rglmnetmultinomial

Penalized GLM using the glmet - package


Since I have a lot of explanatory variables, I want to perform a penalized estimation of a multinomial logit model. Using the glmnet package, I would proceede as follows:

library(glmnet)
data(MultinomialExample)

cvfit=cv.glmnet(x, y, family="multinomial", type.multinomial = "grouped", parallel = TRUE)
plot(cvfit)
coef(cvfit, s = "lambda.min")

From other packages that perform the multinomial logit regression, I kow that the output K-1 coefficients for a dependent variable with K levels, since one of them is the so called reference category.

However, coef(cvfit, s = "lambda.min") gives me coefficients for each category, which confuses me:

$`1`
31 x 1 sparse Matrix of class "dgCMatrix"
                       1
(Intercept)  0.015885341
V1           0.051848049
V2          -0.340036374
V3           0.421616900
....

$`2`
31 x 1 sparse Matrix of class "dgCMatrix"
                       1
(Intercept) -0.017214370
V1          -0.329369991
V2          -0.145053512
V3          -0.160609561
.......

$`3`
31 x 1 sparse Matrix of class "dgCMatrix"
                       1
(Intercept)  0.001329029
V1           0.277521942
.......

So basically:

  1. Do you know how to interprete the output?

  2. Do you know how I get the coefficients for category 2 & 3 - assuming that 1 is the reference category?


Solution

  • Check out the answer by KH Kim here. His/her code shows how you can go between the output from glmnet and the more usual format from e.g. multinom() from nnet.