在 R 中,克里金法给出 "system is exactly singular" 错误

In R, kriging gives "system is exactly singular" error

我遇到了一个问题,我的特定输入产生了错误。

library(kriging)

x <- c(0.65,0.45,0.25,0.65,0.45,0.25,0.55,0.4,0.25,0.55,0.4,0.25,0.6,0.45,0.25,0.6,0.45,0.25,0.5,0.4,0.25,0.5,0.4,0.25,0.55,0.4,0.25,0.55,0.4,0.25,0.5,0.35,0.25,0.5,0.35,0.25)

y <- c(0.25,0.45,0.65,0.2,0.4,0.6,0.25,0.4,0.55,0.2,0.35,0.5,0.25,0.4,0.6,0.2,0.35,0.55,0.25,0.35,0.5,0.2,0.3,0.45,0.25,0.4,0.55,0.2,0.35,0.5,0.2,0.35,0.45,0.15,0.3,0.4)

r <- c(241.5,236.8333333,229.875,242,235.5,231.3333333,238,236.875,225.75,238.5,233.25,228.5,24,0.5,237.1666667,229.5,241.3333333,236.8333333,227.75,237.625,233.7,228.3333333,236.8,235,229.8333333,238.1,234.6,228.6666667,237.375,235.1,228.6666667,236.4,231.6666667,227.3,236.5,232.625,227.3571429)


x <- data.matrix(x)
x <- sweep(x,1,100,"*")

y <- data.matrix(y)
y <- sweep(y,1,100,"*")

krig <- kriging(x,y,r,lag=3)

Error in solve.default(matrix(A, n + 1, n + 1)) :Lapack routine dgesv: system is exactly singular: U[26,26] = 0

老实说,我不知道出了什么问题。我的格式似乎与我看到的示例代码完全一致。

正如@mrip 提到的,问题是您有重复的观察结果。在此上下文中,点具有完全相同的 xy 坐标。以下代码揭示了重复项:

coor = cbind(x, y)
duplicated(coor)
# [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#[13] FALSE  TRUE  TRUE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE
#[25]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE FALSE
coor[duplicated(coor),]
#     [,1] [,2]
#[1,]   45   40
#[2,]   25   60
#[3,]   25   55
#[4,]   40   35
#[5,]   25   50
#[6,]   55   25
#[7,]   40   40
#[8,]   25   55
#[9,]   55   20
#[10,]   40   35
#[11,]   25   50
#[12,]   50   20
#[13,]   25   45

这导致克里金方程中的不可逆协方差矩阵,进而导致 dgesv 的 Lapack 误差。解决方案是从数据集中删除重复项。

以下数据集有效:

x = runif(100)
y = runif(100)
z = runif(100)
krig = kriging(x, y, z, lag = 3)
image(krig)