#
# Midwest ozone data 'day 16' stripped of missings
data( ozone2)
y<- ozone2$y[16,]
good<- !is.na( y)
y<-y[good]
x<- ozone2$lon.lat[good,]
# nearly interpolate using defaults (Exponential)
mKrig( x,y, theta = 2.0, lambda=.01)-> out
#
# NOTE this should be identical to
# Krig( x,y, theta=2.0, lambda=.01)
# interpolate using tapered version the taper scale is set to 1.5
# Default covariance is the Wendland.
# Tapering will done at a scale of 1.5 relative to the scaling
# done through the theta passed to the covariance function.
mKrig( x,y,cov.function="stationary.taper.cov",
theta = 2.0, lambda=.01, Taper.args=list(theta = 1.5, k=2)
) -> out2
predict.surface( out2)-> out.p
surface( out.p)
# here is a bigger problem
# using a compactly supported covariance directly
#
# Also note increase in the temp space sie for the
# Cholesky decomposition. Default size (1e5) is too small
#
set.seed( 334)
N<- 1000
x<- matrix( 2*(runif(2*N)-.5),ncol=2)
y<- sin( 1.8*pi*x[,1])*sin( 2.5*pi*x[,2]) + rnorm( 1000)*.01
mKrig( x,y, cov.function="wendland.cov",k=2, theta=.1,
lambda=1e2)-> look2
# The following will fail for theta=.2 because tmpmax and max.points are too
# small. (Here theta controls the support of the covariance and so
# indirectly the number of nonzero elements in the sparse matrix
# mKrig( x,y, cov.function="wendland.cov",k=2, theta=.3, lambda=1e2)-> look2
# as a guess on the size of tmpmax this was set to mean.neighbor* nrow(x)
mKrig( x,y,
cov.function="wendland.cov",k=2, theta=.3,
lambda=1e2, mean.neighbor=150,
chol.args=list( memory=list( tmpmax=150*1000))
)-> look2
predict.surface( look2)-> out.p
surface( out.p)
#
# Using mKrig for evaluating a solution on a big grid.
# (Thanks to Jan Klennin for motivating this example.)
x<- RMprecip$x
y<- RMprecip$y
Tps( x,y)-> obj
# make up an 80X80 grid that has ranges of observations
# use same coordinate names as the x matrix
glist<- fields.x.to.grid(x, nx=80, ny=80) # this is a cute way to get a defautl grid that covers x
# convert grid list to actual x and y values ( try plot( Bigx, pch="."))
make.surface.grid(glist)-> Bigx
# include actual x locations along with grid.
Bigx<- rbind( x, Bigx)
# evaluate the surface on this set of points (exactly)
predict(obj, x= Bigx)-> Bigy
# theta sets range for the compact covariance function
# this will involve less than 20 nearest neighbors tha have
# nonzero covariance
theta<- c( 2.5*(glist$lon[2]-glist$lon[1]),
2.5*(glist$lat[2]-glist$lat[1]))
# this is an interplotation of the values using a compact
# but thin plate spline like covariance.
mKrig( Bigx,Bigy, cov.function="wendland.cov",k=4, theta=theta,
lambda=0)->out2
# the big evaluation this takes about 45 seconds on a Mac G4 latop
predict.surface( out2, nx=400, ny=400)-> look
# the nice surface
surface( look)
US( add=TRUE, col="white")
Run the code above in your browser using DataLab