data( ozone2)
x<- ozone2$lon.lat
y<- ozone2$y[16,]
obj<- Tps( x,y)
# or try the alternative model:
# obj<- spatialProcess(x,y)
fit<- predictSurface( obj, nx=40, ny=40)
imagePlot( fit)
# predicting a 2d surface holding other variables fixed.
fit<- Tps( BD[,1:4], BD$lnya) # fit surface to data
# evaluate fitted surface for first two
# variables holding other two fixed at median values
out.p<- predictSurface(fit)
surface(out.p, type="C")
#
# plot surface for second and fourth variables
# on specific grid.
glist<- list( KCL=29.77, MgCl2= seq(3,7,,25), KPO4=32.13,
dNTP=seq( 250,1500,,25))
out.p<- predictSurface(fit, glist)
surface(out.p, type="C")
out.p<- predictSurfaceSE(fit, glist)
surface(out.p, type="C")
## a test of the fast prediction algorithm for use with
# mKrig/spatialProcess objects.
if (FALSE) {
data(NorthAmericanRainfall)
x<- cbind(NorthAmericanRainfall$longitude,
NorthAmericanRainfall$latitude)
y<- log10(NorthAmericanRainfall$precip)
mKrigObject<- mKrig( x,log10(y),
lambda=.024,
cov.args= list( aRange= 5.87,
Covariance="Matern",
smoothness=1.0),
sigma2=.157
)
gridList<- list( x = seq(-134, -51, length.out = 100),
y = seq( 23, 57, length.out = 100))
# exact prediction
system.time(
gHat<- predictSurface( mKrigObject, gridList)
)
# aproximate
system.time(
gHat1<- predictSurface( mKrigObject, gridList,
fast = TRUE)
)
# don't worry about the warning ...
# just indicates some observation locations are located
# in the same grid box.
# approximation error omitting the NAs from outside the convex hull
stats( log10(abs(c(gHat$z - gHat1$z))) )
image.plot(gHat$x, gHat$y, (gHat$z - gHat1$z) )
points( x, pch=".", cex=.5)
world( add=TRUE )
}
Run the code above in your browser using DataLab