To set the ball rolling, we may sum up the cumulative posterior probability > 0.5 for each coin. For example, if one coin i
flips ni=10
times with xi=3
heads, the chance of the true pi>0.5
would be the cumulative posterior probability > 0.5. In case of uniform prior, the posterior will have the exact shape of the Binomial likelihood yi = 1 - pbinom(0.5*10, size=10, prob=3/10)
according to this answer.
The expected number of coins with pi>0.5
, that is y=sum(yi)
, should be close to 50. A single simulation below returns y
of 44.45 .
set.seed(1)
#single simulation
p <- c(runif(50, min=0, max=0.5), runif(50, min=0.5, max=1)) #exactly 50 and 50 with p<.5 and >.5
n <- sample(10, size=length(p), replace=TRUE) #number of draw for each ball
a <- rbinom(length(p), size=n, prob=p) / n #observed frequency
#adjust for extreme results
a[a==0] <- 0.05 / n[a==0]
a[a==1] <- 1 - 0.05 / n[a==1]
#expected number of p > 0.5
y <- function(a, n) {
return(sum(pbinom(0.5*n, size=n, prob=a, lower.tail=F)))
}
y(a, n)
#44.44555
However, I'm stuck by the results of 100,000 simulations that show underestimated mean 46.68 . Maybe it's due to low number of coin flip xi<=10
?
set.seed(1)
results <- NULL
for (i in 1:100000) {
p <- c(runif(50, min=0, max=0.5), runif(50, min=0.5, max=1))
n <- sample(10, size=length(p), replace=TRUE)
a <- rbinom(length(p), size=n, prob=p) / n
a[a==0] <- 0.05 / n[a==0]
a[a==1] <- 1 - 0.05 / n[a==1]
results = c(results, y(a, n))
}
mean(results)
# 46.68259
sd(results)
# 2.89322
Somehow, the results are pretty normally distributed.

# dev.new(height=4, width=4)
hist(results, breaks=100, probability=TRUE)
x_ <- seq(0, 100, by=0.1)
lines(x_, dnorm(x_, mean(results), sd(results)), col='red')