Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created June 4, 2024 08:30
Show Gist options
  • Save abikoushi/ce24205c14fb4fd117ff7899d732453a to your computer and use it in GitHub Desktop.
Save abikoushi/ce24205c14fb4fd117ff7899d732453a to your computer and use it in GitHub Desktop.
Singed rank plot
signTable <- function(mu,x){
x2 <- x-mu
x2 <- x2[x2 != 0]
data.frame(table(sign(x2)), loc=mu)
}
wilcoxTable <- function(mu,x){
x2 <- x-mu
x2 <- x2[x2 != 0]
data.frame(w=sign(x2)*rank(abs(x2)), loc=mu)
}
x <- rt(30,5) + 1
muv <- seq(min(x),max(x),by=0.1)
dfw <- bind_rows(lapply(muv, wilcoxTable, x=x))
ggplot(dfw,aes(x=loc, y=w))+
geom_tile(height=1, width=0.1, colour="lightgrey")+
geom_vline(xintercept = 1, lty=1, colour="royalblue", alpha=0.7)+
theme_bw()+
labs(y="signed-rank", x = "location parameter (null)")
ggsave("wilcox.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment