Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created June 28, 2024 06:24
Show Gist options
  • Save abikoushi/9d55649944b90a55a06f8bb4dc23f310 to your computer and use it in GitHub Desktop.
Save abikoushi/9d55649944b90a55a06f8bb4dc23f310 to your computer and use it in GitHub Desktop.
An example of P-value function
library(ggplot2)
set.seed(123)
x <- rweibull(50,1.5) - log(2)^(1/1.5)
qweibull(0.5,1.5)- log(2)^(1/1.5) #中央値が0の分布
sx <- jitter(sort(x)) #ちょうど0をなくすため
pv_w <- sapply(sx,function(m)wilcox.test(x, mu=m)$p.value)
pv_s <- sapply(sx,function(m)binom.test(sum(x>m), length(x))$p.value)
df4p <- data.frame(x=x,sx=sx,sign=pv_s,wilcox=pv_w)
m <- median(x)
null_wilcox <- wilcox.test(x, conf.int = TRUE)
ggplot(df4p, aes(x=sx))+
geom_step(aes(y=sign, colour="sign"))+
geom_step(aes(y=wilcox, colour="wilcoxon"))+
geom_rug(aes(x=x))+
geom_point(data = NULL,aes(x=null_wilcox$estimate,y=0, colour="wilcoxon"))+
geom_point(data = NULL,aes(x=m,y=0, colour="sign"))+
theme_bw(18)+
labs(colour="method", y="p-value", x="x")
#ggsave("pfun_wil.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment