Created
April 7, 2022 13:07
-
-
Save abikoushi/6c40d5bbc40c1435a364221c7e548aa6 to your computer and use it in GitHub Desktop.
An comparison between Wilcoxon and Student's t test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(parallel) | |
### | |
#panel function for pairs-plot | |
panel.ecdf <- function(x,...){ | |
x <- sort(x) | |
y <- seq(0,1,length.out=length(x)) | |
lines(x, y, type="s", col="black",lwd=2) | |
abline(a = 0, b = 1, col="cornflowerblue", lty="dotted", lwd=2) | |
} | |
add_line <- function(x,y,...){ | |
points(x,y,...) | |
abline(a = 0, b = 1, col="salmon", lwd=1.5) | |
} | |
### | |
simfunc <- function(i, m, n){ | |
set.seed(i) | |
x1 <- rweibull(m,0.8) | |
x2 <- rweibull(n,0.8) | |
R <- rank(c(x1,x2)) | |
r1 <- R[1:m] | |
r2 <- R[(m+1):(m+n)] | |
tres <- t.test(r1, r2, var.equal = TRUE) | |
wres <- wilcox.test(x1, x2) | |
c(t=tres$p.value, wilcox=wres$p.value) | |
} | |
outsim1 <- mclapply(1:1000, simfunc, m=20, n=20, | |
mc.cores = detectCores()) | |
p_df <- as.data.frame(t(simplify2array(outsim1))) | |
pairs(t~wilcox, data=p_df, | |
panel = add_line, | |
diag.panel = panel.ecdf, | |
col=rgb(0,0,0,0.2)) | |
#dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment