R gstat krige()-位置[5.88,47.4,0]处的协方差矩阵奇异:正在跳过


10

当我想执行克里金法时,它有时只能工作,这取决于我在数据表中使用的值。作为krige函数的结果,我得到了var1.pred: NA NA NA ...and var1.var: NA NA NA ...(但仅当我在数据表中使用“错误”值时)。

例如:

  • 的工作原理总是(到目前为止)时,我只用10个值
  • 的工作原理,当我用50个值,但只有特定的一些
  • 当我使用50个值和“错误”值时,它不起作用
  • 当我使用25个值和前面提到的“错误”值时,它起作用

我不明白为什么它有时起作用而有时却不起作用。奇怪的是,当我添加Zwiesel;49.02999878;13.22999954;2.2到数据表中时,当我使用少于20个值时,它就起作用了;但是当我使用了50个以上的值时,它就不起作用了。

我的错误在哪里?

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
...
...

我的代码执行克里金插值

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)

警告

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...
...
...

Answers:


16

通常会返回此错误,因为您有重复的位置。您可以使用该sp::zerodist功能进行检查。

要删除重复的位置,请sp::zerodist在方括号索引中调用。

WeatherData <- WeatherData[-zerodist(WeatherData)[,1],] 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.