0
$\begingroup$

I am trying to do Wilcox test to detect the significant difference in alpha diversity but it is showing an error? physeqN2 is a phyloseq object and Season is a metadata column.

results = estimate_richness(physeqN2, measures = 'Chao1')

d = sample_data(physeqN2)

# calculate Wilcox Test
Wet.root = results[d[,'Season'] == 'Wet',]
Dry.root = results[d[,'Season'] == 'Dry',]
pmv <-pairwise.wilcox.test(Wet.root, Dry.root)

capture.output(pmv, file = "chao1.16s.wet_vs_Dry.root.txt")

Error;
Error in wilcox.test.default(xi, xj, paired = paired, ...) :
  'x' must be numeric
Calls: pairwise.wilcox.test ... compare.levels -> wilcox.test -> wilcox.test.def                                                                                        ault
Execution halted

I hvae tried to do it in another way but here also getting error?

alpha.diversity <- estimate_richness(physeqN2, measures=c("Chao1"))


## Wilcox on observed richness
data <- cbind(sample_data(physeqN2), alpha.diversity)
pmv <-pairwise.wilcox.test(Chao1 ~ Season, data)

capture.output(pmv, file = "chao1.16s.wet_vs_Dry.root.txt")

Error:

Error in if (length(ans) == 0L || as.character(ans[[1L]])[1L] == "~") { :
  missing value where TRUE/FALSE needed
Calls: pairwise.wilcox.test ... sapply -> lapply -> FUN -> compare.levels -> [ -> [.formula
Execution halted

Many thanks

$\endgroup$
2
  • $\begingroup$ Is the data truely paired? $\endgroup$
    – M__
    Oct 7 '20 at 11:33
  • 1
    $\begingroup$ ?pairwise.wilcox.test, Your syntax is wrong in both examples pairwise.wilcox.test(results,d) seems more likely. But as Michael mentioned you might not want to do a paired test. $\endgroup$
    – Greg
    Oct 7 '20 at 12:29
0
$\begingroup$

I think this is a bug in the input data.

At a wild guess what I think is happening is the input data is not regarded as paired, hence the error paired = paired. The other weird error is x must be numeric. Firstly,

  • how are you scoring missing data, its not via - by any chance? Missing data must be via nan type syntax.
  • are you sure there are no heading bugs? Like a header is getting dragged into the numeric data?

Wilcoxan is a non-parametric T test, so the wet root and dry root must match exactly the same sample. Thus it is not a general wet root versus generic dry root, but wet and dry from the same specimen. If this is the data you have the program doesn't think it is matching.

If it is truely paired, again I think the source of error is you have some missing value which is leaving the pairings unequal lengths or else a header bug.

If the data genuinely isn't paired, then I would look at the Mann-Whitney U test, it would be easier in this scenario.

I don't use R syntax (just pandas dataframes) so can't say whether the syntax in the first example is valid, but it is pretty clear regarding your input. In Python you'd generally just give it the entire dataframe and tell it to go figure.

The reality is that loads of programs do Wilcoxan, you don't need to use R if its a one-off test. Obviously if this a part of a pipeline (automation) thats a bit different.

$\endgroup$
2
  • $\begingroup$ Hi Michael, I have merged two factor (region & season) into single one and then did annova test followed by posthoc and it work well. Should I update the code? $\endgroup$ Oct 11 '20 at 6:21
  • $\begingroup$ No that's fine thanks. You can answer your own question however, but are not obliged to do so. $\endgroup$
    – M__
    Oct 11 '20 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.