I made a simple df
as follows:
df<-data.frame(pass=c(0,1,0,0,1,1,1,0,0,1,0,1,1,1,0,0,0,0,0,1),
math=c(23,46,66,78,77,88,90,99,21,34,56,55,67,67,88,89,90,12,11,34),
physics=c(87,43,56,78,44,56,90,99,21,32,45,46,46,77,88,90,32,12,34,57),
bmi=c(23,24,34,21,18,19,26,37,35,21,12,13,41,25,27,28,34,32,21,22))
pass
is a response variable for logistic lasso regression. I made train and test set, fit logistic lasso regression. I could get coefficients of logistic lasso regression by using coef(lasso.model)
.However, I don't know how to get p-values.
#split train and test set
sample <- sample.int(n = nrow(df), size = floor(.7*nrow(df)), replace = F)
train <- df[sample, ]
test <- df[-sample, ]
library(ROCR)
library(glmnet)
library(caret)
x <- as.matrix(data.frame(train[,2:4]))
y<-as.matrix(train$pass)
lasso.model <- cv.glmnet(x , y ,
family = 'binomial', type.measure = 'auc')
newX <- as.matrix(data.frame(test[,2:4]))
# Apply model to testing dataset
test$lasso.prob <- predict(lasso.model,type="response",
newx = newX, s = 'lambda.min')
coef(lasso.model)