空间距离矩阵的对角线条目应为零,因为它们表示每个位置与自身之间的距离。但是,来自fields
R包
的rdist.earth()
函数有时会在对角线上给出非零值:
> # Set number of decimals of output display
> options(digits=8)
> # Some longitude, latitude data
> LLdat
lon lat
1 -105.85878 43.65797
2 -105.81812 43.57009
3 -105.80796 43.57748
>
> # Create distance matrix
> library(fields)
> distmat <- rdist.earth(LLdat,LLdat)
> distmat
1 2 3
1 0.0000000 6.410948951394 6.12184338
2 6.4109490 0.000059058368 0.72150586
3 6.1218434 0.721505863563 0.00000000
在上面的距离矩阵中,对角线上的第二个条目为
0.000059058368
(默认单位为英里),而另外两个条目为0.0000000
。首先,为什么第二列的条目显示了更多的数字?其次,为什么第二条对角线上的条目不像其他条目一样有8位小数为零?这种差异似乎不足以归因于浮点舍入误差。现在将
rdist.earth()
的输出与另一个包geosphere
和函数distGeo()
的输出进行比较,后者计算两点之间的距离(不是完整的距离矩阵)。在这里,我们计算每个点与其自身之间的距离。输出向量单位为米:> library(geosphere)
> distmat2 <- distGeo(LLdat,LLdat)
> distmat2
[1] 0 0 0
使用distGeo()
方法计算的所有三种距离度量均相符且为零。
我是否遗漏了什么?还是这表明rdist.earth()
存在问题?