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 の座標を元のデータとまったく同じにしようとしましたが、それでもこのエラーが発生します。私は地球統計学の手法に慣れていないので、基本的な間違いを犯していたら申し訳ありません。誰が私が間違っているのかアドバイスできますか? ありがとう。