Guest User

Untitled

a guest
Jun 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #!/usr/bin/Rscript
  2.  
  3. library(statmod)
  4. library(ggplot2)
  5. library(reshape2)
  6.  
  7. num_samples <- 10
  8.  
  9. pow <- matrix(nrow=(num_samples+1), ncol=(num_samples+1))
  10.  
  11. for(j in 1:(num_samples+1)){
  12. for(i in 1:(num_samples+1)) {
  13. p1 <- (i-1)/num_samples
  14. p2 <- (j-1)/num_samples
  15.  
  16. pow[i, j] <- power.fisher.test(p1, p2, num_samples, num_samples)
  17.  
  18. }
  19. }
  20.  
  21. rownames(pow) <- c(0:num_samples)/num_samples
  22. colnames(pow) <- c(0:num_samples)/num_samples
  23.  
  24. melted_pow <- melt(pow)
  25.  
  26. png('fischer.power.samples.png')
  27.  
  28. 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"))
  29.  
  30. dev.off()
Add Comment
Please, Sign In to add comment