我试图获得一些具有高斯边缘的各种 Copula 的漂亮轮廓图,但不知何故,我根本没有得到我所期望的 - 我做错了什么?
我的R代码:
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)
根据您提供的示例,您尝试重新创建的该图看起来就像用于创建联结的二元正态分布。您可以创建二元正态分布的等高线图,匹配您用于联结函数的参数,如下所示:
library(ggplot2)
mu <- c(0, 0)
sigma <- matrix(c(1, 0.7, 0.7, 1), 2, 2) # Use a correlation of 0.7, matching your copula
bivariate_normal <- rmvnorm(100000, mean = mu, sigma = sigma)
colnames(bivariate_normal) <- c("x", "y")
df <- tibble::as_tibble(bivariate_normal)
df |>
ggplot(aes(x = x, y = y)) +
geom_density_2d() +
labs(title = "Bivariate Normal Distribution (Correlation = 0.7)",
x = "X", y = "Y")