I am using krige.cv() for cross validation of a data set with 1394 locations. In my code, empirical variogram estimation, model fitting, and kriging (by krige()) everything works fine. But when I use krige.cv() I get the following error.

Error: dimensions do not match: locations 2786 and data 1394

One can notice that 1394 * 2 = 2786. What could I be missing? Please note that there are no NA or NaN or missing values in the data, variogram or kringing results. Everything works fine, and it's just krige.cv() that does not work.

Update: Here is the source code.


data <- read.table("data.txt", header=T)

#variable of interest
var = z
coordinates(data) = ~x + y
data.var <- variogram(var ~ 1, data=data, cutoff=1, width=.05)
model <- fit.variogram(data.var, vgm(0.20, "Sph", nugget=0.06, range=1, fit.method=2))
poly <- chull(coordinates(data))
poly.in <- polygrid(seq(69.0, 74.1, 0.1), seq(31.5, 37.5, 0.1), coordinates(data)[poly,])
coordinates(poly.in) <- ~ x + y
krige.out <- krige(var ~ 1, data, poly.in, model=model)
krige.out.cv= krige.cv(var ~ 1, data, model=model)

  • 2
    Can you provide a minimal reproducible example which will help us to diagnose your problem? – Phil Sep 23 '16 at 9:36
  • Hi Phil, I have added an example code to my question. The data file has 3 columns (z, x, y) and 1394 rows. I have no idea how to attach it to my question. – Asad Ali Sep 24 '16 at 19:00
  • You need to provide some data we can work with. See some of the answers to the question in the link I posted. I would expect you need to use dput(). Also your example should be minimal: strip your code down to the fewest lines needed to recreate your issue. There's a lot extra here. – Phil Sep 26 '16 at 20:55

Your Answer

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

Browse other questions tagged or ask your own question.