A function that finds the local outlier factor (Breunig et al.,2000) of the matrix "data" using k neighbours. The local outlier factor (LOF) is a measure of outlyingness that is calculated for each observation. The user decides whether or not an observation will be considered an outlier based on this measure. The LOF takes into consideration the density of the neighborhood around the observation to determine its outlyingness.

LOF(data, k)

Arguments

data

The data set to be explored

k

The kth-distance to be used to calculate the LOF's.

Details

The LOFs are calculated over a range of values, and the max local outlier factor is determined over this range.

Note

This function was originally published in the library dprep.

Value

lof

A vector with the local outlier factor of each observation

References

Breuning, M., Kriegel, H., Ng, R.T, and Sander. J. (2000). LOF: Identifying density-based local outliers. In Proceedings of the ACM SIGMOD International Conference on Management of Data

Author

Caroline Rodriguez

Examples

# Detecting the top 10 outliers using the LOF algorithm

(iris.lof <- LOF(iris[,-5], 10))
#>   [1] 0.9749183 0.9933587 0.9971526 1.0082478 0.9976917 1.1171744 1.1367249
#>   [8] 0.9759294 1.2258481 0.9771966 1.0505187 1.0374252 0.9681938 1.4668862
#>  [15] 1.4358094 1.6070560 1.1684473 0.9724836 1.2538291 1.0277455 1.1418438
#>  [22] 0.9985157 1.6511907 1.2176375 1.3457631 1.0752058 1.0140112 0.9848109
#>  [29] 0.9847763 0.9539171 0.9786418 1.1052521 1.2580528 1.3292011 0.9771966
#>  [36] 1.0561318 1.1505964 1.0053093 1.1763094 0.9694070 0.9691967 2.1401892
#>  [43] 1.1634980 1.2846246 1.2743178 0.9681938 1.1023672 1.0025265 1.0224348
#>  [50] 0.9767920 1.0979408 0.9901712 1.0972535 1.0538616 0.9629112 1.0114595
#>  [57] 0.9973142 1.5092052 1.0037563 1.1289565 1.4601484 0.9992419 1.1892734
#>  [64] 0.9777481 1.1354693 1.0264278 1.0379323 0.9597265 1.2802262 1.0313942
#>  [71] 1.0542443 1.0448665 1.0354977 0.9868557 0.9959136 1.0062564 1.0422980
#>  [78] 1.0111163 0.9953478 1.1887348 1.0729744 1.0899291 0.9747153 0.9842419
#>  [85] 1.1455531 1.0776115 1.0433643 1.2078677 0.9735054 1.0055367 1.0227888
#>  [92] 0.9893527 0.9687127 1.4359117 0.9782820 0.9763235 0.9852838 0.9988898
#>  [99] 1.5296245 0.9597168 1.1422904 1.0333302 1.0699243 1.0361851 0.9982689
#> [106] 1.1366996 1.6907715 1.1523481 1.1793638 1.2761094 1.0222755 1.0112407
#> [113] 0.9756681 1.1200491 1.2440212 1.0018319 0.9743390 1.2640817 1.2613618
#> [120] 1.1273150 0.9895024 1.0803134 1.1936765 0.9715100 0.9946723 1.1513666
#> [127] 0.9796737 0.9911333 0.9685807 1.2152147 1.1421662 1.2609661 0.9704360
#> [134] 0.9920405 1.2411459 1.1450440 1.0565329 0.9848026 0.9817719 0.9847805
#> [141] 1.0002989 1.0475650 1.0333302 0.9963329 1.0315736 1.0116648 1.0012104
#> [148] 0.9991678 1.1183161 0.9910457