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):
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)
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.