I have installed R and Rstudio just to use glmnet for a multinomial logistic regression. I keep getting the following error:
Error in lognet(xd, is.sparse, ix, jx, y, weights, offset, alpha,
nobs, : one multinomial or binomial class has 1 or 0 observations; not allowed
whenever I plug in the dependent variable observations of my data. That comprises 120 "numeric" entries: 1 through 4. The predictors are 6=4 continuous+ 2 categorical.
I created a table "data" with 6 columns in which I changed the class of the categorical observations to "factor"
data <- cbind(x1,x1fat) # x1=4 columns, x1fat=2 factor columns
Then I set
x <- model.matrix(~.+0, data=data) # 120x12 matrix
to create the matrix of regressors observations with one-hot-encoded factor data. To feed the dependent variable y observations in glmnet, I use the following line
y <- model.matrix(~.+0, data=y1) # y1 is the 1-column table of imported observations
Now, the command
fit <- glmnet(x, y, family = "multinomial")
prompts the aforementioned error.
I do not comprehend why the following do not prompt any errors:
If I randomly generate the y vector through
y=sample(1:4,120,replace=true)
If I include the intercept column in y:
y <- model.matrix(~., data=y1)
I am completely stuck here. Any comment is appreciated, thanks.