Created
August 17, 2016 21:18
-
-
Save thomaswp/e3b6324964c34f69d022d9f2e6a13bac to your computer and use it in GitHub Desktop.
This file contains 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
# Generates an array of arrays of arguments to a prop test to check it | |
chiSqTest <- function(n) { | |
# Set seed for consistency | |
set.seed(1234) | |
# Generate n (counts), p (proportions) and s (successes) | |
n1s <- round(runif(n, 80, 120)) | |
n2s <- round(runif(n, 80, 120)) | |
p1s <- round(c(runif(n / 2, 0, 0.5), runif(n / 2, 0.5, 1)), 3) | |
p2s <- round(c(runif(n / 2, 0, 0.5), runif(n / 2, 0.5, 1)), 3) | |
s1s <- n1s * p1s | |
s2s <- n2s * p2s | |
# Do the significance tests | |
sigs <- sapply(1:n, function(i) prop.test(c(s1s[i], s2s[i]), c(n1s[i], n2s[i]), correct=F)$p.value < 0.05) | |
sigs <- ifelse(sigs, "true", "false") | |
# Create the JS array | |
rows <- paste(n1s, n2s, p1s, p2s, sigs, sep=",") | |
arrayify <- function(...) { | |
paste("[[", paste(..., sep="], ["), "]]", sep="") | |
} | |
do.call(arrayify, as.list(rows, sep="], [")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment