Radial.basis | R Documentation |
Two dimensional radial basis and tensor functions based on a Wendland function and using sparse matrix format to reduce the storage.
Radial.basis(x1, centers, basis.delta, max.points = NULL,
mean.neighbor = 50,
BasisFunction = "WendlandFunction",
distance.type = "Euclidean",
verbose = FALSE)
Tensor.basis(x1, centers, basis.delta, max.points = NULL, mean.neighbor = 50,
BasisFunction = "WendlandFunction", distance.type = "Euclidean")
WendlandFunction(d)
triWeight(d)
x1 |
A matrix of locations to evaluate the basis
functions. Each row of |
centers |
A matrix specifying the basis function centers. For spherical distances these locations are assumed to be in degrees. |
d |
A vector of distances. |
basis.delta |
A vector of scale parameters for the basis functions. |
max.points |
Maximum number of nonzero entries expected for the returned matrix. |
distance.type |
A text string indicate type distance to use between spatial locations when evaluating the basis functions. Default is "Euclidean". Other choices when locations are in degrees ( e.g. longitude and latitude) are "Chordal" and "GreatCircle" with the default units being miles. See Details below how to change the radius that is used. |
mean.neighbor |
Average number of centers that are within delta of each x1 location. For centers on a regular grid this is often easy to estimate. |
BasisFunction |
A function that will take a non-negative argument and be zero outside [0,1]. This is applied to distance(s) to generate the basis functions. For tensor basis functions, the function is applied to the distance components for each dimension. |
verbose |
Print out debugging information if TRUE. |
This function finds the pairwise distances between the points x1 and
centers and evaluates the function RadialBasisFunction at these
distances scaled by delta. In most applications delta is constant, but
a variable delta could be useful for lon/lat regular grids. The
Wendland function is for 2 dimensions and smoothness order 2. See
WendlandFunction
for the polynomial form. This code has a very
similar function to the fields function wendland.cov
.
In pseudo R code for delta a scalar Radial.basis
with the Wendland "shape" evaluates as
BigD<- rdist( x1,centers) WendlandFunction(BigD/basis.delta)
and is comparable to
Radial.basis(x1, centers,basis.delta)
The actual code uses a FORTRAN subroutine to search over distances less than delta and also returns the matrix in sparse format.
Part of the flexibility in these function is to use different distance functions
(metrics). See help on LKDistance
for the S4 method to find distance and
LKDist for the lower level functions that actually do the work.
To change the radius used for the spherical distances one add a Radius
attribute to the text string. For example to use kilometers for great circle
distance ( R approximately 6371)
dtype <- "GreatCircle" attr( dtype, which="Radius") <- 6371
dtype
is still a text string but has the extra bit of information attached to it. Now use distance.type = dtype
for the distance type argument.
The function Tensor.basis
has similar function as the radial
option. The main difference is that a slightly different distance function is
used to return the component distances for each dimension. In pseudo R code
for delta a scalar and for just two dimensions Tensor.basis evaluates as
BigD1<- rdist( x1[,1],centers[,1]) BigD2<- rdist( x1[,2],centers[,2]) WendlandFunction(BigD1/basis.delta) *WendlandFunction(BigD1/basis.delta)
The user is also encourage to consider using the higher level function
LKrig.basis paired with an LKinfo object to define the centers. But besure to use normalize = FALSE
to avoid strange interactions of the SAR model, irrelevant in this case, with the basis function form.
For Radial.basis
and Tensor.basis
a matrix in sparse format with number of
rows equal to nrow(x1) and columns equal to nrow(center) and value are the
basis functions evaluated at these combinations
For WendlandFunction
and triweight
a vector with the values
for this function.
Doug Nychka
LKrig.basis, LKDist
set.seed(12)
x<- cbind( runif(100), runif(100))
center<- expand.grid( seq( 0,1,,5), seq(0,1,,5))
# coerce to matrix
center<- as.matrix(center)
PHI1<- Radial.basis(x, center, basis.delta = .5)
PHI2<- Tensor.basis( x, center, basis.delta = .5 )
# similarity of radial and tensor product forms
plot( c(0,1.1), c(0,1.1), type="p")
for( k in 1:25){
points( PHI1[,k], PHI2[,k])
}
# LKrig with a different radial basis function.
#
data(ozone2)
x<-ozone2$lon.lat
y<- ozone2$y[16,]
# Find locations that are not 'NA'.
# (LKrig is not set up to handle missing observations.)
good <- !is.na( y)
x<- x[good,]
y<- y[good]
obj<- LKrig(x,y,NC=30,nlevel=1, alpha=1, lambda=.01, a.wght=5)
obj1<- LKrig(x,y,NC=30,nlevel=1, alpha=1,
lambda=.01, a.wght=5, BasisFunction="triWeight", overlap=1.8)
# It is usually better to create the LKinfo object first and then call LKrig
LKinfo <- LKrigSetup( x,NC=30,nlevel=1, alpha=1,
lambda=.01, a.wght=5, BasisFunction="triWeight", overlap=1.8 )
obj1B<- LKrig(x,y, LKinfo=LKinfo)
#######################################################
### a radial basis on the sphere
#######################################################
# icosohedral grid at the second generation
allLevels<- IcosahedronGrid(2)
# extract second level
centers3d<- allLevels[[2]]
centers<- toSphere(centers3d)
# take a look
plot( centers, xlim=c(-180,180), ylim=c( -90, 90), pch=16)
lonlat<- make.surface.grid( list( x= seq( -180,180,,80), y= seq( -90,90,,40)))
delta<- 5000 # default distance is in miles
# evaluate all basis functions on the grid
bigX<- Radial.basis( lonlat, centers, basis.delta= delta, distance.type="GreatCircle")
# look at the 12th basis function
b12<- bigX[,12]
image( as.surface( lonlat, b12), col=c( "white",tim.colors(256)), add=TRUE,
xlim="longitude", ylim="latitude")
points( centers, pch=16, col="magenta", cex=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.