Dear R-ers: I'm sorry to disturb you, I want just ask if R can plot a given complicated density function. I mean if we have the expression of the density en we want to see how it's look like? and this is a density with two variables thus it's a 3D plot Thank you very much Hicham Amsterdam
On 11 Jan 2003 at 12:22, H. Zmarrou wrote: Hola! You need persp, and for the following example, library(mvtnorm) (from CRAN)> x <- seq(-3,3, length=200) > y <- seq(-3,3,length=200) > z <- matrix(0, 200, 200) > for (i in 1:200) for (j in 1:200) {+ z[i,j] <- dmvnorm(c(x[i],y[j]), c(0,0), matrix(c(1,0.5,0.5,1),2,2)) }> persp(x,y,z)Kjetil Halvorsen> > Dear R-ers: > I'm sorry to disturb you, I want just ask if R can plot a given > complicated density function. I mean if we have the expression of the > density en we want to see how it's look like? and this is a density > with two variables thus it's a 3D plot > > Thank you very much > Hicham Amsterdam > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
You can use a few functions: persp, contour, filled.contour, image. Say dens() is your density function of two variables, for example, dens <- function(x, y) { dnorm(x) * dnorm(y) } then you could do: x <- seq(-3, 3, len = 40) y <- seq(-3, 3, len = 30) g <- expand.grid(x, y) mat <- matrix(dens(g[,1], g[,2]), nrow = 40, ncol = 30) image(x,y,mat) persp(x,y,mat) filled.contour(x,y,mat) contour(x,y,mat) -roger _______________________________ UCLA Department of Statistics rpeng at stat.ucla.edu http://www.stat.ucla.edu/~rpeng On Sat, 11 Jan 2003, H. Zmarrou wrote:> > Dear R-ers: > I'm sorry to disturb you, I want just ask if R can plot a given > complicated density function. I mean if we have the expression of the > density en we want to see how it's look like? and this is a density > with two variables thus it's a 3D plot > > Thank you very much > Hicham Amsterdam > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help >