我想在自動映射包中使用autoKrige()函數進行通用克里金簡單應用。我有一個不規則間距的測量網格,我想在精細的空間尺度上插入它們之間。示例代碼:R通用克里金與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的座標與原始數據完全相同,但仍然出現此錯誤。如果我犯了一個基本錯誤,我對地質統計學技術很陌生,所以很抱歉。任何人都可以告訴我哪裏出錯了?謝謝。
的'預解碼<-cbind(PRED [,1],預解碼[,2])'一步可以省略對我來說,'autoKrige'工作,即使沒有它。 –