On Jun 23, 2011, at 8:55 AM, Adan_Seb wrote:
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)
Right. integrand() is NaN outside [0,1]
> integrand(1:100)
[1] 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
[22] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
[43] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
[64] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
[85] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
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.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.