我正在尝试使用普通克里金法使用 R 中的 gstat 或 automap 包根据预测变量在空间上预测动物将出现的数据。我有许多(超过 100 个)重复的坐标点,因为这些站点是采样的,所以我无法丢弃它们多年来多次。每次我为普通克里金运行下面的代码时,我都会收到一个 LDL 错误,这是由于重复点造成的。有谁知道如何在不丢弃数据的情况下解决这个问题?我已经尝试了 automap 包中应该纠正重复项的代码,但我无法让它工作。感谢您的帮助!
coordinates(fish) <- ~ LONGITUDE+LATITUDE
x.range <- range(fish@coords[,1])
y.range <- range(fish@coords[,2])
grd <- expand.grid(x=seq(from=x.range[1], to=x.range[2], by=3), y=seq(from=y.range[1], to=y.range[2], by=3))
coordinates(grd) <- ~ x+y
plot(grd, pch=16, cex=.5)
gridded(grd) <- TRUE
library(gstat)
zerodist(fish) ###146 duplicate points
v <- variogram(log(WATER_TEMP) ~1, fish, na.rm=TRUE)
plot(v)
vgm()
f <- vgm(1, "Sph", 300, 0.5)
print(f)
v.fit <- fit.variogram(v,f)
plot(v, model=v.fit) ####In fit.variogram(v, d) : Warning: singular model in variogram fit
krg <- krige(log(WATER_TEMP) ~ 1, fish, grd, v.fit)
## [using ordinary kriging]
##"chfactor.c", line 131: singular matrix in function LDLfactor()Error in predict.gstat(g, newdata = newdata, block = block, nsim = nsim,: LDLfactor
##automap code for correcting for duplicates
fish.dup = rbind(fish, fish[1,]) # Create duplicate
coordinates(fish.dup) = ~LONGITUDE + LATITUDE
kr = autoKrige(WATER_TEMP, fish.dup, grd)
###Error in inherits(formula, "SpatialPointsDataFrame"):object 'WATER_TEMP' not found
###somehow my predictor variables are no longer available when in a Spatial Points Data Frame??