0

I iterated delong tests through a list of values that I wanted to compare. I got the results which looks like this:

$`7  V  8`

    DeLong's test for two correlated ROC curves

data:  test1 and test2
Z = 6.6128, p-value = 3.771e-11
alternative hypothesis: true difference in AUC is not equal to 0
95 percent confidence interval:
 0.04771894 0.08792131
sample estimates:
AUC of roc1 AUC of roc2 
  0.8122934   0.7444732 

I was wondering if it is possible to get the values (for Z, p-Value, CI, AUC ROC1 and AUC ROC2) of each delong test into a dataframe/table. I tried to extract it but it seems not to work if you use

roc.test(test1, test2, reuse.auc=TRUE, method="delong", na.rm=TRUE)

Does anyone has an idea on this?

Thanks so much!!

Best!

Calimo
  • 7,510
  • 4
  • 39
  • 61
R. E.
  • 1
  • 1
  • 1
    the broom package will turn these into data frames, using either `tidy()` or `glance()` depending on what you try to extract. https://cran.r-project.org/web/packages/broom/vignettes/broom.html – Phil Jul 20 '22 at 20:18
  • Hi, thanks! I tried it out. It says "Error: No glance method recognized for this list.". Both for tidy and glance. Any idea? – R. E. Jul 20 '22 at 20:25
  • I figured it out. I used lapply. Thanks for the tip with tidy()! – R. E. Jul 20 '22 at 20:32

1 Answers1

0

The results of the roc.test function is an S3 object of class htest. It follows the conventions for saving the results of hypothesis tests in R, and prints/works nicely with the base (stats) R functions.

The broom package has a glance function which can convert it to a more programmer-friendly tabular format:

# Generate an htest object from roc.test
library(pROC)
roc1 <- roc(aSAH$outcome, aSAH$s100b)
roc2 <- roc(aSAH$outcome, aSAH$wfns)
x <- roc.test(roc1, roc2)
# Convert it with broom
library(broom)
glance(x)
# A tibble: 1 × 8
  estimate1 estimate2 statistic p.value conf.low conf.high method    alternative
      <dbl>     <dbl>     <dbl>   <dbl>    <dbl>     <dbl> <chr>     <chr>
1     0.731     0.824     -2.21  0.0272   -0.174   -0.0104 DeLong's… two.sided

Make sure to keep the object marked as an htest object and don't accidentally convert it to a list, otherwise the glance function wouldn't know how to handle it.

Calimo
  • 7,510
  • 4
  • 39
  • 61