[R] Kernel Density Estimation at manually specified points

David L Carlson dcarlson at tamu.edu
Mon Jun 27 19:16:39 CEST 2011


Look at ?approx. For your example (of course your random numbers give
different results):

> approx(f$x, f$y, c(-2, -1, 0, 1, 2))
$x
[1] -2 -1  0  1  2

$y
[1] 0.03757113 0.19007982 0.31941779 0.37066592 0.10227509

approx gives NA's if you try to interpolate outside the bounds of the data.
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Carsten Harlaß
Sent: Sunday, June 26, 2011 7:02 PM
To: r-help at r-project.org
Subject: [R] Kernel Density Estimation at manually specified points

Hello,

my name is Carsten. This ist my first post to R-help mailing list.

I estimate densities with the function "density" out of the package
"stats".

A simplified example:

	
	#generation of test data
	n=10
	z = rnorm(n)
	
	#density estimation
	f=density(z,kernel="epanechnikov",n=n)

	#evaluation
	print(f$y[5])

Here I can only evaluate the estimation at given points. These points
are determined by the parameter n. By default they are equidistant
distributed on the interesting interval.

But I need to evaluate the estimation (the estimated densitiy function)
at manually specified points. For example I want to compute f(z[i]).
This means I am interested in the estimated density at a the observation
z[i].

Does anyone know how I can compute this? I think this is an ordinary
task so I would be surprised if R can not manage this. But even after a
long search I have found nothing.

Thanks in advance

Carsten Harlaß

--
Carsten Harlaß
Aachen University of Applied Sciences
Campus Jülich
E-Mail: carsten_harlass at web.de

______________________________________________
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.



More information about the R-help mailing list