Trying to cokrige two variables that are not perfectly colocated (one has sparser measurements than the other), I faced an issue that I'll illustrate with the following MRE.
With the meuse dataset, consider we krige
lead as principal variable assisted by
copper measurements as auxiliary variable. We subset the
lead, to simulate sparser measurements and hence, a need for cokriging with the denser
library("gstat") library("sp") data("meuse") coordinates(meuse) = ~x+y g <- gstat(NULL, data=meuse[1:80,], formula=lead ~ 1) # subset g <- gstat(g, data=meuse, formula=copper ~ 1) v <- variogram(g) plot(v) # zero distance semivariance dot in panel var1.var2 g <- fit.lmc(v=v, g, vgm("Sph")) # error
Error in fit.variogram(x, m, fit.ranges = fit.ranges, ...) : fit.method 7 will not work with zero distance semivariances; use another fit.method value
You can see in the bottom-left panel of the plot a zero distance dot, which subsequently causes
fit.lmc() to fail.
Now, if no subset is done (somewhat limiting the interest of cokriging, no?), everything works fine. This because, the zero distance dot in the cross-semivariogram does not appear in this case:
g <- gstat(NULL, data=meuse, formula=lead ~ 1) g <- gstat(g, data=meuse, formula=copper ~ 1) v <- variogram(g) plot(v) # no zero dist dot on var1.var2 panel g <- fit.lmc(v=v, g, vgm("Sph")) # fit fine with default fit.method
There is no reason for this dot to appear only in the subsetted cases, right?
Another example of this can be seen in this 2009 exercise document by Edzer Pebesma. In section 8.13, he refers to this as the "undersampled case". But the provided code is not working any more, likely for the reason mentioned above.
Is there is a simple way around this (hopefully) temporary bug?
PS: I moved this from Cross-validated because it is software-related.