Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created August 26, 2024 09:25
Show Gist options
  • Save abikoushi/395c6b7daf25bf6396232e730eca7c80 to your computer and use it in GitHub Desktop.
Save abikoushi/395c6b7daf25bf6396232e730eca7c80 to your computer and use it in GitHub Desktop.
An simulation of wilcox.test for the compositional data
library(gtools)
library(ggplot2)
library(ggbrick)
set.seed(1)
wp <- numeric(10000)
ksp <- numeric(10000)
tp <- numeric(10000)
for(i in 1:10000){
y1 <- rdirichlet(50,rep(1,10))
y2 <- rdirichlet(50,rep(10,10))
wp[i] <- wilcox.test(y1[,1],y2[,1])$p.value
ksp[i] <- ks.test(y1[,1],y2[,1])$p.value
tp[i] <- t.test(y1[,1],y2[,1])$p.value
}
hist(ksp,main="ks.test",xlab = "p-value")
hist(tp,main="t.test",xlab = "p-value")
hist(wp,main="wilcox.test",xlab = "p-value")
df <- data.frame(x=rep(LETTERS[1:2],each=50),y=c(y1,y2))
ggplot(df,aes(x=x,y=y))+
geom_brick()+
theme_bw()
ggplot(df,aes(x=x,y=y))+
stat_summary(fun.y="mean",geom="col",alpha=0.8)+
stat_summary(geom = "errorbar",width=0.5)+
theme_bw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment