Skip to contents

Robust bandwidth estimation for kernel density estimation

Usage

kde_bandwidth(
  data,
  method = c("robust_normal", "double", "lookout"),
  max.iter = 2
)

Arguments

data

A numeric matrix or data frame.

method

Method to use for selecting the bandwidth. robust_normal uses a robust version of the normal reference rule. lookout uses the topological data analysis approach that is part of the lookout algorithm.

max.iter

How many times should the lookout method be iterated. That is, outliers (probability < 0.05) are removed and the bandwidth is re-computed from the remaining observations.

Value

A matrix of bandwidths (or scalar in the case of univariate data).

Author

Rob J Hyndman

Examples

# Univariate bandwidth calculation
kde_bandwidth(oldfaithful$duration)
#> [1] 4.526927
# Bivariate bandwidth calculation
kde_bandwidth(oldfaithful[,2:3])
#>           [,1]      [,2]
#> [1,]  32.85912   182.179
#> [2,] 182.17895 16357.846