空间距离矩阵对角线上的条目应该为零,因为它们表示每个位置与其自身之间的距离。但是rdist.earth()
函数fields
R package
有时会在对角线上给我非零:
> # 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
。首先,为什么第二列的条目显示的数字比其他两个多?为什么第二条对角线上的条目不像其他条目那样从零到八位小数?差异似乎不足以归因于浮点舍入误差。
现在将 的输出与rdist.earth()
不同包的输出geosphere
和函数的输出进行比较distGeo()
,后者计算两点之间的距离(不是全距离矩阵)。在这里,我们计算每个点与其自身之间的距离。输出向量单位以米为单位:
> library(geosphere)
> distmat2 <- distGeo(LLdat,LLdat)
> distmat2
[1] 0 0 0
因此distGeo()
,所有三个距离度量都一致并且适当地为零。
有什么我想念的吗?或者这是否表明存在问题rdist.earth()
?