[R] Numerical Integration

Ravi Varadhan rvaradhan at jhmi.edu
Wed Nov 8 19:16:31 CET 2006


Can you get an estimate of f(x) at any given x?  If so, the Gaussian
quadrature methods will work, but not otherwise since f(x) must be known at
all the nodes.  A rough approximation to the integral can be obtained using
the trapezoidal rule.  Here is a simple function to do that:
trap.rule <- function(x,y) sum(diff(x)*(y[-1]+y[-length(y)]))/2

However, the use of the word "knots" seems to indicate that some sort of
spline is being fit to the data.  Martha - can you provide more information
about your function f(x)?

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 stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Doran, Harold
Sent: Wednesday, November 08, 2006 1:04 PM
To: Xiaofan Cao; r-help at stat.math.ethz.ch
Subject: Re: [R] Numerical Integration

You might try the statmod package which provides nodes and weights for
gaussian quadrature. 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Xiaofan Cao
> Sent: Wednesday, November 08, 2006 12:43 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Numerical Integration
> 
> Hi everyone,
> 
> I'm trying to integrate f(x) over x where f(x) does not have 
> a close form but only numerical values at certurn knots of x. 
> Is there a way that I can use any generical R function (such 
> as integrate) or any package to do so?
> 
> Thanks! I appreciate your time.
> 
> Best Regards,
> Martha Cao
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>

______________________________________________
R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list