Skip to content

Instantly share code, notes, and snippets.

@wwood
Created October 19, 2021 02:49
Show Gist options
  • Save wwood/e4cb06b19e01af74fe05d31e8199a9e0 to your computer and use it in GitHub Desktop.
Save wwood/e4cb06b19e01af74fe05d31e8199a9e0 to your computer and use it in GitHub Desktop.
options(repr.plot.width=15)
analyse <- function(current_samples, p0) {
# p0 = 0.5
print("Current samples:")
print(current_samples)
proportion = sum(current_samples<(p0*n))
print(paste("Proportion less than",p0*n,'is',proportion,"out of",length(current_samples)))
binom_test_result = binom.test(proportion, length(current_samples), p=p0)
print(binom_test_result)
pvalues = c()
means = c()
for (i in 1:length(current_samples)){
pval = binom.test(sum(current_samples[1:i]<(p0*n)), length(current_samples[1:i]), p=p0)$p.value
pvalues = c(pvalues, pval)
means = c(means, mean(current_samples[1:i]))
}
plot1 = qplot(x=1:length(current_samples), y=pvalues, geom='line', ylab='P-value', xlab='number',size=I(4))+geom_hline(colour='blue', yintercept=0.05)
plot2 = qplot(x=1:length(current_samples), y=means, geom='line', ylab='Mean', xlab='number',size=I(4), ylim = c(0,100))+geom_hline(colour='red', yintercept=50)
ggarrange(plot1, plot2, labels=c('A','B'))
}
theme_set(theme_bw() + theme(text = element_text(size = 25)) )
current_samples = c(62,55,45,15,41,24,16, 47,33,1, 63, 24, 55, 40, 44, 49, 2, 48,6,69)
analyse(current_samples, 0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment