I was wondering why the expected value (i.e., long-run average) of the p-values from a simulation of a binomial experiment in the below experiment becomes roughly about $.61$, regardless of $p$; the probability of success?
Here is my simulation code in R:
simulation <- function(n, p, n.sim){
fun = function(){
x = rbinom(1, n, p)
pe = x/n
p.value = binom.test(x, n, p)[[3]]
c(p.value, pe)
}
sim <- t(replicate(n.sim, fun()))
par(mfcol = c(2, 2))
plot(sim[, 1], 1:n.sim, xlim = c(0, 1), pch = 19, col = 2, main = "p.value")
plot(sim[, 2], 1:n.sim, xlim = c(0, 1), pch = 19, col = 4, main = "proportion")
abline(v = p, lty = 2, col = 2)
hist(sim[, 1], main = "p.value")
hist(sim[, 2], main = "proportion")
list(p.value = mean(sim[, 1]), proportion = mean(sim[, 2]))
}
simulation(n = 15, p = .1, n.sim = 1e3) ## Change p to whatever and p.value remains around .61
n
to 15) and then what happens? $\endgroup$