0

I was wondering if you could help me with this problem. I have a dataset of US counties that I am trying to do k-nearest neighbor analysis for spatial weighting, following the method proposed here, but the results aren't making sense, or potentially I'm not understanding them.

library(spdep)
library(tigris)
library(sf)

counties <- counties("Georgia", cb = TRUE)
coords <- st_centroid(st_geometry(counties), of_largest_polygon=TRUE)
col.knn <- knearneigh(coords)
gck4.nb <- knn2nb(knearneigh(coords, k=4, longlat=TRUE))
summary(gck4.nb, coords, longlat=TRUE, scale=0.5)

However, the output I'm getting, with regards to the distances, seems rather small, on the order of less than 1 km:

Neighbour list object:
Number of regions: 159 
Number of nonzero links: 636 
Percentage nonzero weights: 2.515723 
Average number of links: 4 
Non-symmetric neighbours list
Link number distribution:

  4 
159 
159 least connected regions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 with 4 links
159 most connected regions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 with 4 links
Summary of link distances:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.1355  0.2650  0.3085  0.3112  0.3482  0.6224 

  The decimal point is 1 digit(s) to the left of the |

  1 | 44
  1 | 7799999999999999
  2 | 00000000000011111111112222222222222233333333333333333333333333444444
  2 | 55555555555555555555555555556666666666666666666666666666666666667777+92
  3 | 00000000000000000000000000000001111111111111111111111111111111111111+121
  3 | 55555555555555555555555555555556666666666667777777777777777777777777+19
  4 | 00000000000111111111112222222222223333333444
  4 | 555667777999
  5 | 0000014
  5 | 7888
  6 | 2

1 Answer 1

1

The counties data is in a lat-long coordinate system:

> st_centroid(st_geometry(counties))
Geometry set for 159 features 
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -85.50453 ymin: 30.71009 xmax: -81.13284 ymax: 34.91671
Geodetic CRS:  NAD83
First 5 geometries:
POINT (-82.13771 30.78134)
POINT (-81.54068 31.23092)
POINT (-82.00076 33.06113)

so knearneigh is going to work in those units, which are degrees. From the help it also looks like it will calculate distances using great circles given lat-long coordinates, and not assume they are numbers on a grid system.

If you don't need the distances for the rest of the work and only need the nearest-neighbour list then you're good to go. If you do need the distances, then you can use st_distance on the centroids to get the great-circle distances. Alternatively you can transform the centroids to a cartesian grid coordinate system in metres using st_transform and work in that. There's probably a standard CRS for Georgia, or you need to find the UTM zone containing your data and use that. Then all the neareast-neighbours will be done in the projected coordinates rather than great circles, which might result in minor differences.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.