4
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).

dp2023
  • 43
  • 3

1 Answers1

5

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)

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 2
    But for the curious, while `sum(dbinom((z+1):N, N, theta)) == pbinom(z, N, theta, lower.tail = FALSE)` is `FALSE`, it's due to https://stackoverflow.com/q/9508518/3358272, https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f, not a flaw in the `*binom` functions. – r2evans Mar 23 '23 at 17:03