我正在尝试使用 automap 包中的 autoKrige() 函数来简单地应用通用克里金法。我有一个不规则间隔的测量网格,我想在它们之间以精细的空间尺度进行插值。示例代码:
library('automap')
# create an irregularly spaced grid
y <-x <-c(-5,-4,-2,-1,-0.5,0,0.5,1,2,4,5)
grid <-expand.grid(x,y)
names(grid) <-c('x', 'y')
# create some measurements, greatest in the centre, with some noise
vals <-apply(grid,1, function(x) {12/(0.1+sqrt(x[1]^2 + x[2]^2))+rnorm(1,2,1.5)})
# get data into sp format
s <-SpatialPointsDataFrame(grid, data.frame(vals))
# make some prediction locations and get them into sp format
pred <-expand.grid(seq(-5,5,by=0.5), seq(-5,5,by=0.5))
pred <-cbind(pred[,1], pred[,2]) # this seems to be needed, not sure why
pred <-SpatialPoints(pred)
# try universal kriging
surf <-autoKrige(vals~x+y, s, new_data=pred)
这会导致错误:
Error in gstat.formula.predict(d$formula, newdata, na.action = na.action, :
NROW(locs) != NROW(X): this should not occur
我尝试让 new_data 与原始数据具有相同的行数,甚至尝试使 new_data 中的坐标与原始数据完全相同,但我仍然收到此错误。我是地质统计学技术的新手,如果我犯了一个基本错误,我深表歉意。谁能告诉我哪里出错了?谢谢。