| exclude.too.far {mgcv} | R Documentation |
Takes two arrays defining the nodes of a grid over a 2D covariate space and two arrays
defining the location of data in that space, and returns a logical vector with elements TRUE if
corresponding node is too far from data and FALSE otherwise. Basically a service routine for
vis.gam.
exclude.too.far(g1,g2,d1,d2,dist)
g1 |
co-ordinates of grid relative to first axis. |
g2 |
co-ordinates of grid relative to second axis. |
d1 |
co-ordinates of data relative to first axis. |
d2 |
co-ordinates of data relative to second axis. |
dist |
how far away counts as two far. Grid and data are first scaled so that the grid lies exactly
in the unit square, and dist is a distance within this unit square. |
Linear scalings of the axes are first determined so that the grid defined by the nodes in
g1 and g2 lies exactly in the unit square (i.e. on [0,1] by [0,1]). These scalings are
applied to g1, g2, d1 and d2. The minimum Euclidean
distance from each node to a datum is then determined and if it is greater than dist the
corresponding entry in the returned array is set to TRUE (otherwise to FALSE). The
calculations are performed by looping through the nodes (although they are vectorized with respect to the
data): unless there are very few data this is not overly ineffeicient, and avoids using excessive amounts of
memory.
An logical array with TRUE indicating a node in the grid defined by g1, g2 that
is too far from any datum to be included.
Routine is vectorized w.r.t. the data and not the grid: it will be very inefficient if
d1 and d2 are very short while g1 and g2 are very long.
Simon N. Wood simon@stats.gla.ac.uk
http://www.stats.gla.ac.uk/~simon/
library(mgcv) x<-rnorm(100);y<-rnorm(100) # some "data" n<-20 # generate a grid.... mx<-seq(min(x),max(x),length=n) my<-seq(min(y),max(y),length=n) gx<-rep(mx,n);gy<-rep(my,rep(n,n)) tf<-exclude.too.far(gx,gy,x,y,0.1) plot(gx[!tf],gy[!tf],pch=".");points(x,y,col=2)