#
# Presenting the Matern family:
# the function matern is called by matern.cov
d<- seq( 0,5,,200)
sm<- seq( .5, 8,,5)
temp<- matrix( NA, 200, 5)
for ( k in 1:5){
temp[,k] <- matern(d, smoothness=sm[k])
}
matplot( d, temp, type="l", lty=1)
# note differing correlation scales depending on smoothness
# Matern covariance matrix ( marginal variance =1) for the ozone
# locations
out<- matern.cov( ozone$x, theta=100, smoothness=1.0)
# out is a 20X20 matrix
out2<- matern.cov( ozone$x[6:20,],ozone$x[1:2,], theta=100,
smoothness=1.0)
# out2 is 15X2 cross covariance matrix
# Kriging fit using a Matern covariance and where the nugget and
# sill variances are found by GCV
fit<- Krig( ozone$x, ozone$y, matern.cov, theta=100, smoothness=1.0)
######## examples with matern.earth.cov
# create a 1 degree patch of lon/lats at the equator:
x<- seq( -1,1,,25)
y<- x
make.surface.grid( list( x=x, y=y))-> xg
# find covariance with the (lon,lat) =(0,0)
# theta = 30 , a degree at the equator is about 69.17333 miles.
matern.earth.cov( xg,rbind( c(0,0)), theta = 30 )-> look
# covariance surface
image.plot( x,y,matrix(look, 25,25))
# compare to matern.cov( xg,rbind( c(0,0)), theta = 30/69.17333)
# now change the grid to be close to the north pole
# create a 1 degree patch of lon/lats at (0, 80N) :
x<- seq( -1,1,,25)
y<- x + 80
make.surface.grid( list( x=x, y=y))-> xg
# evaluate the same covariance function at this point
matern.earth.cov( xg,rbind( c(0,80)), theta = 30 )-> look
# plot covariance surface
# stretching is an artifact of this Mercator projection
image.plot( x,y,matrix(look, 25,25))
# a Kriging example with the ozone data
data(ozone2)
Krig( ozone2$lon.lat, ozone2$y[16,], cov.function= matern.earth.cov,
theta=300, na.rm=TRUE)-> look
surface( look, type="C")
US( add=TRUE, lwd=2)
Run the code above in your browser using DataLab