[R] How to do a probability density based filtering in 2D?
Emmanuel Levy
emmanuel.levy at gmail.com
Sat Nov 20 03:40:21 CET 2010
Hello David,
I thought about this at first as well, e.g.,
x1.lim = quantile(x1,prob=c(0.05,0.95))
y2.lim = quantile(y2,prob=c(0.05,0.95))
x1.sub = x1[ x1 > x1.lim[1] & x1 < x1.lim[2] & y2 > y2.lim[1] & y2 <
y2.lim[2]]
y2.sub = y2[ x1 > x1.lim[1] & x1 < x1.lim[2] & y2 > y2.lim[1] & y2 <
y2.lim[2]]
But this is actually does not do what I want because it is not based
on the density of the data. What I would like is to keep only the
points within an area where the density of points is over x.
In other words, if you imagine a contour plot, I'd like to keep all
the points within a given contour line. So the data has to be
interpolated or smoothed at some point. I am using the kde2d function
of the MASS package to plot contour lines but I don't know how to
retrieve subsets of what I plot.
Also I wouldn't be surprised if there is a trick with quantile that
escapes my mind.
Thanks for your help,
Emmanuel
On 19 November 2010 21:25, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Nov 19, 2010, at 8:44 PM, Emmanuel Levy wrote:
>
>> Hello,
>>
>> This sounds like a problem to which many solutions should exist, but I
>> did not manage to find one.
>>
>> Basically, given a list of datapoints, I'd like to keep those within
>> the X% percentile highest density.
>> That would be equivalent to retain only points within a given line of
>> a contour plot.
>>
>> Thanks to anybody who could let me know which function I could use!
>
> What's wrong with quantile?
>
> --
> David Winsemius, MD
> West Hartford, CT
>
>
More information about the R-help
mailing list