--- title: "ROC-Curve" author: "Jessica Kleer" date: "11 3 2021" output: html_document --- Objective: examine the following outcomes per Roc curve: Discrimination between SLE patients and healthy donors, Disease activity, Nephritis ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ```{r load packages} library(pROC) library(psych) ``` ```{r set working directory} setwd("/Volumes/KLIM$/Kleer/Project Paper/Submission/DRYAD") #setwd("/Volumes/KLIM$/Kleer/Project Paper/Masterfiles/4. Testfiles") #setwd("Z:/Kleer/Project Paper/Masterfiles/4. Testfiles/") ``` ```{r} #load data data <- read.csv2("MASTERFILE_kleer_20210305.csv") ``` ```{r} # create a variable which is 0 for NHS-Group and 1 for Lupus-Group # relabeling for ROC Curve, 0 will be baseline data$Group data$Group <- factor(data$Group, levels = c("SLE", "NHS"), labels = c(1,0)) ``` ```{r} #create data.frame for SLE subset SLEsubset <- data[1:378, 1:150] ``` ```{r} # Definition of active Disease SLEsubset$PGA <- factor(SLEsubset$PGA,levels = c("inactive","moderat", "active", "very active"), labels = c(0,1,2,3)) SLEsubset$PGA <- as.numeric(SLEsubset$PGA) SLEsubset$PGA #1=inactive, 2=moderate, 3= active, 4= very active SLEsubset$activity <- ifelse(SLEsubset$SELENA>=6 & SLEsubset$PGA >=2, yes=1, no=0) table(SLEsubset$activity) ``` ```{r data.frame Proteinurie} #proteinuria as a surrogat Parameter for Lupus-Nephropathia # new data.frame for Proteinuria without missing items, because 'NA's' will cause Problems by calculating ROC-curve, since Response and predictor must be vectors of the same length data_Prot <- SLEsubset [! (is.na(SLEsubset$PRO)), ] ``` ####### ROC-Curves Discrimination between SLE patients and healthy donors ######### ```{r A15} #A15 former called A08 par(pty="s")#set pty aka "the plot type" to s, which is short for square roc_1 <- roc(data$Group, data$A08, plot=TRUE, print.auc=TRUE, ci=TRUE, legacy.axes =TRUE, cex.lab= 1.5, main="A15") ci(roc_1) # Confidence interval roc curve A15 (aka A08) ``` ```{r A09} #A09 former called A08shift par(pty="s") #set pty aka "the plot type" to s, which is short for square roc_2 <- roc(data$Group, data$A08shift, plot=TRUE, legacy.axes =TRUE, print.auc=TRUE, ci=TRUE, main="A09") ci(roc_2) # Confidence interval roc curve A15 (aka A08) ``` ```{r A15 & A09} #create Figure par(pty="s") roc(data$Group, data$A08shift, plot=TRUE, legacy.axes=TRUE, #legacy.axes to plot 1-Specificity on the x-axis print.auc=TRUE, print.auc.cex= 1.3, ci=TRUE, col="#feb24c", main="SLE vs. Healthy Donors", cex.main= 2, cex.lab= 1.5) plot.roc(data$Group, data$A08, col="#f03b20", print.auc=TRUE, print.auc.cex= 1.3, ci=TRUE, print.auc.y=0.4, add=TRUE) legend("bottomright", legend = c("A09", "A15"), col = c("#feb24c","#f03b20"),lwd=4, cex=2) ``` ```{r anti C1q} par(pty="s") #set pty aka "the plot type" to s, which is short for square roc_3 <- roc(data$Group, data$antiC1q, plot=TRUE, print.auc=TRUE, ci =TRUE, print.auc.cex= 1.3, legacy.axes=TRUE, #legacy.axes to plot 1-Specificity on the x-axis main="SLE vs. Healthy Donors", cex.main= 2, cex.lab= 1.5) ci(roc_3) #confidence interval roc-curve antiC1q ``` ```{r} #Compare the AUC of two ROC curves roc.test(roc_1, roc_3) ``` ############# active vs. inactive SLE disease ############# ROC Curves for SLEsubset 0= inactive 1= active (Selena >= 6 & PGA >= moderat) ```{r A15} #A15 former called A08 par(pty="s")#set pty aka "the plot type" to s, which is short for square roc_4 <- roc(SLEsubset$activity,SLEsubset$A08, plot=TRUE, print.auc= TRUE, legacy.axes= TRUE, main="A15; Active Disease", cex.main=1) ci(roc_4) ``` ```{r A09} #A09 former called A08shift par(pty="s")#set pty aka "the plot type" to s, which is short for square roc_5 <- roc(SLEsubset$activity, SLEsubset$A08shift, plot=TRUE, legacy.axes=TRUE, print.auc=TRUE, main="A09; Active Disease") ci(roc_5) ``` ```{r A15 & A09 } par(pty="s") roc(SLEsubset$activity, SLEsubset$A08shift, plot=TRUE, legacy.axes=TRUE, #legacy.axes to plot 1-Specificity on the x-axis print.auc=TRUE, print.auc.cex= 1.5, ci=TRUE, print.auc.x=1, print.auc.y=0.8, col="#feb24c", main="Disease Activity", cex.main=2, cex.lab= 1.5) plot.roc(SLEsubset$activity, SLEsubset$A08, legacy.axes= TRUE, col="#f03b20", print.auc=TRUE, print.auc.cex= 1.5, ci= TRUE, add=TRUE, print.auc.x = 1, print.auc.y= 0.7) legend("bottomright", legend = c("A09","A15"), col = c("#feb24c","#f03b20"),lwd=4, cex=2) ``` ```{r ROC anti C1q} par(pty="s") #set pty aka "the plot type" to s, which is short for square roc_6 <- roc(SLEsubset$activity, SLEsubset$antiC1q, plot=TRUE, print.auc=TRUE, print.auc.cex =1.3, ci=TRUE, legacy.axes= TRUE, main= "Disease Activity", cex.main=2, cex.lab =1.5) ci(roc_6) ``` ```{r} roc.test(roc_4, roc_6) roc.test(roc_5, roc_6) ``` #######ROC-Curves for SLE subset with Proteinurie###### ```{r A08} #A15 former called A08 par(pty="s") roc_10 <- roc(data_Prot$PRO, data_Prot$A08, plot=TRUE, legacy.axes =TRUE, print.auc=TRUE, main= "A15;Proteinuria") ci(roc_10) ``` ```{r A08shift } #A09 former called A08shift par(pty="s") roc_11 <- roc(data_Prot$PRO, data_Prot$A08shift, plot=TRUE, legacy.axes =TRUE, print.auc=TRUE, main= "A09;Proteinuria") ci(roc_11) ``` ```{r A15 & A09 } par(pty="s") roc(data_Prot$PRO, data_Prot$A08shift, plot=TRUE, legacy.axes=TRUE, #legacy.axes to plot 1-Specificity on the x-axis print.auc=TRUE, ci=TRUE, print.auc.cex=1.5, print.auc.x = 1, print.auc.y= 0.8, col="#feb24c", main="Proteinuria", cex.main=2, cex.lab=1.5) plot.roc(data_Prot$PRO, data_Prot$A08, legacy.axes= TRUE, col="#f03b20", print.auc=TRUE, ci=TRUE, print.auc.cex=1.5, add=TRUE, print.auc.x = 1, print.auc.y= 0.7) legend("bottomright", legend = c("A09","A15"), col = c("#feb24c","#f03b20"),lwd=4, cex=2) ``` ```{r anti_C1q} par(pty="s")#set pty aka "the plot type" to s, which is short for square roc_12 <- roc(data_Prot$PRO, data_Prot$antiC1q, plot=TRUE, print.auc=TRUE, print.auc.cex=1.3, ci=TRUE, legacy.axes= TRUE, main= "Proteinuria", cex.main=2, cex.lab=1.5) ci(roc_12) ``` ```{r} roc.test(roc_10, roc_12) roc.test(roc_11, roc_12) ```