Trying to run an ANOVA or Kruskall Wallis but struggling
1
0
Entering edit mode
2.9 years ago
abb525 • 0

Hi there

So I seem to be struggling with running any of the statistical tests, I believe because my data is not normally distributed (according to shapiro wilkes test) I technically need to run a Kruskall Wallis test(?). Originally I realised I needed to restructure my matrix into a vector, which I have now done, so that I have the 1st column containing the Simpsons index values across all the samples, and then the 2nd (group column) containing labels of the taxanomic phyla these values are associated with.

I am trying to run a statistical significance test to see if there is a significant difference between one of the taxanomic phyla groups and the other phyla groups, in terms of the simpsons Index values.

    tmp_vector=as.vector(tmp)

tmp_vector

labels=as.vector(sapply(colnames(tmp), function(i){rep(i, dim(tmp)[1])}))

labels

fungi_vector = cbind(tmp_vector, labels)

fungi_vector

The former is the code I used to generate my vector.

enter image description here

And here is a snippet of the output.

Could do with some help as to figuring out how to run the test I need to as I'm not very experienced with R.

Regards

Simpsons R ANOVA kruskall wallis Index • 988 views
ADD COMMENT
1
Entering edit mode
2.9 years ago

Hi,

Please permit that I first reproduce some data in the same format as yours:

fungi_vector <- data.frame(
  tmp_vector = c(rnorm(10, 0.7, 0.1), rnorm(10, 0.2, 0.1)),
  labels = c(rep('Ascomycota', 10), rep('Basidiomycota', 10)))
fungi_vector$tmp_vector <- as.character(fungi_vector$tmp_vector)
str(fungi_vector)
'data.frame':   20 obs. of  2 variables:
 $ tmp_vector: chr  "0.651365595291301" "0.661684503596836" "0.755288193037626" "0.666716503201382" ...
 $ labels    : chr  "Ascomycota" "Ascomycota" "Ascomycota" "Ascomycota" ...


Então / So, the first issue is that your column of numbers is encoded as characters; so, we first need to convert that to numerical values:

fungi_vector$tmp_vector <- as.numeric(fungi_vector$tmp_vector)

To be proper, we should also convert the second column to categorical values:

fungi_vector$labels <- factor(fungi_vector$labels,
  levels = c('Ascomycota','Basidiomycota'))

Then, a Kruskal Wallis test can be done like this:

kruskal.test(tmp_vector ~ labels, fungi_vector)

    Kruskal-Wallis rank sum test

data:  tmp_vector by labels
Kruskal-Wallis chi-squared = 14.286, df = 1, p-value = 0.0001571

For my 'manufactured' data, I already knew that the p-value would be statistically significant due to the fact that I had pre-selected different means via rnorm() (see above).

We can also plot this:

boxplot(tmp_vector ~ labels, fungi_vector)

ggg

I will leave the remainder to you.

Kind regards,

Kevin

ADD COMMENT
0
Entering edit mode

So would this then compare if there's a statistically significant difference across all of the groups? There are several more phyla groups in the dataset.

The objective was to basically determine if there was a statistically significant difference between Ascomycota and the other phyla in the data.

Although using the code you showed me has definitely worked in giving me a P value when I run the Kruskall Wallis on the whole dataset.

ADD REPLY
0
Entering edit mode

So would this then compare if there's a statistically significant difference across all of the groups? There are several more phyla groups in the dataset.

Yes.

The objective was to basically determine if there was a statistically significant difference between Ascomycota and the other phyla in the data.

In this case, please try Dunn's post-hoc test via FSA::dunnTest() ( see https://www.rdocumentation.org/packages/FSA/versions/0.8.32/topics/dunnTest ). This can be run in the same way as kruskal.test()

ADD REPLY
0
Entering edit mode

Would the Pairwise Wilcoxon test also be relevant? Since I am trying to find out specifically the significant differences between groups? That looks like it shouldn't be too hard to code for either.

ADD REPLY
1
Entering edit mode

If they are logically paired, then no problem using the Wilcoxon, of course.

ADD REPLY

Login before adding your answer.

Traffic: 2607 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6