Hi Ravi and Harold,

Thanks for the input. I'm using trapezoidal rule and like to know if 
there's other alternatives. This f(x) is the kernel density estimator and 
thus we can get an estimate of f(x) at any given x in theory.

Thanks again,
Martha

  On Wed, 8 
Nov 2006, Ravi Varadhan wrote:

> 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: [EMAIL PROTECTED]
>
> Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
>
>
>
> ----------------------------------------------------------------------------
> --------
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Doran, Harold
> Sent: Wednesday, November 08, 2006 1:04 PM
> To: Xiaofan Cao; r-help@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: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Xiaofan Cao
>> Sent: Wednesday, November 08, 2006 12:43 PM
>> To: r-help@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@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@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@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.

Reply via email to