Plots ROC curves (receiver operating characteristic) for several case groups (TP=true positives) against one controls group (TN=true negatives) for each parameter. This results in a curve with "sensitivity" = TPR(true positive rate) on y-axis and "1-specificity" = FPR (false positive rate) on the x-axis.1) Select numerical variables for ROC curves (parameter). 2) Template expects a column named "treatment" as category column. Enter the name of the negative control class as plain text. Select several classes as positive controls (cases) that will be plotted against the single negative control class (controls).Options for visualization: a) plot method can be "automatic" (=done with R package "pROC") or "manual" (=plotted point by point). For "manual" controls and cases will be assigned automatically; then controls and cases will be swapped if median(controls) > median(cases). b) enter the title of the plot and check if the parameter name should be in the title as well. c) enter the x-axis label and check if the name of negative control group should be in the x-axis as well d) enter the y-axis label e) set aspect ratio (height/width), depends on pixel dimensions in "output option" tab (default:=700/1000) f) scale the legend (default:=1) and set position #1.0 Parameter selection # a) Define your numerical attribute of interest parameter = c() # b) Either define the treatment column and type in negative control category = controlVar = # c) Or select negative control and define the the case group factor (positve controls) controlVar = caseVar = c() # e) Options for visualization plotMethod = c() controlCaseDirection = c() legendPosition = c() 1)) xAxisLimit[1] <- 0.0if ((is.na(xAxisLimit[2])) || (xAxisLimit[2]<0) || (xAxisLimit[2]>1)) xAxisLimit[2] <- 1.0 if ((is.na(yAxisLimit[1])) || (yAxisLimit[1]<0) || (yAxisLimit[1]>1)) yAxisLimit[1] <- 0.0if ((is.na(yAxisLimit[2])) || (yAxisLimit[2]<0) || (yAxisLimit[2]>1)) yAxisLimit[2] <- 1.0if (is.na(aspRatio)) aspRatio <- 1if ((xAxisLimit[1] != 0.0) || (xAxisLimit[2] != 1.0) || (yAxisLimit[1] != 0.0 || (xAxisLimit[2] != 1.0))) aspRatio <-NULL if (is.na(legendScale)) legendScale <- 1 errorMessage <- NULL if ((is.null(parameter)) && (is.null(errorMessage))) errorMessage <- "Select at least one parameter" #if option A and treatment column is not present/selected use first class of selected column as control and all the others as casesif (!((category == "-USE-treatment-COLUMN-") || (category == "treatment")) && (is.null(errorMessage))) { if (length(unique(kIn[,category])) < 2) { errorMessage <- "Please rename the category column to 'treatment' or choose column with more than 1 category" } else { if (!(controlVar %in% kIn[,category])) { errorMessage <- paste("Didnt find negative control value in column ", category, sep="") } else { caseVar <- setdiff(unique(kIn[,category]), controlVar) } } } else {#if option B and treatment column is selected check if used first class of selected column as control and all the others as cases category <- "treatment" if (is.null(caseVar)) errorMessage <- "Select at least one positive control" }#2.3. calulate if ((useJoinParameterToTitle) && (length(parameter) == 1)) titleLabel <- paste(titleLabel,": (", parameter,")", sep="") if (useJoinNegativeControlToXAxis) xAxisLabel <- paste(xAxisLabel,"(", controlVar,")", sep="")#2.4.1 layout plot legendTitle <- NULL controlCaseResorted <- NULL#2.4.2 plot data if (!is.null(errorMessage)){ plot(0,0,main=errorMessage) } else { #itereate over j-parameters and i-cases for (j in 1:length(parameter)) { for (i in 1:length(caseVar)) { if (plotMethod=="manual") { #set up plot for first iteration, take first color if ((i == 1) && (j == 1)) { plot(0.5,0.5, type = "p", col = "white", xlim=xAxisLimit, ylim=yAxisLimit, main=titleLabel, xlab=xAxisLabel, ylab=yAxisLabel, asp=aspRatio) legendVector <- NULL } controlCaseResorted <- NULL #define the ROC data: contols and one case -> remove NAs -> sort data <- na.omit(rbind(subset(kIn,kIn[,category] == controlVar, select = c(parameter[j], category)), subset(kIn,kIn[,category] == caseVar[i], select = c(parameter[j], category)))) if (median(data[which(data[,category] == controlVar),parameter[j]], na.rm = TRUE) > median(data[which(data[,category] == caseVar[i]),parameter[j]], na.rm = TRUE) || (controlCaseDirection != "automatic")) { data <- data[order(data[,parameter[j]], decreasing = FALSE),] } else { #data is sorted the other way, because control bigger values bigger that case values. Then set * to legend curve and add title to lagend data <- data[order(data[,parameter[j]], decreasing = TRUE),] controlCaseResorted <- "*" legendTitle <- "* = control & case inverted" } #define length of steps to walk in x and y per data point xLength <- 1/(length(which(data[,category] == controlVar))-1) yLength <- 1/(length(which(data[,category] == caseVar[i]))-1) #initalize first point, then draw steps previousPoint <- c(0,0) for (d in 1:length(data[,1])){ if (data[d,category] == controlVar){ currentPoint <- c(previousPoint[1]+xLength,previousPoint[2]) } else { currentPoint <- c(previousPoint[1],previousPoint[2]+yLength) } #if((currentPoint[2] > yAxisLimit[1]) && (currentPoint[2] < yAxisLimit[2]) ){ lines(c(previousPoint[1],currentPoint[1]),c(previousPoint[2],currentPoint[2]), type="l", lwd=lineSize, col=colVector[(j-1)*length(caseVar)+i]) previousPoint <-currentPoint } } else { #if plotMethod == "auto" #calculate the ROC object currentRoc <- roc(controls = kIn[which(kIn[,category] == controlVar),parameter[j]], cases = kIn[which(kIn[,category] == caseVar[i]),parameter[j]], percent=FALSE) if ((i == 1) && (j == 1)) { #set up plot for first iteration, take first color plot.roc(currentRoc, col=colVector[1], legacy.axes=TRUE, main=titleLabel, xlim=c(1-xAxisLimit[1],1-xAxisLimit[2]), ylim=yAxisLimit, xlab=xAxisLabel, ylab=yAxisLabel, asp=aspRatio) #define a variable for legend vector legendVector <- NULL } else { #add lines to plot, colors: e.g. 0*2+1, 0*2+2, 1*2+1, 1*2+2, 2*2+1, ... lines.roc(currentRoc, lwd=lineSize, col=colVector[(j-1)*length(caseVar)+i]) } } #make legend vector: only if ONE parameter use the "cases", else use combination "parameter - cases" as legend if (length(parameter) == 1){ legendVector[i] <- paste(caseVar[i], controlCaseResorted,sep="") } else { legendVector[(j-1)*length(caseVar)+i] <- paste(parameter[j], " - ", caseVar[i], controlCaseResorted, sep="") } } } legend(legendPosition, legendVector, lty=1, col=colVector[1:length(legendVector)], cex=legendScale, title=legendTitle) } ]]>