Learn R Programming

plotROC (version 2.3.0)

melt_roc: Transform biomarkers stored as wide to long

Description

Multiple biomarkers measured on the same subjects are often stored as multiple columns in a data frame. This is a convenience function that transforms the data into long format, suitable for use with ggplot and geom_roc

Usage

melt_roc(data, d, m, names = NULL)

Value

A data frame in long format with three columns: D = binary disease status, M = biomarker value, and name = biomarker name

Arguments

data

Data frame containing disease status and biomarkers stored in columns

d

Column containing binary disease status. Can be a column name or index

m

Vector of column names or indices identifying biomarkers

names

Optional vector of names to assign to the biomarkers. If NULL, names will be taken from the column names

Examples

Run this code
D.ex <- rbinom(50, 1, .5)
widedata <- data.frame(D = D.ex, M1 = rnorm(50, mean = D.ex, sd = 1), 
   M2 = rnorm(50, mean = D.ex, sd = .5))
longdata <- melt_roc(widedata, "D", c("M1", "M2"))
ggplot(longdata, aes(d = D, m = M, color = name)) + geom_roc()

Run the code above in your browser using DataLab