library(glmnet)
## Loading required package: Matrix
## Loaded glmnet 5.0
library(pROC)
## Type 'citation("pROC")' for a citation.
##
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
##
## cov, smooth, var
dat <- read.csv("PIPC_SYNTHETIC_75.csv")
dat_model <- na.omit(dat)
y <- dat_model$outcome_hosp_6m
x <- model.matrix(outcome_hosp_6m ~ ., dat_model)[,-1]
set.seed(123)
cv_fit <- cv.glmnet(x, y, family="binomial", alpha=1)
plot(cv_fit)

pred <- predict(cv_fit, newx=x, s="lambda.1se", type="response")
roc_obj <- roc(y, as.vector(pred))
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
plot(roc_obj, print.auc=TRUE)

auc(roc_obj)
## Area under the curve: 1