ggpubr icon indicating copy to clipboard operation
ggpubr copied to clipboard

Spearman p-value inconsistency

Open tiagochst opened this issue 6 years ago • 5 comments

Hello,

Someone notice a weird p-value in my correlation plot. When I checked the spearman test from stat_cor is different from the one given by cor.test. The pearson seems to be correct.

Here is an example: http://rpubs.com/tiagochst/inconsistency. I get a 2.2e-16 from stat_cor and 0.3333 from cor.test.

Minimal code below:

data <- data.frame(met = c(0.1073659,0.5130488, 0.0800250), 
                   exp = c(26.10,18.95,47.01)
)
data
spearman.test <- cor.test(x = data$met,y = data$exp, method = "spearman")
spearman.test
p <- ggscatter(data,
               x = "met",
               y = "exp",
               ylab = "log2(TPM + 1)",
               font.label = c(4),
               xlab = "DNA methylation",
               add = "reg.line",                              
               conf.int = FALSE,                                  
               add.params = list(color = "blue",
                                 fill = "lightgray")
)  +    theme(legend.title = element_text(size=8),
          legend.text = element_text(size=8),
          legend.position="right",
          plot.title = element_text(size=8,face="bold"))
p + stat_cor(method = "spearman")

tiagochst avatar Aug 20 '19 16:08 tiagochst

The option exact= FALSE was systematically specified when computing correlation in stat_cor(). Removed now! Thank you for pointing this out.

kassambara avatar Aug 20 '19 20:08 kassambara

We're still running into a similar issue, can someone help us out?

We're using ggpubr 0.4.0.

The following code produces a p-value of 0.019:

library(ggpubr)
SLAVScatterPlot<- ggscatter(SLAVdata, x= "SLAVAdaptationFirstExposure", y= "SLAVAdaptationSecondExposure", 
          add = "reg.line", conf.int = TRUE, 
          cor.coef = TRUE, cor.method = "spearman",
          xlab = "SLA Adaptation Volume First Exposure", ylab = "SLA Adaptation Volume Second Exposure"
)
SLAVScatterPlot <- annotate_figure(SLAVScatterPlot,
                fig.lab = "A", fig.lab.face = "bold"
)
SLAVScatterPlot

While the code below gives a p-value of 0.1158:

resSLAV <- cor.test(Adapt_data$SLAFirstVolume, Adapt_data$SLASecondVolume,
                method = "spearman")
resSLAV

The data (Adapt_data and SLAVdata) are the same, just structured differently, we checked this.

Does anyone have a clue?

tombuurke avatar Aug 26 '20 12:08 tombuurke

I am running into the same issue. Also using the spearman. None of it matches with cor.test.

khayer avatar Mar 23 '22 21:03 khayer

I have the same issue. Could you reopen this discussion?

yzhan360 avatar Sep 26 '22 20:09 yzhan360

I'm having the same issue too. Has this been resolved?

JessQWu avatar Feb 15 '24 21:02 JessQWu