z = 3
N = 45
theta = 0.014
pbinom(z, N, theta, lower.tail = FALSE)
sum(dbinom(z:N, N, theta))
I was expecting both of these expressions return the upper tail region P(x >= 3).
This is an off-by-one error. When dealing with discrete distributions you have to be careful about whether pbinom(..., lower.tail = FALSE)
is calculating Pr(x>=N) or Pr(x>N) ...
sum(dbinom((z+1):N, N, theta))
@r2evans points out that the computed values are equivalent but not identical:
s1 <- sum(dbinom((z+1):N, N, theta))
p1 <- pbinom(z, N, theta, lower.tail = FALSE)
s1 == p1 ## FALSE
all.equal(s1, p1) ## TRUE
(due to floating point limitations)