# Plot ROC curve in R with the PRROC package

After many hours of research, trial and error and frustration I hope someone here will be able to guide me in the right direction. I am fairly new to R and statistics and can not wrap my hand about the workings of the roc.curve() function of the PRROC package in R. My goal is to plot a ROC curve in the standard fashion provided by the PRROC package like this:

Picture: Example ROC curve

I now want to plot the ROC curve for the fitted logistic regression model with the testdata. My problem is, that I only get AUC values either 1 or 0 according to the order I put in my data in the curve is rectangluar.

Can someone see my mistake? Any help is greatly appreciated.

PRROC Documentation

library(PRROC)

# Split set
# Subset
# Logistic regression
# predict test-data
# ROC curve plot NOT WORKING
x<-c(fg_data,bg_data)
y<-c(rep(1,length(fg_data)),rep(0,length(bg_data)))

roc<-roc.curve(scores.class0 = x, weights.class0 = y, curve = TRUE)
plot(roc)


Ok let's do it in one way, according to the vignette (?roc.curve):

scores.class0: the classification scores of i) all data points or ii) only the data points belonging to the positive class.

      In the first case, scores.class1 should not be assigned an
explicit value, but left at the default
(scores.class1=scores.class0).  In addition, weights.class0
needs to contain the class labels of the data points (1 for
positive class, 0 for negative class) or the soft-labels for
the positive class, i.e., the probability for each data point
to belong to the positive class.  Accordingly, weights.class1
should be left at the default value (1-weights.class0).


So we provide the probability of being positive class, and a weights that is as long as your testset:

glm.probs.test <- predict(glm.fit,testset ,type = "response")


Now we need a weight that is 1 if positive, 0 if negative class in the actual label, by default your factors are numerically coded as 1 and 2, so -1 gives 0,1:

wt1 <- as.numeric(testset\$true_value)-1


Then plot:

roc = roc.curve(scores.class0=glm.probs.test,weights.class0=wt1,curve=TRUE)
plot(roc)