nn: Outlier detection using k Nearest Neighbours Distance method

Description Usage Arguments Details Value Author(s) References Examples

Description

Takes a dataset and finds its outliers using distance-based method

Usage

1
2
nn(x, k = 0.05 * nrow(x), cutoff = 0.95, Method = "euclidean",
  rnames = FALSE, boottimes = 100)

Arguments

x

dataset for which outliers are to be found

k

No. of nearest neighbours to be used, default value is 0.05*nrow(x)

cutoff

Percentile threshold used for distance, default value is 0.95

Method

Distance method, default is Euclidean

rnames

Logical value indicating whether the dataset has rownames, default value is False

boottimes

Number of bootsrap samples to find the cutoff, default is 100 samples

Details

nn computes average knn distance of observation and based on the bootstrapped cutoff, labels an observation as outlier. Outlierliness of the labelled 'Outlier' is also reported and it is the bootstrap estimate of probability of the observation being an outlier. For bivariate data, it also shows the scatterplot of the data with labelled outliers.

Value

Outlier Observations: A matrix of outlier observations

Location of Outlier: Vector of Sr. no. of outliers

Outlier probability: Vector of proportion of times an outlier exceeds local bootstrap cutoff

Author(s)

Vinay Tiwari, Akanksha Kashikar

References

Hautamaki, V., Karkkainen, I., and Franti, P. 2004. Outlier detection using k-nearest neighbour graph. In Proc. IEEE Int. Conf. on Pattern Recognition (ICPR), Cambridge, UK.

Examples

1
2
3
4
#Create dataset
X=iris[,1:4]
#Outlier detection
nn(X,k=4)

Example output

Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl.init' failed, running with 'rgl.useNULL = TRUE'. 
$`Outlier Observations`
    Sepal.Length Sepal.Width Petal.Length Petal.Width
42           4.5         2.3          1.3         0.3
107          4.9         2.5          4.5         1.7
118          7.7         3.8          6.7         2.2
132          7.9         3.8          6.4         2.0

$`Location of Outlier`
[1]  42 107 118 132

$`Outlier Probability`
[1] 0.96 1.00 0.96 1.00

$`3Dplot`

Warning messages:
1: `arrange_()` is deprecated as of dplyr 0.7.0.
Please use `arrange()` instead.
See vignette('programming') for more help
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 
2: `line.width` does not currently support multiple values. 
3: `line.width` does not currently support multiple values. 

OutlierDetection documentation built on June 16, 2019, 1:03 a.m.