在R中,kriging给出了"系统是完全单一的"错误

时间:2015-03-16 19:19:29

标签: r kriging

我遇到的问题是我的特定输入会产生错误。

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
老实说,我不知道出了什么问题。我的格式似乎与我见过的示例代码完全一致。

1 个答案:

答案 0 :(得分:6)

问题是,正如@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

这导致kriging方程中的不可逆协方差矩阵,这反过来导致来自dgesv的Lapack误差。解决方案是从数据集中删除重复项。

以下数据集有效:

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

enter image description here