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)
Run the code above in your browser using DataLab