Hi All, I have a 2-dim density defined on 0<x<1, 0<y<1, x<y. I know the exact formula of the density. How can I visualize it? What plot functions can I use? Thanks, Annie [[alternative HTML version deleted]]
I'd suggest either a color plot as given by image() and related functions or a 3d mesh-plot which you can get from persp() E.g., x = seq(0,1,by=0.01); y = x z = outer(x,y+1,"/") # z = x/(y+1) -- I know that's not a density but you can adapt as necessary filled.contour(x,y,z) persp(x,y,z) There are many more functions like this available, but here's a start. Good luck! Michael Weylandt On Thu, Aug 11, 2011 at 3:11 PM, annie Zhang <annie.zhang2010@gmail.com>wrote:> Hi All, > > I have a 2-dim density defined on 0<x<1, 0<y<1, x<y. I know the exact > formula of the density. How can I visualize it? What plot functions can I > use? > > Thanks, > Annie > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
On 11/08/2011 3:11 PM, annie Zhang wrote:> Hi All, > > I have a 2-dim density defined on 0<x<1, 0<y<1, x<y. I know the exact > formula of the density. How can I visualize it? What plot functions can I > use?persp() or contour() are in the graphics package. There are similar ones in lattice (and I think in ggplot2), but I forget their names. There's also persp3d() in the rgl package for a rotatable version of persp(). Supposing f(x,y) gives the density at (x,y) (or NA if x > y), you plot it as follows: x <- seq(0, 1, len=30) y <- seq(0, 1, len=30) z <- outer(x, y, f) persp(x,y,z) contour(x,y,z) persp3d(x,y,z) This relies on f() being vectorized; if it's not, use z <- outer(x,y, Vectorize(f)) instead. Duncan Murdoch