# Get conditional kernel densities in julia

**URL:** https://discourse.julialang.org/t/get-conditional-kernel-densities-in-julia/54086
**Category:** Probabilistic Programming
**Tags:** question, distributions
**Created:** [January 27, 2021, 9:53pm UTC](https://discourse.julialang.org/t/get-conditional-kernel-densities-in-julia/54086 "2021-01-27T21:53:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![claudio20497](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/claudio20497/32/36602_2.png) [@claudio20497](https://discourse.julialang.org/u/claudio20497)
#### Post date: [January 27, 2021, 9:53pm UTC](https://discourse.julialang.org/t/get-conditional-kernel-densities-in-julia/54086/1 "2021-01-27T21:53:55Z")

</div>

Hello,

I was wondering if there is a method to get a conditional distribution out of a multivariate kde in julia, preferably using the package [KernelDensityEstimate.jl](https://github.com/JuliaRobotics/KernelDensityEstimate.jl).

So say for example that I have the following code:

```julia
using KernelDensityEstimate, Distributions

# define number of samples
const n_samples = 500

# define two correlated variables
const x = randn(n_samples)
const y = x.^2 .+ rand(Uniform(-0.0005, 0.0005), n_samples) 

# and an uncorrelated one
const z = rand(Gamma(), n_samples);

# fit the kde
kde = kde!(Array((hcat(x,y,z)')))

```

And I would like to get the distribution of x and y conditioned to, say, z = 10.0.

It would be ok for me if the solution uses a multivariate KDEs package different from [KernelDensityEstimate.jl](https://github.com/JuliaRobotics/KernelDensityEstimate.jl), as long as it implements a `rand` function.

Thank you very much
