smooth.2d(Y, ind = NULL, weight.obj = NULL, setup = FALSE, grid = NULL,
x = NULL, nrow = 64, ncol = 64, surface = TRUE, cov.function =
gauss.cov, Mwidth = NULL, Nwidth = NULL, ...)
The kernel function is specified by an function that should evaluate with the kernel for two matrices of locations. Assume that the kernel has the form: K( u-v) for two locations u and v. The function given as the argument to cov.function should have the call myfun( x1,x2) where x1 and x2 are matrices of 2-d locations if nrow(x1)=m and nrow( x2)=n then this function should return a mXn matrix where the (i,j) element is K( x1[i,]- x2[j,]). Optional arguments that are included in the ... arguments are passed to this function when it is used. The default kernel is the Gaussian and the argument theta is the bandwidth. It is easy to write other other kernels, just use Exp.cov.simple as a template.
# Normal kernel smooth of the precip data with bandwidth of .5 ( degree)
#
look<- smooth.2d( RMprecip$y, x=RMprecip$x, theta=.25)
# finer resolution used in computing the smooth
look3<-smooth.2d( RMprecip$y, x=RMprecip$x, theta=.25, nrow=256,
ncol=256,Nwidth=32,
Mwidth=32)
# if the width arguments were omitted the padding would create a
# 512X 512 matrix with the data filled in the upper 256X256 part.
# with a bandwidth of .25 degrees the normal kernel is essentially zero
# beyond 32 grid points from its center ( about 6 standard deviations)
#
# take a look:
#set.panel(2,1)
#image( look3, zlim=c(-8,12))
#points( RMprecip$x, pch=".")
#image( look, zlim =c(-8,12))
#points( RMprecip$x, pch=".")
# bandwidth changed to .25, exponential kernel
look2<- smooth.2d( RMprecip$y, x=RMprecip$x, cov.function=Exp.cov,theta=.25)
#
Run the code above in your browser using DataLab