[R] boundary check

baptiste auguie baptiste.auguie at googlemail.com
Fri Sep 24 13:55:22 CEST 2010


Hi,

I remember a discussion we had on this list a few months ago for a
better way to decide if a point is inside a convex hull. It eventually
lead to a R function in this post,

http://tolstoy.newcastle.edu.au/R/e8/help/09/12/8784.html

I don't know if it was included in the geometry package in the end.

HTH,

baptiste


On 24 September 2010 12:44, Michael Bedward <michael.bedward at gmail.com> wrote:
> Hello,
>
> If an N-dimensional convex hull fits your idea of a "smallest ball"
> then you could try the convhulln function in the geometry package.
>
> For testing if a new point is inside a previously derived hull, one
> brute force approach is to rbind the new point to your data, generate
> a new hull and see if it is the same as the previous one.
>
> I've only used convhulln in low dimensions so I don't know how
> efficient it is when N is large.
>
> Hope this helps.
> Michael
>
>
> On 24 September 2010 19:44, Feng Li <feng.li at stat.su.se> wrote:
>> Dear R,
>>
>> I have a covariates matrix with 10 observations,  e.g.
>>
>>> X <- matrix(rnorm(50), 10, 5)
>>> X
>>             [,1]        [,2]        [,3]        [,4]       [,5]
>>  [1,]  0.24857135  0.30880745 -1.44118657  1.10229027  1.0526010
>>  [2,]  1.24316806  0.36275370 -0.40096866 -0.24387888 -1.5324384
>>  [3,] -0.33504014  0.42996246  0.03902479 -0.84778875 -2.4754644
>>  [4,]  0.06710229  1.01950917 -0.09325091 -0.03222811  0.4127816
>>  [5,] -0.13619141  1.33143821 -0.79958805  2.08274102  0.6901768
>>  [6,] -0.45060357  0.19348831 -1.23793647 -0.72440163  0.5057326
>>  [7,] -1.20740516  0.20231086  1.15584485  0.81777770 -1.2719855
>>  [8,] -1.81166284 -0.07913113 -0.91080581 -0.34774436  0.9552182
>>  [9,]  0.19131383  0.14980569 -0.37458224 -0.09371273 -1.7667203
>> [10,] -0.85159276 -0.66679528  1.63019340  0.56920196 -2.4049600
>>
>> And I define a boundary of X:  The smallest "ball" that nests all the
>> observations of X. I wish to check if a particular point x_i
>>
>>> x_i <- matrix(rnorm(5), 1, 5)
>>> x_i
>>           [,1]      [,2]       [,3]      [,4]      [,5]
>> [1,] -0.1525543 0.4606419 -0.1011011 -1.557225 -1.035694
>>
>> is inside the boundary of X or not. I know it's easy to do it with 1-D or
>> 2-D, but I don't knot how to manage it when the dimension is large.
>>
>> Can someone give a hint? Thanks in advance!
>>
>>
>> Feng
>>
>> --
>> Feng Li
>> Department of Statistics
>> Stockholm University
>> 106 91 Stockholm, Sweden
>> http://feng.li/
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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