匹配积分并计算总分distance/accuracy

Matching points and calculate total distance/accuracy

我有一个包含 309 个数据帧的列表 list.response。在每个数据框中有 10 行和两列。列是 X 和 Y 坐标,代表“点击次数”,调查受访者在图片上进行的点击次数。

此外,我还有另一个具有 10 个 XY 坐标的数据框 df.true。这些坐标表示受访者在调查中试图点击的对象的坐标。

目标:对于每个受访者(即 list.response 中的每个数据框),我想计算他们在尝试点击对象时的准确度。也就是说:他们10次点击的坐标和df.true.

中的10个物体的坐标之间的距离是多少?

我的问题是他们点击的坐标和物体的坐标顺序不一样。例如,受访者 A 可能从左-右点击了对象,而受访者 B 可能从右-左点击了对象,这搞乱了点击和对象的顺序。因此,我需要将受访者的点击与最近的对象进行匹配。匹配条件为:

最后,我想计算所有匹配点之间的总距离(即汇总所有匹配点之间的距离)。这将是我对受访者点击对象的总体准确度的衡量。


我已经研究了一些类似问题的解决方案(请参阅 and https://gis.stackexchange.com/questions/297153/excluding-point-from-nearest-neighbor-search-once-its-been-matched-using-r),但是我无法在我的案例中使用它。免责声明:我是 R / 编程的新手

我希望有人能帮助我吗?


可重现示例的数据:

具有点击次数的列表中的 20 个 df 示例:

list.response <- list(structure(list(X = c(536, 160, 467, 552, 476, 242, 355, 
414, 556, 0), Y = c(91, 181, 128, 84, 52, 379, 434, 528, 551, 
0)), row.names = c(NA, -10L), class = "data.frame"), structure(list(
    X = c(536, 542, 455, 148, 70, 239, 369, 416, 553, 0), Y = c(91, 
    94, 110, 185, 98, 387, 427, 509, 554, 0)), row.names = c(NA, 
-10L), class = "data.frame"), structure(list(X = c(536, 160, 
232, 374, 425, 561, 461, 544, 473, 0), Y = c(91, 193, 380, 426, 
513, 559, 105, 97, 37, 0)), row.names = c(NA, -10L), class = "data.frame"), 
    structure(list(X = c(536, 156, 240, 375, 455, 476, 549, 414, 
    547, 0), Y = c(91, 194, 389, 425, 116, 37, 87, 494, 553, 
    0)), row.names = c(NA, -10L), class = "data.frame"), structure(list(
        X = c(536, 70, 455, 543, 482, 241, 368, 418, 551, 0), 
        Y = c(91, 99, 107, 93, 47, 385, 427, 511, 552, 0)), row.names = c(NA, 
    -10L), class = "data.frame"), structure(list(X = c(536, 480, 
    458, 81, 158, 231, 393, 409, 558, 0), Y = c(91, 35, 91, 114, 
    175, 385, 423, 508, 562, 0)), row.names = c(NA, -10L), class = "data.frame"), 
    structure(list(X = c(536, 67, 492, 460, 542, 240, 364, 407, 
    554, 0), Y = c(91, 98, 48, 108, 98, 391, 428, 507, 553, 0
    )), row.names = c(NA, -10L), class = "data.frame"), structure(list(
        X = c(536, 156, 240, 371, 409, 563, 449, 480, 547, 0), 
        Y = c(91, 194, 387, 414, 510, 549, 110, 44, 96, 0)), row.names = c(NA, 
    -10L), class = "data.frame"), structure(list(X = c(536, 485, 
    462, 419, 556, 371, 240, 156, 71, 0), Y = c(91, 50, 110, 
    499, 556, 423, 380, 183, 96, 0)), row.names = c(NA, -10L), class = "data.frame"), 
    structure(list(X = c(536, 423, 362, 76, 156, 243, 551, 480, 
    455, 0), Y = c(91, 505, 434, 103, 187, 386, 547, 50, 114, 
    0)), row.names = c(NA, -10L), class = "data.frame"), structure(list(
        X = c(536, 155, 245, 359, 414, 552, 456, 535, 483, 0), 
        Y = c(91, 185, 391, 423, 508, 544, 119, 92, 48, 0)), row.names = c(NA, 
    -10L), class = "data.frame"), structure(list(X = c(536, 419, 
    366, 242, 155, 76, 451, 538, 480, 0), Y = c(91, 510, 425, 
    393, 190, 103, 107, 96, 53, 0)), row.names = c(NA, -10L), class = "data.frame"), 
    structure(list(X = c(536, 412, 369, 243, 153, 76, 458, 481, 
    543, 0), Y = c(91, 512, 425, 386, 187, 100, 114, 48, 96, 
    0)), row.names = c(NA, -10L), class = "data.frame"), structure(list(
        X = c(536, 483, 457, 151, 73, 241, 368, 416, 552, 0), 
        Y = c(91, 45, 108, 186, 99, 386, 426, 507, 556, 0)), row.names = c(NA, 
    -10L), class = "data.frame"), structure(list(X = c(536, 151, 
    483, 455, 544, 239, 368, 418, 547, 0), Y = c(91, 182, 43, 
    104, 96, 388, 426, 508, 554, 0)), row.names = c(NA, -10L), class = "data.frame"), 
    structure(list(X = c(536, 418, 368, 238, 154, 73, 454, 482, 
    543, 0), Y = c(91, 510, 430, 387, 184, 100, 110, 48, 93, 
    0)), row.names = c(NA, -10L), class = "data.frame"), structure(list(
        X = c(536, 481, 455, 149, 70, 240, 369, 417, 555, 0), 
        Y = c(91, 46, 109, 184, 99, 386, 427, 509, 555, 0)), row.names = c(NA, 
    -10L), class = "data.frame"), structure(list(X = c(536, 456, 
    541, 148, 71, 244, 370, 418, 555, 0), Y = c(91, 110, 96, 
    186, 88, 389, 427, 511, 553, 0)), row.names = c(NA, -10L), class = "data.frame"), 
    structure(list(X = c(536, 454, 240, 151, 71, 541, 366, 416, 
    551, 0), Y = c(91, 108, 389, 183, 99, 92, 428, 510, 552, 
    0)), row.names = c(NA, -10L), class = "data.frame"), structure(list(
        X = c(536, 147, 476, 499, 553, 244, 385, 417, 557, 0), 
        Y = c(91, 185, 110, 38, 87, 397, 433, 506, 552, 0)), row.names = c(NA, 
    -10L), class = "data.frame"))

而df.true坐标:

df.true <- structure(list(X = c(71, 151, 240, 370, 415, 552, 542, 456, 482, 
0), Y = c(99, 186, 387, 429, 509, 553, 91, 108, 45, 0)), row.names = c(NA, 
-10L), class = "data.frame") 

我想出了一个解决办法。首先,我将所有数据帧转换为矩阵。然后我使用了这里的函数:https://gis.stackexchange.com/questions/297153/excluding-point-from-nearest-neighbor-search-once-its-been-matched-using-r:

pairup <- function(list1, list2){
  keep = 1:nrow(list2)
  used = c()
  for(i in 1:nrow(list1)){
    nearest = FNN::get.knnx(list2, list1[i,,drop=FALSE], 1)$nn.index[1,1]        
    used = c(used, keep[nearest])
    keep = keep[-nearest]
    list2 = list2[-nearest,,drop=FALSE]
  }
  used
}

然后我 运行 for 循环:

#Define an empty vector 
pm <- c()

#Run loop and calculate distance
for (i in 1:length(list.response)) {
  match <- pairup(list.response[[i]],df.true)
  pm[i]<-sum(pointDistance(list.response[[i]], df.true[match,], lonlat=FALSE))
}