kassambara / rstatix

Pipe-friendly Framework for Basic Statistical Tests in R
https://rpkgs.datanovia.com/rstatix/
449 stars 51 forks source link

wilcox_test gives an error: Error in if (f.lower <= 0) return(mumin) #79

Open microresearcher opened 4 years ago

microresearcher commented 4 years ago

Hi,

I am using the rstatix package to compare the microbiota between three different groups, and when using the pairwise_wilcox_test I ran into an issue with certain bacteria where it gave the following error:

Error in if (f.lower <= 0) return(mumin) : missing value where TRUE/FALSE needed

Running the base pairwise.wilcox.test function worked perfectly fine on these bacteria though. When I took a look at the specific bacteria, I found that they were present in one group and absent in the other two, so I suspect that is related to the issue. I would really like to find a way to make this work, however, as I am using the output of pairwise_wilcox_test to generate boxplots of the significant bacteria with p-value annotations using stat_pvalue_manual, which the rstatix package seems to work really well for.

Seeing as the base pairwise.wilcox.test ran fine, I would think that pairwise_wilcox_test is intended to be able to handle this as well. I'd appreciate any help with this!

Thanks in advance.

kassambara commented 4 years ago

Hi, would you please provide a reproducible R code with a demo data (using the reprex R package)

XMinFu commented 3 years ago

Hi, I am meeting the same problem as you described by using rstatix package. I am wondering if you find some solutions for it? I am appreciative of any shares or helps with it! Thank you in advance!

kassambara commented 3 years ago

A reproducible script with a demo data are needed so that I can help efficiently.

guanxn90 commented 3 years ago

A reproducible script with a demo data are needed so that I can help efficiently.

@kassambara Hi, thanks a lot for this great package! I encountered the same error, though the cause might be different. After checking my data, I though it could be caused by 'all 0 values in one group'. When using the following minimal code, I reproduced the same error. Please see below:

` library(rstatix)

reproduce the error

df <- data.frame(group = c(rep('a', 10), rep('b', 10)), value = rep(0, 20)) t_test(df, value ~ group) wilcox_test(df, value ~ group)

base R ttest and wilcox test is fine; show warning, but not error

t.test(rep(0, 10), rep(0, 10)) wilcox.test(rep(0, 10), rep(0, 10))

to show the error only happens when one group has all 0 value

df <- data.frame(group = c(rep('a', 10), rep('b', 10)), value = 1:20) t_test(df, value ~ group) wilcox_test(df, value ~ group)

`

fredust commented 2 years ago

A reproducible script with a demo data are needed so that I can help efficiently.

@kassambara Hi, thanks a lot for this great package! I encountered the same error, though the cause might be different. After checking my data, I though it could be caused by 'all 0 values in one group'. When using the following minimal code, I reproduced the same error. Please see below:

` library(rstatix)

reproduce the error

df <- data.frame(group = c(rep('a', 10), rep('b', 10)), value = rep(0, 20)) t_test(df, value ~ group) wilcox_test(df, value ~ group)

base R ttest and wilcox test is fine; show warning, but not error

t.test(rep(0, 10), rep(0, 10)) wilcox.test(rep(0, 10), rep(0, 10))

to show the error only happens when one group has all 0 value

df <- data.frame(group = c(rep('a', 10), rep('b', 10)), value = 1:20) t_test(df, value ~ group) wilcox_test(df, value ~ group)

`

Hello, I met the same problem, I wonder if you have solved this problem? Thank you very much.

microresearcher commented 2 years ago

Sorry for not following up. The script guanxn90 shared is indeed what gets me the error as well. Hope what they shared is helpful in solving the issue! Thanks again

Victor-K27 commented 2 years ago

Hi all, I am getting the same error, I was wondering whether you figured out what is wrong.

mlyjones commented 2 years ago

@Victor-K27 I was getting this same error as well, but eventually realized that there were a lot of zeros in the data for each group I was using, so I had to use a different tool to deal with the zero inflated values. The tool I found and used was https://github.com/chvlyl/ZIR/

marwa38 commented 2 years ago

Hi @kassambara I got the same error (Error in if (f.lower <= 0) return(mumin) : missing value where TRUE/FALSE needed) and here is a reproducible example

ps.prev.phylum is attached as .zip of .rds vector that you can read as follow ps.prev.phylum <- readRDS("ps.prev.phylum.rds") ps.prev.phylum.zip

# psmelt 
ps.prev.phylum_melt <- ps.prev.phylum %>%
  psmelt()
# log transform
ps.prev.phylum_melt$logAbundance <- log10(1 + ps.prev.phylum_melt$Abundance)
# select only Fusobacteriota
ps.prev.phylum_melt.fuso <- subset(ps.prev.phylum_melt, subset = Phylum == "Fusobacteriota")
# pairwise wilcox 
ps.prev.phylum_melt.fuso.pairwise <- pairwise_wilcox_test(ps.prev.phylum_melt.fuso,
                                                           Abundance ~ Sample_Regime,
                                                           p.adjust.method = "BH")
Error in if (f.lower <= 0) return(mumin) : missing value where TRUE/FALSE needed
basedank commented 1 year ago

I have this same error when I try using wilcox_test, which is the test I need to use. When I try using t_test, it works without a single issue.

maxkarlsson commented 1 year ago

I had this issue too, but found that it was due to that some values were non-finite (Inf, to be precise) in the data. When removing those, the test worked fine.

flyinchang commented 1 year ago

@Victor-K27 I was getting this same error as well, but eventually realized that there were a lot of zeros in the data for each group I was using, so I had to use a different tool to deal with the zero inflated values. The tool I found and used was https://github.com/chvlyl/ZIR/

Exactly the same issue for me, and the solution works! Thanks for sharing.