#
# fit a monthly precipitation field over the Rocky Mountains
# grid is 64X64
out<- krig.image( x= RMprecip$x, Y = RMprecip$y, m=64,n=64,cov.function=
Exp.image.cov,
lambda=.5, theta=1, kmax=100)
#
# range parameter for exponential here is .5 degree in lon and lat.
#diagnostic plots.
plot( out)
# look at the surface
image.plot( out$surface) #or just surface( out)
#
#simulate 4 realizations from the conditional distribution
look<- sim.krig.image( out, nreps=4)
# take a look: plot( look)
# check out another values of lambda reusing some of the objects from the
# first fit
out2<- krig.image( RMprecip$x, RMprecip$y, cov.function= Exp.image.cov,
lambda=4,
start= out$omega2,cov.obj=out$cov.obj)
#
# some of the obsare lumped together into a singel grid box
#
# find residuals among grid box means and predictions
res<- predict( out2, out2$xM) - out2$yM
#compare with sizes of out2$residuals (raw y data)
#starting values from first fit in out$omega2
# covariance and grid information are
# bundled in the cov.obj
##
#
## fitting a thin plate spline. The default here is a linear null space
## and second derivative type penalty term.
## you will just have to try different values of lambda vary them on
## log scale to
out<- krig.image( RMprecip$x, RMprecip$y, cov.function=Rad.image.cov,
lambda=1, m=64, n=64, p=2, kmax=300)
# take a look: image.plot( out$surface)
# check out different values reuse some of the things to make it quicker
# note addition of kmax argument to increase teh number of iterations
out2<- krig.image( RMprecip$x, RMprecip$y,cov.function=Rad.image.cov,
lambda=.5, start= out$omega2, cov.obj=out$cov.obj, kmax=400)
# here is something rougher
out3<- krig.image( RMprecip$x, RMprecip$y,cov.function=Rad.image.cov,
lambda=1e-2, start= out2$omega2, cov.obj=out$cov.obj,kmax=400,
tol=1e-3)
# here is something close to an interpolation
out4<- krig.image( RMprecip$x, RMprecip$y,cov.function=Rad.image.cov,
lambda=1e-7, start= out3$omega2, cov.obj=out$cov.obj,kmax=500, tol=1e-3)
#compare the the four surfaces:
# but note the differences in scales ( fix zlim to make them the same)
#
# take a look
# set.panel( 2,2)
# image.plot( out$surface)
# points( out$x, pch=".")
# image.plot( out2$surface)
# image.plot( out3$surface)
# image.plot( out4$surface)
# some diagnostic plots)
set.panel( 4,4)
plot( out, graphics.reset=FALSE)
plot( out2, graphics.reset=FALSE)
plot( out3, graphics.reset=FALSE)
plot( out4, graphics.reset=FALSE)
set.panel(1,1)
Run the code above in your browser using DataLab