Skip to content
Prev 156069 / 398513 Next

How to plot contours for joint density of 2 independently distributed r.v.?

do you know the probability density functions for these random variable? 
If yes, then you need something like the following:

x <- seq(-5, 5, len = 50)
y <- seq(0.001, 10, len = 50)
z <- outer(x, y, function(x, y){
     dnorm(x) * dgamma(y, 5)
})

contour(x, y, z)

where you replace dnorm() and dgamma() with your pdf's.

If you just have a sample from X and Y, then you could use kernel 
density estimation, for instance, check

help("bkde2D", package = "KernSmooth")


I hope it helps.

Best,
Dimitris
rlearner309 wrote: