lof1d: Trims extreme values from a vector based on the local outlier...

Description Usage Arguments Details Value Examples

View source: R/lof1d.R

Description

The local outlier factor (LOF) compares the local density of a value to the average local density of its k nearest neighbors. If the ratio of the densities (the LOF) is significantly higher than 1, the point is an outlier and can be discarded. This function uses a highly simplified calculation to trim outlier values from the upper tail of 1-dimensional data.

Usage

1
lof1d(x, k = 5, cutoff = 3)

Arguments

x

A vector of values.

k

The number of nearest neighbors to consider. Also the number of upper tail values considered as possible outliers.

cutoff

The maximum LOF for a value to be retained.

Details

If length(x) is less than 3*k, the vector is returned unchanged. See the Wikipedia page for a description of the LOF algorithm: https://en.wikipedia.org/wiki/Local_outlier_factor

Value

The input vector x with any of the k largest values that have an LOF greater than cutoff removed.

Examples

1
2
3
4
set.seed(222)
x <- c(-5, rnorm(20), 2, 5, 10, 50, 100)
print(x)
print(lof1d(x))

sethmcg/climod documentation built on Nov. 19, 2021, 11:12 p.m.