Search code examples
rkriging

autoKrige gives different results if data frame columns removed


I may be doing something wrong here, but I find that if I simplify my data frame by removing irrelevant columns the autoKrige function in the automap library gives different results. I have reproduced this problem with the meuse data in the automap library.

library(automap)
data(meuse)
colnames(meuse)
 [1] "x"       "y"       "cadmium" "copper"  "lead"    "zinc"    "elev"   
 [8] "dist"    "om"      "ffreq"   "soil"    "lime"    "landuse" "dist.m" 

coordinates(meuse) =~ x+y
data(meuse.grid)
gridded(meuse.grid) =~ x+y
kriging_result_01 = autoKrige(zinc~1, meuse)
plot(kriging_result_01)

meuse <- NULL
data(meuse)
meuse <- meuse[, c(1,2,6)]

coordinates(meuse) =~ x+y
data(meuse.grid)
gridded(meuse.grid) =~ x+y
kriging_result_02 = autoKrige(zinc~1, meuse)
plot(kriging_result_02)

identical(kriging_result_01, kriging_result_02)
[1] FALSE

The plots are also different in their detail.

Is this the expected behaviour?

Thanks, Bill


Solution

  • The problem is not the removed columns, but the grid to apply the fitted model on. Using your example, you can see:

    library(automap)
    set.seed(42)
    
    data(meuse)
    coordinates(meuse) =~ x+y
    data(meuse.grid)
    gridded(meuse.grid) =~ x+y
    kriging_result_01 = autoKrige(zinc~1, meuse)
    
    meuse <- NULL
    data(meuse)
    meuse <- meuse[, c(1,2,6)]
    coordinates(meuse) =~ x+y
    
    kriging_result_02 = autoKrige(zinc~1, meuse)
    
    
    kriging_result_01$krige_output@grid
                                x1           x2
    cellcentre.offset 178635.12844 329744.86186
    cellsize              32.93423     32.93423
    cells.dim             84.00000    118.00000
    

    and

    kriging_result_02$krige_output@grid
                                x1           x2
    cellcentre.offset 178614.42379 329741.35016
    cellsize              32.93423     32.93423
    cells.dim             85.00000    118.00000
    

    As you can see, the grids are slightly different, with 4999 and 4996 grid points respectively.

    If you use

    kriging_result_01 = autoKrige(zinc~1, meuse, meuse.grid)
    kriging_result_02 = autoKrige(zinc~1, meuse, meuse.grid)
    
    kriging_result_01$krige_output@grid
                           x      y
    cellcentre.offset 178460 329620
    cellsize              40     40
    cells.dim             78    104
    
    kriging_result_02$krige_output@grid
                           x      y
    cellcentre.offset 178460 329620
    cellsize              40     40
    cells.dim             78    104
    

    The grids are similar.