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 copper measurements:

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.

  • If you believe this to be a new bug you could try and download an older version of R. – Albert Sep 10 '18 at 6:34
  • I should give it a try, indeed. – Yo B. Sep 11 '18 at 7:58
  • 1
    Same error observed in Rossitier (2012)'s example (see here). It was working before. – Andre Silva Sep 16 '18 at 17:18
  • Indeed, I had missed that, thanks. I did open an issue on gstat github, maybe something can be done! – Yo B. Sep 17 '18 at 7:19

Found it. There is no bug. Just use the subset also in the second line and It sould work.

g <- gstat(NULL, data=meuse[1:80,], formula=lead ~ 1) # subset
g <- gstat(g, data=meuse[1:80,], formula=copper ~ 1)

Have a good day.

  • 1
    There is nearly no interest in doing this. We need the full set of the auxiliary variable: it helps predicting lead where copper is present alone (index 81 to 155). This is informed by the correlation of lead and copper where they are collocated (index 1 to 80). But thanks for trying! – Yo B. Sep 13 '18 at 9:38
  • I'm sorry, but you said that an error occured at subseting and it is because of that mistake in code. This answer solves it. Other thing is that you need that subset or not. – César Arquero Dec 22 '18 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.