Learn R Programming

Introduction

Kernel smoothing for data from 1- to 6-dimensions. This package forms the basis for the practical data analysis in the book Multivariate Kernel Smoothing and Its Applications.

There are three main types of functions in this package:

  • computing kernel estimators - these function names begin with k
  • computing bandwidth selectors - these begin with h (1-d) or H (>1-d)
  • displaying kernel estimators - these begin with plot.

The kernel used throughout is the normal (Gaussian) kernel. For 1-d data, the bandwidth h is the standard deviation of the normal kernel, whereas for multivariate data, the bandwidth matrix H is the variance matrix.

The main function kde() computes a kernel density estimate. For display, its plot method calls plot.kde(). The bandwidth choice is crucial for the performance of kernel estimators. There are several varieties of bandwidth selectors available

  • plug-in hpi (1-d); Hpi(), Hpi.diag() (2- to 6-d)
  • least squares (or unbiased) cross validation (LSCV or UCV) hlscv() (1-d); Hlscv(), Hlscv.diag() (2- to 6-d)
  • biased cross validation (BCV) Hbcv(), Hbcv.diag() (2- to 6-d)
  • smoothed cross validation (SCV) hscv() (1-d); Hscv(), Hscv.diag() (2- to 6-d)
  • normal scale hns() (1-d); Hns() (2- to 6-d).

For an example with bivariate data, see vignette("ks"). The other types of kernel estimators follow a similar functionality.

Installation

Install the latest release version from CRAN:

install.packages("ks") 

Geospatial and tidy data analysis

The functionality in the ks package is ported to the sister eks package. The latter can substantially simplify workflows for geospatial and tidy data analysis.

If the input are geospatial data, then the output are also geospatial and are compatible with base R and ggplot2 graphics. Likewise, if the input are tidy data, then output are also tidy and are compatible with ggplot2 graphics.

Further reading

Chacon, J.E. & Duong, T. (2018) Multivariate Kernel Smoothing and Its Applications. Chapman & Hall/CRC Press, Boca Raton.

Duong, T. (2004) Bandwidth Matrices for Multivariate Kernel Density Estimation Ph.D. Thesis, University of Western Australia.

Copy Link

Version

Install

install.packages('ks')

Monthly Downloads

54,418

Version

1.15.3

License

GPL-2 | GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Tarn Duong

Last Published

August 4th, 2026

Functions in ks (1.15.3)

kda

Kernel discriminant analysis (kernel classification)
hsct

Haematopoietic stem cell transplant
kcopula

Kernel copula (density) estimate
contour

Contour functions
kdde

Kernel density derivative estimate
histde

Histogram density estimate
grevillea

Geographical locations of grevillea plants
kcde

Kernel cumulative distribution/survival function estimate
ise.mixt

Squared error bandwidth matrix selectors for normal mixture densities
kdcde

Deconvolution kernel density derivative estimate
kde.local.test

Kernel density based local two-sample comparison test
kfe

Kernel functional estimate
kde.test

Kernel density based global two-sample comparison test
kroc

Kernel receiver operating characteristic (ROC) curve
kde.truncate

Truncated kernel density derivative estimate
kfs

Kernel feature significance
kde

Kernel density estimate
kde.boundary

Kernel density estimate for bounded data
kdr

Kernel density ridge estimation
kms

Kernel mean shift clustering
ks-internal

Internal functions in the ks library
ksupp

Kernel support estimate
plot.kde

Plot for kernel density estimate
mixt

Normal and t-mixture distributions
plot.histde

Plot for histogram density estimate
plot.kdde

Plot for kernel density derivative estimate
plotmixt

Plot for 1- to 3-dimensional normal and t-mixture density functions
plot.kde.part

Partition plot for kernel density clustering
plot.kfs

Plot for kernel feature significance
plot.kcde

Plot for kernel cumulative distribution estimate
unicef

Unicef child mortality - life expectancy data
plot.kroc

Plot for kernel receiver operating characteristic curve (ROC) estimate
ks-package

ks
plot.kda

Plot for kernel discriminant analysis
vector

Vector and vector half operators
worldbank

Development indicators from the World Bank Group
pre.transform

Pre-sphering and pre-scaling
rkde

Derived quantities from kernel density estimates
tempb

Daily temperature
quake

Geographical locations of earthquakes and tectonic plates
vkde

Variable kernel density estimate.
plot.kde.loctest

Plot for kernel local significant difference regions
binning

Linear binning for multivariate data
cardio

Foetal cardiotocograms
Hnm

Normal mixture bandwidth
Hpi

Plug-in bandwidth selector
Hlscv

Least-squares cross-validation (LSCV) bandwidth matrix selector for multivariate data
air

Air quality measurements in an underground train station
Hns

Normal scale bandwidth
Hbcv

Biased cross-validation (BCV) bandwidth matrix selector for bivariate data
Hscv

Smoothed cross-validation (SCV) bandwidth selector
as.kde

Quasi kernel density estimate