Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method = "t.test", compare_means calculated P value is different from stat_compare_means #34

Closed
wydty opened this issue Sep 19, 2017 · 3 comments

Comments

@wydty
Copy link

wydty commented Sep 19, 2017

use data

> data("ToothGrowth")
> df <- ToothGrowth
> compare_means(len~dose,data = df,method = "t.test")
# A tibble: 3 x 8
    .y. group1 group2            p        p.adj p.format p.signif method
  <chr>  <chr>  <chr>        <dbl>        <dbl>    <chr>    <chr>  <chr>
1   len    0.5      1 6.697250e-09 1.339450e-08  6.7e-09     **** T-test
2   len    0.5      2 1.469534e-16 4.408602e-16  < 2e-16     **** T-test
3   len      1      2 1.442603e-05 1.442603e-05  1.4e-05     **** T-test
## 0.5 VS 1  p.value=6.697250e-09
> my_comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") )
> ggboxplot(df, x = "dose", y = "len")+ 
+  stat_compare_means(comparisons = my_comparisons,method = "t.test")
## 0.5 VS 1  p.value≈1.3e-07

image

#t.test result  0.5 VS 1
> t.test(df$len[df$dose==0.5],y=df$len[df$dose==1])$p.value
[1] 1.268301e-07

t.test() calculated P value the same of graphics,but compare_means() function is different

kassambara added a commit that referenced this issue Sep 19, 2017
@kassambara
Copy link
Owner

Thank you for pointing this out.

This is due to inconsistency in R base functions.

Internally, compare_means() uses the R base function pairewise.t.test(), which default is to compute pairewise t.test by assumming homocedacity.

In stat_compare_means(), if the argument comparisons is specified, the standard t.test() function is used to compare only the groups specified by users. The problem is that, the default behavior of the standard t.test() is to not assume homocedacity.

This issue is fixed. Now, the default behaviour of pairewise.t.test() is to act as the standard t.test() for consistency in ggpubr.

You can install the latest developmental version of ggpubr (devtools::install_github("kassambara/ggpubr").

Kindly confirm that it works so that we can close the issue, thanks.

@wydty
Copy link
Author

wydty commented Sep 19, 2017

I see,Thank you very much

@wydty wydty closed this as completed Sep 19, 2017
@kcmtest
Copy link

kcmtest commented Jan 1, 2019

I have similar issue with the KW test here is my code and the output of the same ,when im using the base R function the p value reported is different im using the latest version Version: 0.2.999
not sure how to add the generated plot as don't know in github yet but you can run the code and data to see what im doing wrong

My data so that you can run and test to see whats wrong https://drive.google.com/open?id=10vanPZEW77qfImINZvoYiAc8CH2Y0XOi

library(ggpubr)
library(reshape2)
df1 = read.csv("NEW_RBP/CORPLOT/RBP_DISEASE_CLUSTER/RBP_DISEASE_C1_C4_AVG.txt",header = TRUE,sep = "\t",row.names = 1)
head(df1)
my_comparisons <- list( c("HSC", "LSC"), c("LSC", "Blast"), c("HSC", "Blast") )
 
ex <- melt(df1, id.vars=NULL)

head(ex)

ggboxplot(ex, x = "variable", y = "value",ggtheme = theme_bw(base_size = 30),
          color = "variable", palette = "jco", add = "jitter")+ 
  stat_compare_means(comparisons = my_comparisons)+ # Add pairwise comparisons p-value
  stat_compare_means(label.y = 50,method = "wilcox.test")     # Add global p-value


kruskal.test(LSC ~ HSC, data = df1)

	Kruskal-Wallis rank sum test

data:  LSC by HSC
Kruskal-Wallis chi-squared = 416, df = 416, p-value = 0.4908


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants