Created
June 2, 2024 01:31
-
-
Save abikoushi/62e42792de782a58a93b7c3baf6d40df to your computer and use it in GitHub Desktop.
simulation study for wilcox.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(ggplot2) | |
#check the moments | |
integrate(function(x)x*dexp(x), 0,Inf) | |
integrate(function(x)x^2*dexp(x), 0,Inf) | |
integrate(function(x)x*dnorm(x,1,1), -Inf,Inf) | |
integrate(function(x)x^2*dnorm(x,1,1), -Inf,Inf) | |
pv_simfun <- function(n1,n2){ | |
x1 <- rexp(n1) | |
x2 <- rnorm(n2,1,1) | |
pw <- wilcox.test(x1,x2)$p.value | |
pt <- t.test(x1,x2)$p.value | |
data.frame(p=c(pw,pt), method=c("wilxcox","t")) | |
} | |
res <- lapply(1:10000, | |
function(i){set.seed(i);pv_simfun(100,100)}) | |
res <- do.call("rbind",res) | |
ggplot(res,aes(x=p, colour=method, group=method, linetype = method))+ | |
stat_ecdf()+ | |
scale_color_brewer(palette = "Set1")+ | |
theme_bw()+labs(x="nominal", y="actual") | |
ggsave("wil_p.png") | |
ggplot(data = NULL)+ | |
stat_function(fun=dexp, aes(colour="exp"))+ | |
stat_function(fun=dnorm, aes(colour="normal"), args = list(mean=1))+ | |
theme_bw()+xlim(c(-4,4))+labs(colour="pop. dist.", y="density") | |
ggsave("pop_dens.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment