How to weight different variables to produce optimal AUC in logistic regression

by Ryan   Last Updated August 13, 2019 23:19 PM

Lets say I have 7 independent variables (x1 to x7) that I determined to be important variables in predicting y using forward selection (stepAIC function):

``````y <- rep(c('Positive', 'Negative'), each = 20)

x1 <- rnorm(40, 1, .1)

x2 <- rnorm(40, 1, .1)

x3 <- rnorm(40, 1, .1)

x4 <- rnorm(40, 1, .1)

x5 <- rnorm(40, 1, .1)

x6 <- rnorm(40, 1, .1)

x7 <- rnorm(40, 1, .1)
``````

I make an overall score using the 7 x variables. Now I want to weight these variables to produce the highest AUC value. What would be the code to do this? Basically I want to see which values (or weights) I could multiply by each x variable to produce the highest AUC.

``````score <- x1 + x2 + x3 + x4 + x5 + x6 + x7

dat <- data.frame(y, score)

library(pROC)

glm.fit <- glm(y ~ score, family = binomial, data = dat)

a <- roc(dat$$y, glm.fit$$fitted.values)
a\$auc
``````

Thanks!

Tags :

Related Questions

Updated July 09, 2015 14:08 PM

Updated October 14, 2017 12:19 PM

Updated May 04, 2019 23:19 PM

Updated May 17, 2017 00:19 AM

Updated February 25, 2018 12:19 PM