11

When I want to perform the kriging it only works sometimes, depending on what values I use in my datatable. As a result of the krige function I get for var1.pred: NA NA NA ... and var1.var: NA NA NA ... (but only when I use the "wrong" values in my datatable.)

For example:

  • it works always (so far) when I only use 10 values
  • it works when I use 50 values, but only with certain ones
  • it works not when I use 50 values and the "wrong" values
  • it works when I use 25 values and the before mentioned "wrong" values

I don't get it why it's sometimes working and sometimes not. The strange thing is that when I add Zwiesel;49.02999878;13.22999954;2.2 to the datatable it works when I use less then ~20 values, but it doesn't work when I use more then 50 values ...

Where is my mistake?

myWeatherTable.csv:

Place;Latitude;Longitude;Temperature
Aachen;50.77999878;6.09999990;3
Abbikenhausen;53.52999878;8.00000000;7.9
Adelbach;49.04000092;9.76000023;3.1
Adendorf;51.61999893;11.69999981;1.9
Alberzell;48.45999908;11.34000015;4.6
...
...

My code to perform kriging interpolation

WeatherData <- read.csv(file="myWeatherTable", header = TRUE, sep ";")

coordinates(WeatherData) = ~Longitude + Latitude

vario <-  variogram(log(Temperature) ~1, WeatherData)
vario.fit <- fit.variogram(vario, vgm("Sph"))

min_lon <- min(WeatherData$Longitude)
max_lon <- max(WeatherData$Longitude)
min_lat <- min(WeatherData$Latitude)
max_lat <- max(WeatherData$Latitude)
Longitude.range <- as.numeric(c(min_lon,max_lon))
Latitude.range <- as.numeric(c(min_lat,max_lat))
grd <- expand.grid(Longitude = seq(from = Longitude.range[1], to = Longitude.range[2], by = 0.1),
  Latitude = seq(from = Latitude.range[1],to = Latitude.range[2], by = 0.1))
coordinates(grd) <- ~Longitude + Latitude
gridded(grd) <- TRUE

plot1 <- WU_data_spatial %>% as.data.frame %>%
  ggplot(aes(Longitude, Latitude)) + geom_point(size=1) + coord_equal() + 
  ggtitle("Points with measurements")

plot2 <- grd %>% as.data.frame %>%
  ggplot(aes(Longitude, Latitude)) + geom_point(size=1) + coord_equal() + 
  ggtitle("Points at which to estimate")

grid.arrange(plot1, plot2, ncol = 2)

kriged <- krige(Temperature~ 1, WeatherData, grd, model=variogram_fit)

Warnings:

1: In predict.gstat(g, newdata = newdata, block = block,  ... :
Covariance matrix singular at location [5.88,47.4,0]: skipping...
2: In predict.gstat(g, newdata = newdata, block = block,  ... :
Covariance matrix singular at location [5.98,47.4,0]: skipping...
3: In predict.gstat(g, newdata = newdata, block = block,  ... :
Covariance matrix singular at location [6.08,47.4,0]: skipping...
4: In predict.gstat(g, newdata = newdata, block = block,  ... :
Covariance matrix singular at location [6.18,47.4,0]: skipping...
...
...

2 Answers 2

17

This error is commonly returned because you have duplicate locations. You can check this using the sp::zerodist function.

To remove duplicate locations you call sp::zerodist within a bracket index.

WeatherData <- WeatherData[-zerodist(WeatherData)[,1],] 
0

because your sampling point(eg.soil point)have duplicate locations. try to delete the same location points

1
  • 1
    How does this improve upon the accepted Answer?
    – Vince
    Commented Jul 15, 2023 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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