Computes the spatial correlation coefficient (Moran's I) of a vector given a distance matrix, and a distance threshold used to define "neighborhood".
Arguments
- x
Numeric vector, generally model residuals, Default:
NULL- distance.matrix
Distance matrix among cases in
x. The number of rows of this matrix must be equal to the length ofx. Default:NULL- distance.threshold
numeric value in the range of values available in
distance.matrix. Distances below such threshold are set to 0. Default:NULL(which defaults to 0).- verbose
Logical, if
TRUE, prints a Moran's I plot. Default:TRUE
Value
A list with three named slots:
test: Data frame with observed and expected Moran's I values, p-value, and interpretation.plot: Moran's plot of the vector x against the spatial lags of x.plot.df: Data used in the Moran's plot.
Details
Inspired in the Moran.I() function of the ape package.
Examples
#loading example data
data(distance_matrix)
data(plant_richness_df)
#Moran's I of the response variable
out <- moran(
x = plant_richness_df$richness_species_vascular,
distance.matrix = distance_matrix
)
out
#> $test
#> distance.threshold moran.i.null moran.i p.value
#> 1 0 -0.004424779 0.4019806 0
#> interpretation
#> 1 Positive spatial correlation
#>
#> $plot
#>
#> $plot.df
#> x x.lag
#> 1 4835 4368.3183
#> 2 4360 5909.4259
#> 3 1362 1604.9887
#> 4 7818 4863.0757
#> 5 10394 8523.0261
#> 6 2690 7123.0241
#> 7 5109 6395.6429
#> 8 7372 4017.7514
#> 9 2766 3077.2355
#> 10 4254 5578.2924
#> 11 2610 3178.1693
#> 12 2502 3883.8773
#> 13 492 498.8487
#> 14 6084 6684.7941
#> 15 10248 6429.4275
#> 16 7963 6353.2393
#> 17 3976 5073.5762
#> 18 4253 4158.5834
#> 19 4110 3894.2505
#> 20 2578 6414.4450
#> 21 7546 8385.7792
#> 22 6940 6923.7338
#> 23 15207 4283.8823
#> 24 2502 3108.6868
#> 25 566 962.0570
#> 26 7158 7035.2828
#> 27 2169 2310.5125
#> 28 2507 5953.2691
#> 29 904 1359.3426
#> 30 1162 804.6076
#> 31 2435 3278.0874
#> 32 8874 6647.0586
#> 33 4939 7626.1568
#> 34 3398 2867.0901
#> 35 5893 6293.7076
#> 36 5861 7823.0254
#> 37 1986 3638.6749
#> 38 2503 4620.5206
#> 39 760 879.8758
#> 40 1056 1839.7473
#> 41 2324 2311.4758
#> 42 4119 2564.0549
#> 43 2362 3011.7135
#> 44 3017 3212.9472
#> 45 2774 4393.8251
#> 46 2656 2875.5411
#> 47 2014 2780.6413
#> 48 1353 5283.7504
#> 49 1461 2330.0667
#> 50 4767 4187.5883
#> 51 4426 4908.8691
#> 52 2776 3052.9065
#> 53 1489 2167.3774
#> 54 2942 2614.5905
#> 55 397 799.4982
#> 56 11751 7681.5538
#> 57 3831 2345.3673
#> 58 1279 3071.4096
#> 59 681 3986.2620
#> 60 777 904.0946
#> 61 1981 2535.9755
#> 62 1466 6681.7905
#> 63 10813 6731.3003
#> 64 6103 3816.9916
#> 65 2887 4166.2646
#> 66 3231 7489.2782
#> 67 11213 9088.8757
#> 68 5175 7185.4311
#> 69 1016 1093.9574
#> 70 3784 3364.9129
#> 71 4866 7477.1001
#> 72 1162 1120.7208
#> 73 11637 7101.9210
#> 74 5374 3666.8794
#> 75 4886 4257.8382
#> 76 288 1206.2662
#> 77 2279 6884.7060
#> 78 1740 5127.3180
#> 79 370 3837.5450
#> 80 3306 3317.0790
#> 81 2176 4798.6409
#> 82 1335 1524.1047
#> 83 2143 6789.9206
#> 84 2225 2788.8132
#> 85 3586 4337.8403
#> 86 683 800.5768
#> 87 2324 3855.0199
#> 88 2127 6271.5716
#> 89 2758 4118.1962
#> 90 1626 1893.8264
#> 91 5456 3662.1279
#> 92 807 3880.5085
#> 93 1495 3753.7027
#> 94 10237 7241.7882
#> 95 3873 8880.8585
#> 96 4247 4985.6259
#> 97 9762 6663.5340
#> 98 7481 8003.7927
#> 99 10738 8836.8818
#> 100 2960 5557.4603
#> 101 2814 2830.9187
#> 102 5324 5787.1852
#> 103 1746 1958.6108
#> 104 1463 4090.6375
#> 105 3859 3668.4180
#> 106 1877 2767.6785
#> 107 7100 6584.0362
#> 108 3555 4659.7921
#> 109 6773 9529.4151
#> 110 583 5002.8990
#> 111 1946 6409.7379
#> 112 3996 2711.0997
#> 113 2130 3568.4787
#> 114 390 5132.6664
#> 115 7158 9397.8923
#> 116 663 838.8103
#> 117 1900 3523.5747
#> 118 1233 4363.7955
#> 119 2977 4063.6008
#> 120 922 1009.9923
#> 121 768 2178.5612
#> 122 11893 4663.6103
#> 123 1337 1083.1607
#> 124 3552 3859.0821
#> 125 3156 4050.0754
#> 126 4174 7033.6847
#> 127 2699 7780.5820
#> 128 3799 3549.1571
#> 129 2513 4790.2413
#> 130 3293 2651.8489
#> 131 4129 5439.9601
#> 132 2156 2220.0287
#> 133 874 1048.7245
#> 134 4349 1916.2288
#> 135 7677 6915.3229
#> 136 10302 6134.9954
#> 137 979 970.9996
#> 138 2121 2864.7848
#> 139 2731 4793.2146
#> 140 1058 1192.4013
#> 141 7669 3805.1163
#> 142 2704 3377.3832
#> 143 1240 1213.6701
#> 144 5745 6842.0618
#> 145 5352 6454.5336
#> 146 792 3287.1665
#> 147 2954 3084.7135
#> 148 3150 4302.4927
#> 149 1406 1556.8688
#> 150 316 452.0215
#> 151 2448 6611.0317
#> 152 2331 2741.3252
#> 153 6006 6381.5374
#> 154 2393 2735.2333
#> 155 6705 6512.2170
#> 156 8004 6464.5759
#> 157 7488 4925.3907
#> 158 2331 3028.2236
#> 159 2432 7027.6256
#> 160 9986 7099.4369
#> 161 2740 2541.7869
#> 162 2498 9498.4190
#> 163 5188 6996.1839
#> 164 6774 5153.5209
#> 165 22187 7395.7515
#> 166 2778 3785.9743
#> 167 5535 3538.1065
#> 168 1871 4818.6468
#> 169 1453 3268.6825
#> 170 1724 3860.0428
#> 171 7056 9885.6102
#> 172 703 924.7212
#> 173 1080 946.2533
#> 174 3468 7445.3538
#> 175 2408 3570.3173
#> 176 4414 3564.9578
#> 177 3364 5360.7608
#> 178 16958 8023.4315
#> 179 3111 5082.7382
#> 180 233 482.0102
#> 181 3963 4068.4379
#> 182 4978 6800.2922
#> 183 648 955.7915
#> 184 3894 3475.5145
#> 185 7345 6602.9181
#> 186 2824 4075.1437
#> 187 5100 8360.3885
#> 188 8513 5723.9092
#> 189 2631 2102.9004
#> 190 4011 3295.7322
#> 191 5364 11122.9172
#> 192 10709 6097.8733
#> 193 3433 2326.0115
#> 194 5432 6733.6451
#> 195 9960 6120.2914
#> 196 742 868.1924
#> 197 251 1138.3890
#> 198 19091 6161.2758
#> 199 1714 2500.1911
#> 200 1247 1239.2068
#> 201 2793 5242.1340
#> 202 2174 2250.7517
#> 203 6262 3966.3815
#> 204 6324 4810.3493
#> 205 3297 6750.9859
#> 206 4101 5326.6182
#> 207 7823 9076.8551
#> 208 1965 5791.1754
#> 209 2877 8868.0648
#> 210 1165 5694.9271
#> 211 2467 5319.3496
#> 212 3558 2828.2183
#> 213 5715 5242.4030
#> 214 12026 6689.6591
#> 215 4495 5275.1110
#> 216 9000 7961.2469
#> 217 847 1104.2053
#> 218 4489 6038.4730
#> 219 420 2353.6291
#> 220 2397 2738.6542
#> 221 2457 2652.6558
#> 222 1776 3568.3498
#> 223 5625 6952.2592
#> 224 4863 7009.4450
#> 225 3326 2152.1098
#> 226 3480 8542.7381
#> 227 1425 6664.6001
#>
#> attr(,"class")
#> [1] "moran"