• Register
1 vote
1.9k views

Problem :

I want to use the glmnet package on a dataset. I am trying to use cv.glmnet() to get the lambda value for the glmnet().

Please find below the dataset and error message:

> head(t2)
  X1 X2        X3 X4 X5         X6    X7 X8 X9 X10 X11 X12
1  1  1 1.7661266 45  2 0.80298213  9120 13  0   6   1   2
2  2  0 1.9571510 40  0 0.12187620  2600  4  0   0   1   1
3  3  0 1.6581801 38  1 0.08511338  3042  2  1   0   1   0
4  4  0 1.2338098 30  0 0.03604968  3300  5  0   0   1   0
5  5  0 1.9072394 49  1 0.02492570 63588  7  0   1   1   0
6  6  0 1.2131787 74  0 0.37560697  3500  3  0   1   1   1
> cv1 <- cv.glmnet(as.matrix(t2[,-c(1,2,7,12)]), t2[,2], family="binomial")
Error in as.matrix(cbind2(1, newx) %*% nbeta) : 
error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error in t(.Call(Csparse_dense_crossprod, y, t(x))) : 
error in evaluating the argument 'x' in selecting a method for function 't': Error: invalid class 'NA' to dup_mMatrix_as_dgeMatrix
> cv1 <- cv.glmnet(as.matrix(t2[,-c(1,2,7,12)]), t2[,2], family="multinomial")
Error in t(.Call(Csparse_dense_crossprod, y, t(x))) : 
error in evaluating the argument 'x' in selecting a method for function 't': Error: invalid class 'NA' to dup_mMatrix_as_dgeMatrix

Any suggestions regarding the solution?

7.5k points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

For some reason the glmnet prefers data.matrix() over as.matrix() so

cv1 <- cv.glmnet(data.matrix(t2[,-c(1,2,7,12)]), t2[,2], family="multinomial")

will solve your problem.

38.6k points
really helpful!! thanks so much for this answer, it worked. I was going crazy

Related questions

0 votes
1 answer 58 views
58 views
Problem: I need help in solving this error: Error in cbind2(1, newx) %*% nbeta : invalid class 'na' to dup_mmatrix_as_dgematrix
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.1k views
2.1k views
Problem : When ever i use the predict glmnet function i get the below mentioned error error in cbind2(1, newx) %*% nbeta : not-yet-implemented method for <data.frame> %*% <dgcmatrix>
asked Nov 12, 2019 peterlaw 6.9k points
0 votes
1 answer 64 views
64 views
Problem: I get the following error when using ridge and lasso regression. Error in storage.mode(y) <- "double" : invalid to change the storage mode of a factor My data set looks like this: > as_data_frame(blca.only) # A tibble: 315 x 435 Tags TCGA.BL.A5ZZ.01 TCGA.XF.AAN1.01 TCGA.DK.A2I4. ... .01 <dbl>, TCGA.GD.A3OP.11 <dbl>, TCGA.K4.A4AC.01 <dbl>, # TCGA.GD.A2C5.01 <dbl>, TCGA.4Z.AA84.01 <dbl>,
asked Apr 25 Humaira ahmed 50.7k points
0 votes
1 answer 10 views
10 views
Problem: Error: protect(): protection stack overflow.
asked Jul 11 Rada Gracelynn 104k points
0 votes
1 answer 11 views
11 views
Problem: Error in model.frame.default object is not a matrix
asked Jun 28 nila 121k points
0 votes
1 answer 100 views
100 views
Problem: Hey everyone, any Help: cholmod error 'x and/or y have wrong dimensions' at file ../matrixops/cholmod_sdmult.c, line 90
asked Mar 13 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.8k views
2.8k views
Problem : I am trying to predict probabilities in a dataset by using glmnet but facing following issue cholmod error 'x and/or y have wrong dimensions' at file ../matrixops/cholmod_sdmult.c, line 90
asked Nov 13, 2019 peterlaw 6.9k points
0 votes
1 answer 1.3k views
0 votes
1 answer 8 views
8 views
Problem: R invalid factor level, na generated.
asked 3 days ago Aurelia Maja 78.4k points
0 votes
1 answer 177 views
177 views
Problem: This is my problem: Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, : na/nan/inf in 'y' Any help.
asked Mar 13 Wafa Abu Yousef 6.1k points