如何用扩展椭圆绘制二元正态分布

时间:2021-07-31 03:37:04

How to plot bivariate normal distribution with expanding ellipses and add 5%, 25%, 50%, 75% and 95% label in the plot? Thank you!

如何绘制具有扩展椭圆的二元正态分布并在图中添加5%,25%,50%,75%和95%标签?谢谢!

如何用扩展椭圆绘制二元正态分布

1 个解决方案

#1


1  

You can create a contour plot using an R package called mvtnorm.

您可以使用名为mvtnorm的R包创建等高线图。

Let's say you're trying to plot a bivariate normal distribution where mu_x = 1 and mu_y = 1 and variance matrix is c(2,1,1,1). Generate 100 observations for x,y,z. You can create a contour plot for this scenario as such:

假设您正在尝试绘制双变量正态分布,其中mu_x = 1且mu_y = 1且方差矩阵为c(2,1,1,1)。为x,y,z生成100个观测值。您可以为此方案创建等高线图:

library(mvtnorm)
x.points <- seq(-3,3,length.out=100)
y.points <- x.points
z <- matrix(0,nrow=100,ncol=100)
mu <- c(1,1)
sigma <- matrix(c(2,1,1,1),nrow=2)
for (i in 1:100) {
   for (j in 1:100) {
    z[i,j] <- dmvnorm(c(x.points[i],y.points[j]),
    mean=mu,sigma=sigma)
   }
}
contour(x.points,y.points,z)

#1


1  

You can create a contour plot using an R package called mvtnorm.

您可以使用名为mvtnorm的R包创建等高线图。

Let's say you're trying to plot a bivariate normal distribution where mu_x = 1 and mu_y = 1 and variance matrix is c(2,1,1,1). Generate 100 observations for x,y,z. You can create a contour plot for this scenario as such:

假设您正在尝试绘制双变量正态分布,其中mu_x = 1且mu_y = 1且方差矩阵为c(2,1,1,1)。为x,y,z生成100个观测值。您可以为此方案创建等高线图:

library(mvtnorm)
x.points <- seq(-3,3,length.out=100)
y.points <- x.points
z <- matrix(0,nrow=100,ncol=100)
mu <- c(1,1)
sigma <- matrix(c(2,1,1,1),nrow=2)
for (i in 1:100) {
   for (j in 1:100) {
    z[i,j] <- dmvnorm(c(x.points[i],y.points[j]),
    mean=mu,sigma=sigma)
   }
}
contour(x.points,y.points,z)