rautomap

autoKrige - Error in eval(expr, envir, enclos) : object '....' not found


I have a question about the package Automap.

I have tried the ordinary kriging without problems with my data and worked fine. But when I tried the Universal Kriging a got an error message that I couldn’t understand.

I think it could be simple, but I don’t know why the function did not find the ‘silt_clay.'

Thank you.

Above my code:

library(automap)
data_interpol<-read.table("merge_guaiba_ceco2.txt", header=T)
head(data_interpol)
   long     lat depth silt_clay    avgran pcsand    om
1 471699 6680184   1.9    51.626 0.6683944 48.313 11.50
2 473777 6679430   1.8    57.810 0.6669483 42.186  8.80
3 471931 6679087   2.4    54.625 0.6718675 45.370  9.30
4 471337 6678456   1.9     2.887 0.4128039 97.113  0.00
5 472936 6678421   2.5    49.136 0.6344626 50.864  9.90
6 473945 6678482   1.9    99.614 0.9984355  0.386  9.45

coordinates(data_interpol)<- ~long+lat
kriging_om = autoKrige(om~ 1, data_interpol, grid4)# works fine
kriging_om_Universal= autoKrige(om~ silt_clay + avgran + pcsand, data_interpol, grid4)
Error in eval(expr, envir, enclos) : object 'silt_clay' not found # my error

####code to obtain grid4:
    grid <- raster( )
    grid <- raster(ncol=1544, nrow=1056, xmn=468318.3, xmx=499998.3, ymn=6634918, ymx=6681238) projection (grid) <- '+proj=utm +zone=22 +south +ellps=aust_SA +units=m +no_defs ‘
    res(grid) <- 30
    grid4 <- as(grid, ‘SpatialPoints’)

Editing to discuss the error. After to change the grid the error persists:

The d_margin_xyz is my new grid.

str(d_margin_xyz)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 1628352 obs. of  1 variable:
  .. ..$ DIST_MARGIN: num [1:1628352] 0 0 0 0 0 0 0 0 0 0 ...
  ..@ coords.nrs : int [1:2] 1 2
  ..@ coords     : num [1:1628352, 1:2] 468333 468363 468393 468423 468453 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:2] "x" "y"
  ..@ bbox       : num [1:2, 1:2] 468333 6634963 499983 6681193
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "x" "y"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
  .. .. ..@ projargs: chr NA

Trying again with the new grid containing the predictor to the Universal Kriging, the error appear again. Any clue?

kriging_om_Universal= autoKrige(om~ DIST_MARGIN, data_interpol, d_margin_xyz)
Error in eval(expr, envir, enclos) : object 'DIST_MARGIN' not found

Solution

  • The problem is that your prediction object, grid4, is only a SpatialGrid object with no attributes. To be able to predict using Universal kriging, you need the values of all the predictors (i.e. silt_clay, avgran, etc) on the prediction locations, i.e. as attributes to grid4. Your error is caused by the fact that silt_clay is not an attribute.

    To fix this issue you need to add the attributes to grid4. For this you need to have some kind of area covering map of silt_clay and the other predictors. Than you can either convert this map to a SpatialGrid object with attributes, or extract the values at the locations in grid4 from this map.