I’m trying to implement lasso and ridge on my logistics regression model and I’m coming across difficulties. I’m using Introduction to Statistical Learning with Applications in R as a reference.
I’m trying to create a matrix in order to use glmnet() for a lasso regression. I've attached my dataframe below. I've tried two ways:
x <- model.matrix(acquired~., data = together)[,-101]
y <- together$acquired
library(glmnet)
grid= 10^seq(10, -2, length=100)
lasso.mod=glmnet(x,y, alpha=1, lambda=grid)
X is then transformed the dataframe that I've attached, x.csv, and then the error says:
Error in glmnet(x, y, alpha = 1, lambda = grid) :
number of observations in y (221) not equal to the number of rows of x (0)
2)
library(glmnet)
grid= 10^seq(10, -2, length=100)
lasso.mod=glmnet(x,y, alpha=1, lambda=grid)
Error in storage.mode(y) = "double" :
invalid to change the storage mode of a factor
My x is attached as x_secondway.
Thank you so much! I hope you have a good day.
Tiffany