You don't need to define comb
-- this is provided by the function choose
in base R. I think all you need is to combine choose
and sum
to compute your numerator:
total <- function(n) {
sum(choose(a, b:(2*b)) * choose(n-a, b:0)) / choose(n, a) - p
}
# Plot total(n) for various n values:
a <- 8
b <- 4
p <- 0.05
n <- 20:100
plot(n, sapply(n, total))
For these parameters, total(n)
crossed 0 between n=36 and n=37.