Hi Maurizio,

Thank you for the very clear example. I think this fixes it:

names(r) = 'elev'
UK<-interpolate(r, gUK, xyOnly=FALSE)

as in:
##UNIVERSAL KRIGING (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)
names(r) = 'elev'
UK<-interpolate(r,gUK, xyOnly=FALSE)


## Comparing the results with "straight gstat":
names(r) <- 'elev'
sp <- as(r, 'SpatialGridDataFrame')
p <- predict(gUK, sp)
plot(raster(p), UK)

# looks OK

Best, Robert


On Mon, Oct 22, 2012 at 11:18 PM, Edzer Pebesma <
edzer.pebesma@uni-muenster.de> wrote:

> 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@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@wwu.de
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

