I want to validate my glm and make a ROC curve. I get some errors which I can't resolve.

My validation of the model:

glm.pred <- predict(m.glm, newdata = df.vld, type="response")

Now I want to make a ROC curve and first I want to analyze the true positives and negatives etc and the cut-offs by using the function 'prediction' (ROCR library)

glm.pred <- prediction(glm.pred, df.vld$hoge_kosten)
(and following glm.perf <- performance(glm.pred, "tpr", "fpr"))

But there is a error when I run the first line: 'predictions' contains NA.

After excluding the NA's by trying:

glm.pred2 = na.exclude(glm.pred)

There are no more NA's in the data (in the column 'hoge_kosten' there weren't any NA's either, only 0 and 1). But when I run the same prediction code with glm.pred2 I get the error "Format of predictions is invalid. It couldn't be coerced to a list."

In the R Documentation of prediction {ROCR} it seems like lists aren't a restriction ...

Can someone help me solve this problem. Or maybe there is another way to make the ROC Curve than..

glm.pred <- prediction(glm.pred2, df.vld$hoge_kosten)
glm.perf <- performance(glm.pred, "tpr", "fpr")

ROC curve

plot(glm.perf, avg= "threshold", col="red", lwd= 2, main= "ROC curve hoge kosten") abline(0, 1, untf = FALSE, col = "lightgray", lty = 2)

New contributor
user31540 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.


Your Answer

user31540 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.