Removes out or flags records that are outliers in geographic space according to the method defined via the method argument. Geographic outliers often represent erroneous coordinates, for example due to data entry errors, imprecise geo-references, individuals in horticulture/captivity.

cc_outl(x, lon = "decimallongitude", lat = "decimallatitude",
  species = "species", method = "quantile", mltpl = 5, tdi = 1000,
  value = "clean", sampling_thresh = 0, verbose = TRUE,
  min_occs = 7, thinning = FALSE, thinning_res = 0.5)

Arguments

x

data.frame. Containing geographical coordinates and species names.

lon

character string. The column with the longitude coordinates. Default = “decimallongitude”.

lat

character string. The column with the latitude coordinates. Default = “decimallatitude”.

species

character string. The column with the species name. Default = “species”.

method

character string. Defining the method for outlier selection. See details. One of “distance”, “quantile”, “mad”. Default = “quantile”.

mltpl

numeric. The multiplier of the interquartile range (method == 'quantile') or median absolute deviation (method == 'mad')to identify outliers. See details. Default = 5.

tdi

numeric. The minimum absolute distance (method == 'distance') of a record to all other records of a species to be identified as outlier, in km. See details. Default = 1000.

value

character string. Defining the output value. See value.

sampling_thresh

numeric. Cut off threshold for the sampling correction. Indicates the quantile of sampling in which outliers should be ignored. For instance, if sampling_thresh == 0.25, records in the 25 not be flagged as outliers. Default = 0 (no sampling correction).

verbose

logical. If TRUE reports the name of the test and the number of records flagged.

min_occs

Minimum number of geographically unique datapoints needed for a species to be tested. This is necessary for reliable outlier estimation. Species wit less than min_occs records will not be tested and the output value will be 'TRUE'. Default is to 7. If method == 'distance', consider a lower threshold.

thinning

forces a raster approximation for the distance calculation. This is routinely used for species with more than 10,000 records for computational reasons, but can be enforced for smaller datasets, which is reommended when sampling is very uneven.

thinning_res

The resolution for the spatial thinning in decimal degrees. Default = 0.5.

Value

Depending on the ‘value’ argument, either a data.frame containing the records considered correct by the test (“clean”) or a logical vector (“flagged”), with TRUE = test passed and FALSE = test failed/potentially problematic . Default = “clean”.

Details

The method for outlier identification depends on the method argument. If “outlier”: a boxplot method is used and records are flagged as outliers if their mean distance to all other records of the same species is larger than mltpl * the interquartile range of the mean distance of all records of this species. If “mad”: the median absolute deviation is used. In this case a record is flagged as outlier, if the mean distance to all other records of the same species is larger than the median of the mean distance of all points plus/minus the mad of the mean distances of all records of the species * mltpl. If “distance”: records are flagged as outliers, if the minimum distance to the next record of the species is > tdi. For species with records from > 10000 unique locations a random sample of 1000 records is used for the distance matrix calculation. The test skipps species with less than min_occs, geographically unique records.

The likelihood of occurrence records being erroneous outliers is linked to the sampling effort in any given location. To account for this, the sampling_cor option fetches the number of occurrence records available from www.gbif.org, per country as a proxy of sampling effort. The outlier test (the mean distance) for each records is than weighted by the log transformed number of records per square kilometre in this country. See for https://ropensci.github.io/CoordinateCleaner/articles/Tutorial_geographic_outliers.html an example and further explanation of the outlier test.

Note

See https://ropensci.github.io/CoordinateCleaner/ for more details and tutorials.

See also

Examples

x <- data.frame(species = letters[1:10], decimallongitude = runif(100, -180, 180), decimallatitude = runif(100, -90,90)) cc_outl(x)
#> Testing geographic outliers
#> Removed 0 records.
#> species decimallongitude decimallatitude #> 1 a 169.610605 -44.4906216 #> 2 b -96.220439 28.2080702 #> 3 c 132.270486 52.0468937 #> 4 d -140.125773 37.5922166 #> 5 e 108.537041 -78.3732614 #> 6 f 56.852804 2.0360419 #> 7 g 54.739547 -53.8328970 #> 8 h -98.523848 56.5408067 #> 9 i 127.432667 27.6804137 #> 10 j -23.181466 -26.4146432 #> 11 a -75.858575 17.3870813 #> 12 b 49.530481 40.9867872 #> 13 c -84.765795 89.2023371 #> 14 d -40.943384 -0.3500511 #> 15 e 42.909829 -48.5469415 #> 16 f 15.004110 -35.7742237 #> 17 g -5.460840 39.6840018 #> 18 h 95.146171 -42.9470247 #> 19 i 165.969697 -70.6146573 #> 20 j -82.589568 -42.7639118 #> 21 a 83.016080 -56.3928870 #> 22 b -131.700403 7.6395023 #> 23 c -162.576638 -78.2066746 #> 24 d 73.298545 68.4693246 #> 25 e -127.003034 -39.7417433 #> 26 f 96.895920 31.0866609 #> 27 g -116.513960 -79.1764427 #> 28 h -140.126760 87.9273990 #> 29 i 157.803267 -39.1904224 #> 30 j 124.729610 9.7402260 #> 31 a 25.611689 70.2151208 #> 32 b 64.473626 -85.8956301 #> 33 c -147.843992 31.9839217 #> 34 d 102.734685 -29.3292366 #> 35 e -98.295319 -64.5847030 #> 36 f -18.655753 -26.5384822 #> 37 g -121.958051 -17.7399258 #> 38 h -116.599792 70.0045834 #> 39 i -108.637876 -33.7294462 #> 40 j -51.259927 -78.9021525 #> 41 a -114.720047 32.3075275 #> 42 b 22.012150 -21.9307376 #> 43 c 57.269883 15.9066627 #> 44 d 57.691227 -1.4438637 #> 45 e -179.135716 -38.5601501 #> 46 f 177.640572 -88.4844729 #> 47 g 45.896123 9.1393735 #> 48 h -174.733079 56.3815634 #> 49 i -106.135842 25.8434254 #> 50 j 58.707599 -77.5688395 #> 51 a -13.052149 41.1689289 #> 52 b -50.274663 30.9800157 #> 53 c 68.171901 57.5641784 #> 54 d -86.810116 74.6318804 #> 55 e 126.433812 34.1947225 #> 56 f -7.198311 -1.4439955 #> 57 g 13.415900 26.4471571 #> 58 h 58.190363 -7.8273078 #> 59 i -71.692376 -67.4196081 #> 60 j -85.139454 18.7856953 #> 61 a -70.183393 58.8288125 #> 62 b 134.984976 21.4880852 #> 63 c 78.637398 61.3896679 #> 64 d -33.508910 -13.0956106 #> 65 e -173.030590 48.4716067 #> 66 f -161.935071 38.1853424 #> 67 g 72.810372 -78.5939025 #> 68 h -156.106703 -13.3190575 #> 69 i -166.992347 -74.1100242 #> 70 j -172.744670 -52.5029725 #> 71 a -45.798805 -48.9130428 #> 72 b -98.760455 -80.9204141 #> 73 c -2.909484 11.1278254 #> 74 d -19.207744 34.9643060 #> 75 e 68.473764 -48.9703222 #> 76 f 123.386393 82.8564489 #> 77 g -44.699880 -1.2893056 #> 78 h 174.560288 40.1775634 #> 79 i 162.873479 -1.5546451 #> 80 j 176.363463 62.1639146 #> 81 a -20.473792 -85.4802606 #> 82 b -124.645013 8.7120437 #> 83 c 160.101836 81.9818670 #> 84 d 7.007909 -64.7096640 #> 85 e -15.971542 37.8492525 #> 86 f -100.767528 -67.2476600 #> 87 g -129.894342 60.4181300 #> 88 h -102.183163 -36.3276893 #> 89 i -33.955678 -21.3608250 #> 90 j -95.855547 -45.3871196 #> 91 a -170.976111 -27.9033031 #> 92 b 90.843105 -14.4389833 #> 93 c 83.546116 28.6397977 #> 94 d -32.721561 81.7122688 #> 95 e 47.108810 -5.4191423 #> 96 f -156.439806 -62.8882035 #> 97 g -126.470825 72.4541123 #> 98 h -79.307365 -11.1553735 #> 99 i 126.236451 55.2160051 #> 100 j -172.245319 -3.3308157
cc_outl(x, method = "quantile", value = "flagged")
#> Testing geographic outliers
#> Flagged 0 records.
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [31] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [46] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [76] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [91] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
cc_outl(x, method = "distance", value = "flagged", tdi = 10000)
#> Testing geographic outliers
#> Flagged 1 records.
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE #> [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [49] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [73] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [85] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [97] TRUE TRUE TRUE TRUE
cc_outl(x, method = "distance", value = "flagged", tdi = 1000)
#> Testing geographic outliers
#> Flagged 92 records.
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [13] TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE #> [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [49] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [61] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE #> [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE #> [85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [97] FALSE FALSE FALSE FALSE