# Kernel density estimation status

**URL:** https://discourse.julialang.org/t/kernel-density-estimation-status/5928
**Category:** Statistics
**Tags:** question, package
**Created:** [September 17, 2017, 3:30am UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928 "2017-09-17T03:30:03Z")
**Posts on this page:** 11
**Page:** 2

<div class="post-metadata">

### Author: ![Nectarineimp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nectarineimp/32/883_2.png) [@Nectarineimp](https://discourse.julialang.org/u/Nectarineimp)
#### Post date: [September 20, 2017, 8:36pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/21 "2017-09-20T20:36:51Z")

</div>

Sure, that would be fun to look at. Here is what I am seeing currently, and helping with these issues might be more productive. Maybe you aren’t seeing these and it’s just me, in which case figuring out what is causing it may be of value in improving stability.

example code that is failing:

y = randn(100\_000)  
o = ash(y; rng = -5:.1:5)

> MethodError: no method matching ash(:Array{Float64,1}; rng=-5.0:0.1:5.0)

Just using the package gives a list of deprecated syntax. Examples:

WARNING: deprecated syntax “typealias VecF Vector{Float64}” at C:\Users\pmancini.julia\v0.6\AverageShiftedHistograms\src\AverageShiftedHistograms.jl:13.  
Use “const VecF = Vector{Float64}” instead.

WARNING: deprecated syntax “typealias MatF Matrix{Float64}” at C:\Users\pmancini.julia\v0.6\AverageShiftedHistograms\src\AverageShiftedHistograms.jl:14.  
Use “const MatF = Matrix{Float64}” instead.

WARNING: deprecated syntax “typealias AVecF AbstractVector{Float64}” at C:\Users\pmancini.julia\v0.6\AverageShiftedHistograms\src\AverageShiftedHistograms.jl:15.  
Use “const AVecF = AbstractVector{Float64}” instead.

WARNING: deprecated syntax “typealias AMatF AbstractMatrix{Float64}” at C:\Users\pmancini.julia\v0.6\AverageShiftedHistograms\src\AverageShiftedHistograms.jl:16.  
Use “const AMatF = AbstractMatrix{Float64}” instead.

WARNING: deprecated syntax “abstract ASH” at C:\Users\pmancini.julia\v0.6\AverageShiftedHistograms\src\AverageShiftedHistograms.jl:18.  
Use “abstract type ASH end” instead.

If I can help with any of these and make the package more useable and stable as is, adding the pdf function would then be easier.

---

<div class="post-metadata">

### Author: ![joshday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshday/32/368_2.png) [@joshday](https://discourse.julialang.org/u/joshday)
#### Post date: [September 20, 2017, 8:38pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/22 "2017-09-20T20:38:15Z")

</div>

You must not be on master. Try `Pkg.checkout("AverageShiftedHistograms")`. There’s a PR to get the updates into Metadata as well.

---

<div class="post-metadata">

### Author: ![Nectarineimp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nectarineimp/32/883_2.png) [@Nectarineimp](https://discourse.julialang.org/u/Nectarineimp)
#### Post date: [September 20, 2017, 8:52pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/23 "2017-09-20T20:52:08Z")

</div>

Lets give it a try… time passes… [Jeopardy theme song plays]  
OK, fewer deprecation warning. Code runs.  
So much better. Can I iterate the resulting Ash object? I can’t seem to get it to plot in Gadfly. I poked it a bit and didn’t see an obvious method for getting the values. However. Damn. It was fast. Much faster than the other methods I’ve used.

---

<div class="post-metadata">

### Author: ![joshday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshday/32/368_2.png) [@joshday](https://discourse.julialang.org/u/joshday)
#### Post date: [September 20, 2017, 8:54pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/24 "2017-09-20T20:54:09Z")

</div>

I still need to finish the docs…

Try

```julia
a = ash(y)
xvals, densityvals = xy(a) 

```

---

<div class="post-metadata">

### Author: ![Nectarineimp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nectarineimp/32/883_2.png) [@Nectarineimp](https://discourse.julialang.org/u/Nectarineimp)
#### Post date: [September 20, 2017, 9:11pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/25 "2017-09-20T21:11:25Z")

</div>

Bueno!

![p1](https://global.discourse-cdn.com/julialang/original/3X/3/2/32dda32c782f1c738200c3ff37968659013bd712.png)

OK. I will study your code and see if can get a start on a PDF based function.

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [September 20, 2017, 9:34pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/26 "2017-09-20T21:34:10Z")

</div>

It’s cool that you also put plot recipes in the package! I’ll try it out soon as I also am a bit frustrated by kernel density lack of speed. There already is one recipe for kernel density [here](https://github.com/JuliaPlots/StatPlots.jl/blob/master/src/StatPlots.jl#L17) so that

`plot(kde(args...))`

makes a line plot for 1D density and a contour plot for 2D density. The seriestype can be changed manually so that for example:

`heatmap(kde(args...))`

would give the heatmap, surface the surface and so on…

Could the `ash` plot recipe behavior be changed to be consistent?

About the 1D recipe, it’d be nice to be consistent, but it’s also true that you have two things to show. Would there be an equivalent plot to that for kernel density? Also, is there an easy way to not display the `:sticks` series? I guess it becomes confusing when splitting data and displaying several ash densities in the same plot.

---

<div class="post-metadata">

### Author: ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)
#### Post date: [April 9, 2020, 3:44am UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/27 "2020-04-09T03:44:48Z")

</div>

I’d like to revive this topic to get an up-to-date overview of the available packages for doing this.

FWIW, I need to plot the joint PDF of model output vs observations in my research quite often, so I’m mostly interested in the 2D case. Previously, as a MATLAB user, I was using `kde2d.m` ([source on Mathworks](https://slack-redir.net/link?url=https%3A%2F%2Fau.mathworks.com%2Fmatlabcentral%2Ffileexchange%2F17204-kernel-density-estimation&v=3)). In Julia, I have been using KernelDensity.jl lately, but I think I preferred the bandwith selection algorithm of `kde2d.m`. So I started to try to translate `kde2d.m` to Julia (see [this small gist](https://gist.github.com/briochemc/ee55f860d90f593e8fe2dd440a7eb76c)) but then I thought that this would probably be done much better by one of the KDE-package developers! Maybe one of you wants to add this algorithm to his package?

@juliohm, whatever answers we get, it would be great if you could update the initial post with a quick overview! (Maybe you just have to select a good answer if someone writes it up below?)

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [April 9, 2020, 6:34am UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/28 "2020-04-09T06:34:56Z")

</div>

I have used KernelDensity.jl for bivariate densities. It is the only package that I am aware of for doing it. If there is something you dislike about it, I think your best bet would be to submit issues/PRs to that package.

---

<div class="post-metadata">

### Author: ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)
#### Post date: [April 9, 2020, 3:03pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/29 "2020-04-09T15:03:22Z")

</div>

Well I just found [this issue](https://github.com/JuliaStats/KernelDensity.jl/issues/75) 🙂 But not sure if it will be fruitful…

---

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [July 4, 2021, 2:04pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/30 "2021-07-04T14:04:09Z")

</div>

Incase anyone finds this old thread.

New multidimensional KDE

> **[GitHub - noilreed/MultiKDE.jl: Multivariate kernel density estimation](https://github.com/noilreed/MultiKDE.jl)**
>
> Multivariate kernel density estimation. Contribute to noilreed/MultiKDE.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![matnbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matnbo/32/220166_2.png) [@matnbo](https://discourse.julialang.org/u/matnbo)
#### Post date: [May 7, 2023, 6:42pm UTC](https://discourse.julialang.org/t/kernel-density-estimation-status/5928/31 "2023-05-07T18:42:46Z")

</div>

Package [Jchemo](https://github.com/mlesnoff/Jchemo.jl), also, proposes multivariate (multiplicative) KDE

```julia
using Jchemo
?dmkern

```

![fda dmkern iris](https://global.discourse-cdn.com/julialang/original/3X/c/d/cdc9d21350b8705f52603f74de789e627a31f977.png)

[Previous page](https://discourse.julialang.org/t/kernel-density-estimation-status/5928.md?page=1)
