4

Given the following sample of a multivariate normal:

mu=rep(0,2)
Sigma=matrix(c(1,0,0,1),2,2)
require(MASS)
X=mvrnorm(n=100,mu,Sigma)

I would like to compute is parametric density function. This used to do it as:

require(rgl)
require(mnormt)
zX=dmnorm(as.matrix(X),mean=colMeans(X),varcov=cov(X))
plot3d(X[,1],X[,2],zX) 

but this pops-ups a plot of points (out of RStudio):

enter image description here

I wonder how can I get a graphic RStudio plots windows which also draws a surface with this points. This I could do it with the non-parametric density:

ngrid = 50
Zbiksm = kde2d(X[,1],X[,2],n=ngrid)
Zbiksm_den = Zbiksm$z # valor de la densidad en cada punto del grid
persp(x=Zbiksm$x,y=Zbiksm$y,z=Zbiksm_den,xlab="x",ylab="y",
      zlab=expression(K(x,y)),theta=-35,axes=TRUE,box=TRUE)

enter image description here

but don't know how to do it in this case.

Alternatively, it also works for me to put together the surface3d and the scatterplot images.

user1868607
  • 2,558
  • 1
  • 17
  • 38
  • what do you mean by _"puts together the points"_? – acylam Jul 10 '18 at 17:17
  • well, as in the last image i get a surface, it would be nice to get the points into a surface and compare the two surfaces, showing the differences between them @useR – user1868607 Jul 10 '18 at 17:18
  • @useR it would even be nice to plot together a plot3d and a persp, so to put together the two plots above (maybe changing color of one of them) do you know how to do this? – user1868607 Jul 10 '18 at 17:52
  • Since the plots are 3d, would you want them to be interactive? – acylam Jul 10 '18 at 18:12
  • No, no, I want them to be printable for presentation, i need a two dimensional perspective image @useR, the idea is to be able to see the differences between the two but not 3d, but 2d – user1868607 Jul 10 '18 at 18:20
  • @useR related: https://stackoverflow.com/questions/36049595/mixing-surface-and-scatterplot-in-a-single-3d-plot – user1868607 Jul 10 '18 at 20:18

0 Answers0