I am trying to get some nice contour plots of various Copulas with Gaussian marginals, but somehow I do not at all get what I would expect - what am I doing wrong ?
My R code:
library(copula)
library(mvtnorm)
#Gaussian Density & distribution
G_copula = norm.cop <- normalCopula(0.70)
cp <- contour(G_copula, dCopula, n=200, nlevels=20, delta=0.01)
persp(G_copula, dCopula)
contour(cp$x,cp$y,cp$z)
contour(qnorm(cp$x),qnorm(cp$y),cp$z)
If you want the contours plot of the copula with margins N(0,1) and N(0,1), one option is to "manually" define its density:
library(copula)
cop <- normalCopula(0.7)
# density of the bivariate distribution with copula 'cop' and margins N(0,1), N(0,1)
f <- function(x, y) {
dCopula(c(pnorm(x), pnorm(y)), cop) * dnorm(x) * dnorm(y)
}
Then you can use the usual contour
function.
But it's easier to create this distribution with mvdc
:
library(copula)
mv <- mvdc(
normalCopula(0.7), margins = c("norm", "norm"),
paramMargins = list(list(mean = 0, sd = 1), list(mean = 0, sd = 1))
)
Then you can directly call contour
on this multivariate distribution:
contour(mv, dMvdc, xlim = c(-3, 3), ylim = c(-3, 3), asp = 1)