When the limits are infinite, it is not a good idea to use "large" but
finite real numbers as approximate limits. It is best to use -Inf and/or
+Inf. See the examples on the help page. Sometimes, setting a more
stringent convergence criterion, i.e. decreasing rel.tol, helps, but it is
best to use infinite limits.
I think this has to do with the transformation of the region of integration
that is done in all the quadrature rules, so that the resulting region
corresponds to appropriate regions for the corresponding orthogonal
polynomials. For example, it is (-1, 1) for Gauss-Legendre quadrature.
Ravi.
----------------------------------------------------------------------------
-------
Ravi Varadhan, Ph.D.
Assistant Professor, The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email: rvaradhan at jhmi.edu
Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
----------------------------------------------------------------------------
--------
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of Allan Clark
Sent: Monday, February 23, 2009 8:10 AM
To: r-help at stat.math.ethz.ch
Subject: [R] r: intergrate behaviour
hello R users
strange behavior of the integrate function!
i assume this occurs because of the way in which the quadriture is set up!
(any comments.)
f=function(x){exp(-exp(-x)-5*x)/gamma(5)}
xx=seq(from=-20, to=20, length.out=1000)
plot(xx,f(xx),type="l")
integrate(f, lower=-Inf, upper= 1)
integrate(f, lower=-Inf, upper= 10)
integrate(f, lower=-10, upper= 11)
integrate(f, lower=-Inf, upper= 11)
integrate(f, lower=-Inf, upper= Inf)
the results:
> integrate(f, lower=-Inf, upper= 1)
0.9999586 with absolute error < 2.1e-06
> integrate(f, lower=-Inf, upper= 10)
1 with absolute error < 1.6e-06
> integrate(f, lower=-10, upper= 11)
1 with absolute error < 7.1e-06
> integrate(f, lower=-Inf, upper= 11)
1.375693e-06 with absolute error < 2.3e-06
> integrate(f, lower=-Inf, upper= Inf)
1 with absolute error < 3.1e-05
i dont get the same behaviour for J.K. Lindsey's int function.
Allan Clark
=======Lecturer in Statistical Sciences Department University of Cape Town
7701 Rondebosch
South Africa
TEL (Office): +27-21-650-3228
FAX: +27-21-650-4773
http://web.uct.ac.za/depts/stats/aclark.htm
[[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.