Help with AUC Analysis Using pROC Package

Hello everyone,

I'm trying to perform an Area Under the Curve (AUC) analysis for the first time. I've been working with the pROC package but haven't been able to get meaningful results. I used the following code:

library(ggplot2)
library(pROC)
library(dplyr)
library(tidyr)

# DDA results
DDAresults <- read.table(text="Taxon	lfc	p_value	q_value	Group
Halobacterium	2.751066225	2.05E-05	3.52E-04	T
Parasutterella	-1.462742415	5.58E-04	0.0347	NT",
                                    header=TRUE, check.names = FALSE, sep = "\t")
# taxa abundance data
taxa_abundance <- read.table(text="SampleID	Halobacterium	Parasutterella
NT10  	5	64
NT11	0	137
NT12	0	19
NT13	0	7
NT14	0	0
NT15	17	0
NT16	0	21
NT17	0	0
NT18	2	8
NT19	204	5
T10  	0	0
T11	0	72
T12	0	57
T13	0	0
T14	0	0
T15	0	1589
T16	0	8
T17	0	0
T18	0	0
T19	0	419", header = TRUE, sep = "\t")

#metadata
metadata <- read.table(text="SampleID	Group
NT10  	None-Treated
NT11	None-Treated
NT12	None-Treated
NT13	None-Treated
NT14	None-Treated
NT15	None-Treated
NT16	None-Treated
NT17	None-Treated
NT18	None-Treated
NT19	Treated
T10  	Treated
T11	Treated
T12	Treated
T13	Treated
T14	Treated
T15	Treated
T16	Treated
T17	Treated
T18	Treated
T19	Treated
D10	Treated", header = TRUE, sep = "\t")



########################## 

taxa_abundance_long <- taxa_abundance %>%
  pivot_longer(cols = -SampleID, names_to = "Taxon", values_to = "Abundance")

########################## 
merged_data <- merge(taxa_abundance_long, metadata, by = "SampleID")

########################## 
merged_data$Abundance <- as.numeric(merged_data$Abundance)

#  Filter data 
merged_data_filtered <- merged_data %>%
  filter(Group %in% c("Non-Treated", "Treated"))

# AUC Analysis for each Taxon
auc_results <- merged_data_filtered %>%
  group_by(Taxon) %>%
  summarise(
    AUC = as.numeric(roc(Group, Abundance)$auc),
    CI_lower = as.numeric(ci.auc(roc(Group, Abundance))[1]),
    CI_upper = as.numeric(ci.auc(roc(Group, Abundance))[3])
  )

# 
auc_results <- merge(auc_results, DDAresults, by.x = "Taxon", by.y = "taxon")

Does anyone have recommendations on how to do this correctly?

Thanks in advance for any suggestions and help

1 Like