[R] numerical integration and 'non-finite function value' error

Adan_Seb dmuluwork at gmail.com
Thu Jun 23 14:55:47 CEST 2011


Here is a self-contained example of my problem. 

set.seed(100)
x = rbeta(100, 10.654, 10.439)
# So the shape parameters and the exteremes are
a = 10.654
b = 10.439
xmax = 1
xmin = 0
# Using the non-standardized form (as in my application and this shouldn't
make any difference) of the 
# Beta density function, I specify the  integrand (i.e., xf(x)) as
integrand = function(x) {x*((1/beta(a,b))*((x^(a - 1)*(xmax - x)^(b-1)) /
xmax^(a + b - 1)))}
 
# Say I want to integrate in the range (0, 0.45) and then in (0.45, Inf)
# In (0, 0.45)
 
integrate(integrand, lower = 0, upper = 0.45)$val
[1] 0.1176079

# In (0.45, Inf)
 
integrate(integrand, lower = 0.45, upper = Inf)$val
Error in integrate(integrand, lower = 0.45, upper = Inf) : 
  non-finite function value

The same thing happens when I integrate f(x) only.
Thanks again.


--
View this message in context: http://r.789695.n4.nabble.com/numerical-integration-and-non-finite-function-value-error-tp3618486p3619761.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list