ROC Curve using plotROC package and geom_roc(), transforming data to “M1 markers”












2















I am attempting to plot a ROC curve using the plotROC package for ggplot2, but I am not sure how to transform the data I have into the M1 marker format. The documentation provided the following example:



# plotROC documentation example
library(plotROC)
library(ggplot2)
D.ex <- rbinom(200, size = 1, prob = .5)
M1 <- rnorm(200, mean = D.ex, sd = .65)
M2 <- rnorm(200, mean = D.ex, sd = 1.5)

D M1 M2
1 1.4995932 0.5508204
1 0.4181619 1.6339181
0 -0.3620614 -1.0428972
1 0.7991132 -1.6396751
0 0.9574047 2.1159753
1 1.3440595 1.3026485

test <- data.frame(D = D.ex, D.str = c("Healthy", "Ill")[D.ex + 1],
M1 = M1, M2 = M2, stringsAsFactors = FALSE)

ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Sample ROC plot output by plotROC



My data is logistic regression scores on a test subset:



# Example starting point
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
scores.class <- ifelse(scores.prob > 0.5, 1, 0)

# Example generated data
test scores.prob scores.class
0 0.7323306 1
0 0.7860687 1
0 0.9535123 1
1 0.3082551 0
0 0.5762784 1
1 0.4613730 0


I would like to know what M1 is and how to transform my data to get that field.










share|improve this question

























  • I don't really understand it, but this paper: ncbi.nlm.nih.gov/pmc/articles/PMC3952000 has a whole bunch about ROC curves, M1 and M2. Could that help?

    – RAB
    Nov 22 '18 at 7:24











  • also check out the ?StatRoc page as it goes into a bit more detail about the d and m parameters

    – RAB
    Nov 22 '18 at 7:32






  • 1





    @user10626943 ?StatRoc was a great resource! Thank you for the fast response.

    – Nick
    Nov 22 '18 at 17:18
















2















I am attempting to plot a ROC curve using the plotROC package for ggplot2, but I am not sure how to transform the data I have into the M1 marker format. The documentation provided the following example:



# plotROC documentation example
library(plotROC)
library(ggplot2)
D.ex <- rbinom(200, size = 1, prob = .5)
M1 <- rnorm(200, mean = D.ex, sd = .65)
M2 <- rnorm(200, mean = D.ex, sd = 1.5)

D M1 M2
1 1.4995932 0.5508204
1 0.4181619 1.6339181
0 -0.3620614 -1.0428972
1 0.7991132 -1.6396751
0 0.9574047 2.1159753
1 1.3440595 1.3026485

test <- data.frame(D = D.ex, D.str = c("Healthy", "Ill")[D.ex + 1],
M1 = M1, M2 = M2, stringsAsFactors = FALSE)

ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Sample ROC plot output by plotROC



My data is logistic regression scores on a test subset:



# Example starting point
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
scores.class <- ifelse(scores.prob > 0.5, 1, 0)

# Example generated data
test scores.prob scores.class
0 0.7323306 1
0 0.7860687 1
0 0.9535123 1
1 0.3082551 0
0 0.5762784 1
1 0.4613730 0


I would like to know what M1 is and how to transform my data to get that field.










share|improve this question

























  • I don't really understand it, but this paper: ncbi.nlm.nih.gov/pmc/articles/PMC3952000 has a whole bunch about ROC curves, M1 and M2. Could that help?

    – RAB
    Nov 22 '18 at 7:24











  • also check out the ?StatRoc page as it goes into a bit more detail about the d and m parameters

    – RAB
    Nov 22 '18 at 7:32






  • 1





    @user10626943 ?StatRoc was a great resource! Thank you for the fast response.

    – Nick
    Nov 22 '18 at 17:18














2












2








2








I am attempting to plot a ROC curve using the plotROC package for ggplot2, but I am not sure how to transform the data I have into the M1 marker format. The documentation provided the following example:



# plotROC documentation example
library(plotROC)
library(ggplot2)
D.ex <- rbinom(200, size = 1, prob = .5)
M1 <- rnorm(200, mean = D.ex, sd = .65)
M2 <- rnorm(200, mean = D.ex, sd = 1.5)

D M1 M2
1 1.4995932 0.5508204
1 0.4181619 1.6339181
0 -0.3620614 -1.0428972
1 0.7991132 -1.6396751
0 0.9574047 2.1159753
1 1.3440595 1.3026485

test <- data.frame(D = D.ex, D.str = c("Healthy", "Ill")[D.ex + 1],
M1 = M1, M2 = M2, stringsAsFactors = FALSE)

ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Sample ROC plot output by plotROC



My data is logistic regression scores on a test subset:



# Example starting point
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
scores.class <- ifelse(scores.prob > 0.5, 1, 0)

# Example generated data
test scores.prob scores.class
0 0.7323306 1
0 0.7860687 1
0 0.9535123 1
1 0.3082551 0
0 0.5762784 1
1 0.4613730 0


I would like to know what M1 is and how to transform my data to get that field.










share|improve this question
















I am attempting to plot a ROC curve using the plotROC package for ggplot2, but I am not sure how to transform the data I have into the M1 marker format. The documentation provided the following example:



# plotROC documentation example
library(plotROC)
library(ggplot2)
D.ex <- rbinom(200, size = 1, prob = .5)
M1 <- rnorm(200, mean = D.ex, sd = .65)
M2 <- rnorm(200, mean = D.ex, sd = 1.5)

D M1 M2
1 1.4995932 0.5508204
1 0.4181619 1.6339181
0 -0.3620614 -1.0428972
1 0.7991132 -1.6396751
0 0.9574047 2.1159753
1 1.3440595 1.3026485

test <- data.frame(D = D.ex, D.str = c("Healthy", "Ill")[D.ex + 1],
M1 = M1, M2 = M2, stringsAsFactors = FALSE)

ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Sample ROC plot output by plotROC



My data is logistic regression scores on a test subset:



# Example starting point
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
scores.class <- ifelse(scores.prob > 0.5, 1, 0)

# Example generated data
test scores.prob scores.class
0 0.7323306 1
0 0.7860687 1
0 0.9535123 1
1 0.3082551 0
0 0.5762784 1
1 0.4613730 0


I would like to know what M1 is and how to transform my data to get that field.







r ggplot2 roc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 16:52







Nick

















asked Nov 22 '18 at 3:56









NickNick

134




134













  • I don't really understand it, but this paper: ncbi.nlm.nih.gov/pmc/articles/PMC3952000 has a whole bunch about ROC curves, M1 and M2. Could that help?

    – RAB
    Nov 22 '18 at 7:24











  • also check out the ?StatRoc page as it goes into a bit more detail about the d and m parameters

    – RAB
    Nov 22 '18 at 7:32






  • 1





    @user10626943 ?StatRoc was a great resource! Thank you for the fast response.

    – Nick
    Nov 22 '18 at 17:18



















  • I don't really understand it, but this paper: ncbi.nlm.nih.gov/pmc/articles/PMC3952000 has a whole bunch about ROC curves, M1 and M2. Could that help?

    – RAB
    Nov 22 '18 at 7:24











  • also check out the ?StatRoc page as it goes into a bit more detail about the d and m parameters

    – RAB
    Nov 22 '18 at 7:32






  • 1





    @user10626943 ?StatRoc was a great resource! Thank you for the fast response.

    – Nick
    Nov 22 '18 at 17:18

















I don't really understand it, but this paper: ncbi.nlm.nih.gov/pmc/articles/PMC3952000 has a whole bunch about ROC curves, M1 and M2. Could that help?

– RAB
Nov 22 '18 at 7:24





I don't really understand it, but this paper: ncbi.nlm.nih.gov/pmc/articles/PMC3952000 has a whole bunch about ROC curves, M1 and M2. Could that help?

– RAB
Nov 22 '18 at 7:24













also check out the ?StatRoc page as it goes into a bit more detail about the d and m parameters

– RAB
Nov 22 '18 at 7:32





also check out the ?StatRoc page as it goes into a bit more detail about the d and m parameters

– RAB
Nov 22 '18 at 7:32




1




1





@user10626943 ?StatRoc was a great resource! Thank you for the fast response.

– Nick
Nov 22 '18 at 17:18





@user10626943 ?StatRoc was a great resource! Thank you for the fast response.

– Nick
Nov 22 '18 at 17:18












1 Answer
1






active

oldest

votes


















1














library(plotROC) 
library(ggplot2)
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
test <- data.frame(D = test,
M1 = scores.prob, stringsAsFactors = FALSE)
ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Your marker/predictor is the fitted values of your glm model. The ROC will give you the idea of how your model work (by means of AUC) and the best probability threshold (the ROC cutoff) for assigning persons to classes.
It is a usefull approach if you want to visualize the added value of fdifferent multivariate/univariate approaches.
Here a full example with the mtcars dataset. Hope it helps.



# Loading data
data(mtcars)
# Manual transmission (am = 1) depends on 1/4 mile time (qsec) and miles/(US) gallon (mpg)
glmfit <- glm(am ~ qsec + mpg, data = mtcars, binomial)
mtcars$fitted_am <- glmfit$fitted.values
# Loading packages
library(plotROC)
library(ggplot2)
library(pROC)
# Calculating ROC curve, AUC and threshold according to Youden index
rocfit <- roc(mtcars$am, mtcars$fitted_am)
auc(rocfit)
coords(rocfit, x = "b")
basicplot <- ggplot(mtcars, aes(d = am, m = fitted_am))
basicplot +
geom_roc() +
style_roc(theme = theme_grey) +
theme(axis.text = element_text(colour = "blue")) +
ggtitle("Automatic transmission prediction") +
scale_x_continuous("1 - Specificity", breaks = seq(0, 1, by = .1))
plot(rocfit)
prop.table(table(mtcars$am))





share|improve this answer





















  • 1





    The mtcars example helped a great deal and thank you for the quick response!

    – Nick
    Nov 22 '18 at 17:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423655%2froc-curve-using-plotroc-package-and-geom-roc-transforming-data-to-m1-markers%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














library(plotROC) 
library(ggplot2)
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
test <- data.frame(D = test,
M1 = scores.prob, stringsAsFactors = FALSE)
ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Your marker/predictor is the fitted values of your glm model. The ROC will give you the idea of how your model work (by means of AUC) and the best probability threshold (the ROC cutoff) for assigning persons to classes.
It is a usefull approach if you want to visualize the added value of fdifferent multivariate/univariate approaches.
Here a full example with the mtcars dataset. Hope it helps.



# Loading data
data(mtcars)
# Manual transmission (am = 1) depends on 1/4 mile time (qsec) and miles/(US) gallon (mpg)
glmfit <- glm(am ~ qsec + mpg, data = mtcars, binomial)
mtcars$fitted_am <- glmfit$fitted.values
# Loading packages
library(plotROC)
library(ggplot2)
library(pROC)
# Calculating ROC curve, AUC and threshold according to Youden index
rocfit <- roc(mtcars$am, mtcars$fitted_am)
auc(rocfit)
coords(rocfit, x = "b")
basicplot <- ggplot(mtcars, aes(d = am, m = fitted_am))
basicplot +
geom_roc() +
style_roc(theme = theme_grey) +
theme(axis.text = element_text(colour = "blue")) +
ggtitle("Automatic transmission prediction") +
scale_x_continuous("1 - Specificity", breaks = seq(0, 1, by = .1))
plot(rocfit)
prop.table(table(mtcars$am))





share|improve this answer





















  • 1





    The mtcars example helped a great deal and thank you for the quick response!

    – Nick
    Nov 22 '18 at 17:21
















1














library(plotROC) 
library(ggplot2)
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
test <- data.frame(D = test,
M1 = scores.prob, stringsAsFactors = FALSE)
ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Your marker/predictor is the fitted values of your glm model. The ROC will give you the idea of how your model work (by means of AUC) and the best probability threshold (the ROC cutoff) for assigning persons to classes.
It is a usefull approach if you want to visualize the added value of fdifferent multivariate/univariate approaches.
Here a full example with the mtcars dataset. Hope it helps.



# Loading data
data(mtcars)
# Manual transmission (am = 1) depends on 1/4 mile time (qsec) and miles/(US) gallon (mpg)
glmfit <- glm(am ~ qsec + mpg, data = mtcars, binomial)
mtcars$fitted_am <- glmfit$fitted.values
# Loading packages
library(plotROC)
library(ggplot2)
library(pROC)
# Calculating ROC curve, AUC and threshold according to Youden index
rocfit <- roc(mtcars$am, mtcars$fitted_am)
auc(rocfit)
coords(rocfit, x = "b")
basicplot <- ggplot(mtcars, aes(d = am, m = fitted_am))
basicplot +
geom_roc() +
style_roc(theme = theme_grey) +
theme(axis.text = element_text(colour = "blue")) +
ggtitle("Automatic transmission prediction") +
scale_x_continuous("1 - Specificity", breaks = seq(0, 1, by = .1))
plot(rocfit)
prop.table(table(mtcars$am))





share|improve this answer





















  • 1





    The mtcars example helped a great deal and thank you for the quick response!

    – Nick
    Nov 22 '18 at 17:21














1












1








1







library(plotROC) 
library(ggplot2)
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
test <- data.frame(D = test,
M1 = scores.prob, stringsAsFactors = FALSE)
ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Your marker/predictor is the fitted values of your glm model. The ROC will give you the idea of how your model work (by means of AUC) and the best probability threshold (the ROC cutoff) for assigning persons to classes.
It is a usefull approach if you want to visualize the added value of fdifferent multivariate/univariate approaches.
Here a full example with the mtcars dataset. Hope it helps.



# Loading data
data(mtcars)
# Manual transmission (am = 1) depends on 1/4 mile time (qsec) and miles/(US) gallon (mpg)
glmfit <- glm(am ~ qsec + mpg, data = mtcars, binomial)
mtcars$fitted_am <- glmfit$fitted.values
# Loading packages
library(plotROC)
library(ggplot2)
library(pROC)
# Calculating ROC curve, AUC and threshold according to Youden index
rocfit <- roc(mtcars$am, mtcars$fitted_am)
auc(rocfit)
coords(rocfit, x = "b")
basicplot <- ggplot(mtcars, aes(d = am, m = fitted_am))
basicplot +
geom_roc() +
style_roc(theme = theme_grey) +
theme(axis.text = element_text(colour = "blue")) +
ggtitle("Automatic transmission prediction") +
scale_x_continuous("1 - Specificity", breaks = seq(0, 1, by = .1))
plot(rocfit)
prop.table(table(mtcars$am))





share|improve this answer















library(plotROC) 
library(ggplot2)
test <- rbinom(200, size = 1, prob = 0.2)
scores.prob <- runif(200, min = 0 , max = 1)
test <- data.frame(D = test,
M1 = scores.prob, stringsAsFactors = FALSE)
ggplot(test, aes(d = D, m = M1)) +
geom_roc()


Your marker/predictor is the fitted values of your glm model. The ROC will give you the idea of how your model work (by means of AUC) and the best probability threshold (the ROC cutoff) for assigning persons to classes.
It is a usefull approach if you want to visualize the added value of fdifferent multivariate/univariate approaches.
Here a full example with the mtcars dataset. Hope it helps.



# Loading data
data(mtcars)
# Manual transmission (am = 1) depends on 1/4 mile time (qsec) and miles/(US) gallon (mpg)
glmfit <- glm(am ~ qsec + mpg, data = mtcars, binomial)
mtcars$fitted_am <- glmfit$fitted.values
# Loading packages
library(plotROC)
library(ggplot2)
library(pROC)
# Calculating ROC curve, AUC and threshold according to Youden index
rocfit <- roc(mtcars$am, mtcars$fitted_am)
auc(rocfit)
coords(rocfit, x = "b")
basicplot <- ggplot(mtcars, aes(d = am, m = fitted_am))
basicplot +
geom_roc() +
style_roc(theme = theme_grey) +
theme(axis.text = element_text(colour = "blue")) +
ggtitle("Automatic transmission prediction") +
scale_x_continuous("1 - Specificity", breaks = seq(0, 1, by = .1))
plot(rocfit)
prop.table(table(mtcars$am))






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 8:53

























answered Nov 22 '18 at 8:18









paoloeusebipaoloeusebi

641413




641413








  • 1





    The mtcars example helped a great deal and thank you for the quick response!

    – Nick
    Nov 22 '18 at 17:21














  • 1





    The mtcars example helped a great deal and thank you for the quick response!

    – Nick
    Nov 22 '18 at 17:21








1




1





The mtcars example helped a great deal and thank you for the quick response!

– Nick
Nov 22 '18 at 17:21





The mtcars example helped a great deal and thank you for the quick response!

– Nick
Nov 22 '18 at 17:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423655%2froc-curve-using-plotroc-package-and-geom-roc-transforming-data-to-m1-markers%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'