[R] density function

Greg Snow 538280 at gmail.com
Wed Jun 27 21:04:05 CEST 2012


Here are 2 approaches:

Use logspline density estimates (logspline package) rather than kernel
density estimates, this can give you a function to pass to integrate
or other tools, the estimates may be a little different from the
kernel density estimates.

If you need to use kernel density estimates, then realize that the kde
is just the sum of 1/n times the kernel centered at each of the n
points.  And the integral of a sum is the sum of the integrals (and
the 1/n can be factored out), so you can just integrate each of the n
kernals (centered at the datapoints with proper width), then sum and
divide by n (or take the mean).

On Tue, Jun 26, 2012 at 6:13 PM, pilaw <pilawski.p at gmail.com> wrote:
> Hello,
>
> I need density function so that I can find expected value (using
> integration). I use density():
> f= density(data)
> but f isn't a function and I can't get values and integrate it
> This is very urget, so please help.
>
> Greetings
> Peter
>
> --
> View this message in context: http://r.789695.n4.nabble.com/density-function-tp4634563.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com



More information about the R-help mailing list