p <- .05
k <- c(-1.2,-0.5, 1.5, 10.4)
n <- 10
ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),
ifelse (k < -1, 0, 1) )
Warning message:
In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
suppressWarnings(ans <- ifelse (k >= -1 & k <= n,
pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse (k < -1, 0, 1) ))
## no warnings
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Thu, Oct 7, 2021 at 10:21 AM Ravi Varadhan via R-help <
r-help at r-project.org> wrote:
Hi,
I would like to execute the following vectorized calculation:
ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE),
ifelse (k < -1, 0, 1) )
For example:
k <- c(-1.2,-0.5, 1.5, 10.4)
n <- 10
ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),
ifelse (k < -1, 0, 1) )
Warning message:
In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
[1] 0.000000000 0.006821826 0.254991551 1.000000000
The answer is correct. However, I would like to eliminate the annoying
warnings. Is there a better way to do this?
Thank you,
Ravi
[[alternative HTML version deleted]]