0

I get the following error

Error in storage.mode(y) <- "double" : invalid to change the storage mode of 
a factor

an issue with getting the format of the input matrix right. Here the code:

library("glmnet")

daten = read.csv("test.csv",header = 1)
# Sex   Age Weight  Height  Other
# 0 22  54  154 1.51
# 1 34  76  178 1.94
# 1 38  75  178 1.93
# 1 32  102 178 2.19
# ...
# 1 35  94  184 2.18

trainX <- daten

# outcome variable
Y <- c(0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0,0,1)
trainY <- factor(Y)

fit.lasso=glmnet(trainX,trainY,alpha=1)

trainY seems to be formated correctly as factor, but what is wrong with trainX?

Any comments would be highly appreciated.

mjs
  • 150
  • 1
  • 20

1 Answers1

0

Problem solved! Simply skip the step

trainY <- factor(Y)

and use

fit.lasso=glmnet(trainX,Y,alpha=1)

and it works fine!

enter image description here

mjs
  • 150
  • 1
  • 20