Does anybody know why integrate in R breaks for large numbers in a beta?
Asked Answered
K

0

7

I have this joint beta distribution I am trying to integrate over:

alpha1 = 400
beta1 = 26000
alpha2 = 410
beta2 = 26000

integrate(function(y) {
   sapply(y, function(y) {integrate(function(x) dbeta(x, shape1 = alpha1, 
     shape2 = beta1)*dbeta(y, shape1 = alpha2, shape2 = beta2), y,1)$value})
}, 0, 1)

This works for smaller alpha and beta even up to these values. But if I go much larger in beta the integrate function starts breaking. I've been comparing this to the Monte Carlo integration

n_sim = 1000000   # number of simulations
y = rbeta(n_sim, shape1 = alpha2, shape2 = beta2)
C2 = (1-pbeta(y, shape1 = alpha1, shape2 = beta1))
mean(C2)

which yields approximately the same answers for smaller reasonable alpha and beta.

And yes I need larger beta, I understand questioning why I need such large beta. It follows from large data sets. Does anybody know why this breaks? Maybe the inner workings of the integrate function? Is there a work around?

Koweit answered 21/9, 2018 at 16:23 Comment(3)
if objective function is too sharply peaked, initial guess at integration points can fail to find itCurse
also, with alpha/beta values this large, the Beta distribution will be practically indistinguishable from a Normal approximation ...Curse
It works fine for me (R Under development (unstable) (2021-10-31 r81114))Adjoint

© 2022 - 2024 — McMap. All rights reserved.