[R-sig-Geo] Universal Kriging and raster library

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Oct 23 08:18:47 CEST 2012


In your example, I see:

> UK<-interpolate(r,gUK)
Error in eval(expr, envir, enclos) : object 'elev' not found

it seems that 'elev' is not present in r.

On 10/23/2012 08:11 AM, Maurizio Marchi wrote:
> Oh, ok, I'm sorry, I had not understand the "self-contained" expression.
> Anyway, a self-contained exaple can be this:
> 
> ############################## BEGINNING
> library(gstat)
> library(rgdal)
> library(raster)
> 
> data(meuse)
> coordinates(meuse) = ~x+y
> r <- raster(system.file("external/test.grd", package="raster"))
> projection(r)<-projection(meuse)
> 
> ##ORDINARY KRIGING (working)
> v<-variogram(log(zinc)~1,meuse)
> m<-fit.variogram(v,vgm(1,"Sph",300,1))
> gOK<-gstat(NULL,"log.zinc",log(zinc)~1,meuse,model=m)
> OK<-interpolate(r,gOK)
> 
> ##UNIVERSAL KRIGING (not working!!)
> vu<-variogram(log(zinc)~elev,meuse)
> mu<-fit.variogram(vu,vgm(1,"Sph",300,1))
> gUK<-gstat(NULL,"log.zinc",log(zinc)~elev,meuse,model=mu)
> UK<-interpolate(r,gUK)
> 
> ###CO-KRIGING (working)
> gCoK<-gstat(NULL,'log.zinc',log(zinc)~1,meuse)
> gCoK<-gstat(gCoK,'elev',elev~1,meuse)
> gCoK<-gstat(gCoK,'cadmium',cadmium~1,meuse)
> gCoK<-gstat(gCoK,'copper',copper~1,meuse)
> gCoK
> coV<-variogram(gCoK)
> plot(coV,type='b',main='Co-variogram')
> coV.fit<-fit.lmc(coV,gCoK,vgm(model='Sph',range=1000))
> coV.fit
> plot(coV,coV.fit,main='Fitted Co-variogram')
> coK<-interpolate(r,coV.fit)
> ############################################ END
> 
> I hope it can be ok :)
> Thanks a lot (again)
> 
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list