Skip to content

Instantly share code, notes, and snippets.

@adamewing
Created June 18, 2018 06:07
Show Gist options
  • Save adamewing/979efc6a6a63844d1817b496bd258256 to your computer and use it in GitHub Desktop.
Save adamewing/979efc6a6a63844d1817b496bd258256 to your computer and use it in GitHub Desktop.
#!/usr/bin/Rscript
library(statmod)
library(ggplot2)
library(reshape2)
num_samples <- 10
pow <- matrix(nrow=(num_samples+1), ncol=(num_samples+1))
for(j in 1:(num_samples+1)){
for(i in 1:(num_samples+1)) {
p1 <- (i-1)/num_samples
p2 <- (j-1)/num_samples
pow[i, j] <- power.fisher.test(p1, p2, num_samples, num_samples)
}
}
rownames(pow) <- c(0:num_samples)/num_samples
colnames(pow) <- c(0:num_samples)/num_samples
melted_pow <- melt(pow)
png('fischer.power.samples.png')
ggplot(data=melted_pow, aes(x=Var1, y=Var2, fill=value)) + geom_tile() + labs(y="Fraction of Responders", x="Fraction of Non-Responders") + guides(fill=guide_legend("power"))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment