[R-sig-Geo] distances reported by gstat when cokriging

Edzer Pebesma edzer.pebesma at uni-muenster.de
Fri Mar 16 16:13:59 CET 2012



On 03/16/2012 03:57 PM, Tom Gottfried wrote:
> Dear Edzer,
> 
> Am 16.03.2012 15:12, schrieb Edzer Pebesma:
>> Tom, right, it is. If you specify nmax=9 for the second variable, you
>> see the dist values for the second as well. They are indeed not computed
>> in your case, as the selection can be copied. Apparently these things
>> mattered when I wrote the code 20 years ago!
> 
> the following modified example gives "dist: 0" for "data id: 0", which
> is non-colocated with the second covariate. As far as I understand the
> selection cannot be copied here:

Distances are only computed when needed. In this case, you use a global
neighbourhood, so they are not needed for neighbourhood selection.

> 
> library(gstat)
> data(meuse)
> coordinates(meuse) <- ~x+y
> data(meuse.grid)
> coordinates(meuse.grid) <- ~x+y
> 
> i <- sample(1:nrow(meuse), 1)
> g <- gstat(NULL, "z", zinc~1, meuse[-i,], model=varmod)
> g <- gstat(g, "dist", I(dist*1000)~1, meuse[-i,])
> variog.g <- variogram(g)
> g <- fit.lmc(variog.g, g, vgm(100000, "Exp", 500, 1000))
> varmod.dist <- g$model$dist
> g <- gstat(g, "dist", I(dist*1000)~1, data=meuse.grid,
>            model=varmod.dist, maxdist=100)
> meuse.point <- meuse[i,]
> predict(g, newdata=meuse.point, debug.level=16)
> 
>> When you say, "Is there a way to get the distances for the second
>> covariate?", do you mean, as R object?
> 
> Well, that would be luxurious. Currently I copy-paste those data into
> Calc for further analysis. Of course I can compute the distances somehow
> outside from gstat, but is there a way to get gstat doing this?

Of course there is (modifying the c code) but my advice would be to take
a shorter path -- sp::spDists? rgeos::gDistance?

> 
> Thanks!
> Tom
> 
>>
>> On 03/16/2012 02:53 PM, Tom Gottfried wrote:
>>> Dear list(en)ers,
>>>
>>> I wonder what the "dist" is, which is in the output of predict.gstat()
>>> with debug.level=16. I expect it to be the distance between the
>>> coordinate pair given in the same line and the prediction location. I
>>> verified this for the coordinates and distances given for "data id: 0"
>>> in the below example (and its true), but for "data id: 1" it's always
>>> "dist: 0". Is there a way to get the distances for the second covariate?
>>> I see it's simple in the example, because data are colocated, but the
>>> problem arose in a case with non-colocated covariates.
>>> Here's the example:
>>>
>>> library(gstat)
>>> data(meuse)
>>> coordinates(meuse)<- ~x+y
>>> variog<- variogram(zinc~1, meuse)
>>> varmod<- fit.variogram(variog, vgm(150000, "Exp", 1000))
>>> data(meuse.grid)
>>> coordinates(meuse.grid)<- ~x+y
>>> g<- gstat(NULL, "z", zinc~1, meuse, model=varmod, nmax=10)
>>> g<- gstat(g, "dist", I(dist*1000)~1, meuse, nmax=10)
>>> variog.g<- variogram(g)
>>> g<- fit.lmc(variog.g, g, vgm(100000, "Exp", 500, 1000))
>>> meuse.point<- meuse.grid[sample(1:nrow(meuse.grid), 1),]
>>> predict(g, newdata=meuse.point, debug.level=16)
>>>
>>> Thanks!
>>> Tom
>>>
>>
> 

-- 
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