7

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.

Marek
  • 49,472
  • 15
  • 99
  • 121
fmark
  • 57,259
  • 27
  • 100
  • 107

2 Answers2

3

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

denis
  • 21,378
  • 10
  • 65
  • 88
2

Of course there are 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.

Community
  • 1
  • 1
Joris Meys
  • 106,551
  • 31
  • 221
  • 263
  • Thanks for your patience, I'm very much new to the R world and its culture, and its taking a while to learn how things are done here :) – fmark Oct 21 '10 at 11:00
  • 1
    @fmark: no problem. You can also take a look at this question http://stackoverflow.com/questions/102056/how-to-search-for-r-materials and this question http://stackoverflow.com/questions/192369/books-for-learning-the-r-language – Joris Meys Oct 21 '10 at 11:26
  • In answer to your question, a Gaussian smoother will do me nicely, and the `fields` package `smooth.2d` seems to have all the parameters I require. – fmark Oct 21 '10 at 11:36