Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do a perform a weighted, 2d kernel density estimation in R?

I would like to produce a kernel density estimation in R, and am somewhat bamboozled by all the different packages. I need to be able to:

  1. Specify weights
  2. Specify bandwidth size
  3. Specify bin size

How would you go about this? Bonus points for a code snippet.

like image 391
fmark Avatar asked Oct 21 '10 07:10

fmark


People also ask

How are the Kernel Density weights calculated?

The KDE is calculated by weighting the distances of all the data points we've seen for each location on the blue line. If we've seen more points nearby, the estimate is higher, indicating that probability of seeing a point at that location.

What is kernel density estimation in R?

What is Kernel Density Estimation? Kernel density estimation is a non-parametric method of estimating the probability density function (PDF) of a continuous random variable. It is non-parametric because it does not assume any underlying distribution for the variable.

What is kernel density estimation?

In statistics, kernel density estimation (KDE) is the application of kernel smoothing for probability density estimation, i.e., a non-parametric method to estimate the probability density function of a random variable based on kernels as weights.

Can kernel density estimation be used for classification?

The method of kernel density estimation can be readily used for the purposes of classification, and an easy-to-use package (alloc80) is now in wide circulation. It is known that this method performs well (at least in relative terms) in the case of bimodal, or heavily skewed distributions.


2 Answers

See also the ks package and the nice picture in Multivariate kernel density estimation.

like image 131
denis Avatar answered Sep 20 '22 05:09

denis


Off course there's a number of packages. You should first decide which 2D kernel estimate you want. In the fields package you have a function smooth.2d, and you have the wonderful package of Brian Ripley, KernSmooth. The extra points for the code snippets you can give to the help files, I ain't going to copy them.

For these kind of questions, also try www.rseek.org.

like image 29
Joris Meys Avatar answered Sep 21 '22 05:09

Joris Meys