I want to create a lasso model, but I can't have a test set because I have a small sample size, so I want to use cross-validation to evaluate the model. In other posts, I saw that functions like cv.glmnet and caret are used to make the lasso model. Now, my question is, should caret be used instead of cv.glmnet to get the confusion matrix for cross-validation in the case of small sample size? Or will cv.glmnet be used as inner CV for pick lambda and caret for outer CV? Knowing this question is important for me to make sure if I should use cv.glmnet or not.
data=read.xlsx("data.xlsx")
head(data)
dim(data)
summary(data)
# Set seed for reproducible random partitioning of data
set.seed(100)
x=as.matrix(data[,-1]) ; y= data[,1]
#fit lasso model for binomial outcome
Lasso.mod = glmnet(x, y, alpha=1,family="binomial", type.measure='deviance')
plot(Lasso.mod, xvar="lambda")
#best lambda
cv.out <- cv.glmnet(x, y, alpha=1, type.measure='deviance',family="binomial",nfold=10)
plot(cv.out)
best.lambda <- cv.out$lambda.min
best.lambda