# [R] Help Regarding 'integrate'

From: A <born.to.b.wyld_at_gmail.com>
Date: Thu, 21 Aug 2008 01:44:35 -0500

f<-function(x){
return(dchisq(x,9,77)*((13.5/x)^5)*exp(-13.5/x)) }

Numerically integrating this function, I observed a couple of things:

1. Integrating the function f over the entire positive real line gives an error:
> integrate(f,0,Inf)
Error in integrate(f, 0, Inf) : the integral is probably divergent
2. Increasing the interval of integration actually decreases the value of the integral:
> integrate(f,0,10^5)
9.813968e-06 with absolute error < 1.9e-05
> integrate(f,0,10^6)
4.62233e-319 with absolute error < 4.6e-319

Since the function f is uniformly positive, B) can not occur. Also, the theory tells me that the infinite integral actually exists and is finite, so A) can not occur. That means there are certain problems with the usage of function 'integrate' which I do not understand. The help document tells me that 'integrate' uses quadrature approximation to evaluate integrals numerically. Since I do not come from the numerical methods community, I would not know the pros and cons of various methods of quadrature approximation. One naive way that I thought of evaluating the above integral was by first locating the maximum of the function (may be by using 'optimize' in R) and then applying the Simpson's rule to an interval around the maximum. However, I am sure that the people behind the R project and other users have much better ideas, and I am sure the 'correct' method has already been implemented in R. Therefore, I would appreciate if someone can help me find it.

Thanks

[[alternative HTML version deleted]]

R-help_at_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. Received on Thu 21 Aug 2008 - 06:47:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Aug 2008 - 08:33:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.