[R] Error with sf ordinary kriging after creating grid

Nicola Gambaro n|co|@ @end|ng |rom g@mb@ro@co@uk
Thu Aug 13 11:03:16 CEST 2020


I want to perform ordinary kriging of temperature (UTCI) data in Nigeria with sf and gstat packages. However, after fitting the variogram model and creating a grid for the region, the krige function returns this error:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘krige’ for signature ‘"formula", "sfc_POINT"’
What am I doing wrong? Here is my code:

library(gstat)
library(sf)  
sf_data <- st_as_sf(x = data, coords = c("longitude", "latitude"), crs = 4326)

#VARIOGRAM  
vgm_utci <- variogram(UTCI~1, sf_data)
utci_fit <- fit.variogram(vgm_utci, vgm("Mat"), fit.kappa = TRUE)
   
#CREATE GRID
nigeria <- read_sf("./Igismap/Nigeria_Boundary.shp")
nigeria <- nigeria$geometry
nigeria.grid <- nigeria %>% 
              st_make_grid(cellsize = 0.1, what = "centers") %>%
              st_intersection(nigeria)
            
#UTCI ORDINARY KRIGING
utci_krig <- krige(formula = sf_data$UTCI ~ 1, nigeria.grid, model = utci_fit)
When plotted, the grid and the variogram model look fine. I have attached data and shapefile. Thank you so much in advance,

Nicola


More information about the R-help mailing list