简体   繁体   English

R在(x,y)点附近的3D正态分布图

[英]3D Plot of normal distribution in R around a (x,y) point

I want to plot a univariate normal density function of the normal distribution onto a (x,y,z) coordinate system. 我想在(x,y,z)坐标系上绘制正态分布的单变量正态密度函数。 The code I am using is: 我使用的代码是:

library(rgl)
open3d()

x <- seq(0, 10, length=100)
y <- seq(0, 10, length=100)


z = outer(x,y, function(x,y) dnorm(x,2.5,1)*dnorm(y,2.5,1))

persp3d(x, y, z,col = rainbow(100))

在此处输入图片说明

The problem I an encountering is that I want the normal distribution not to be around its mean only but also to be on a straight line or a circle. 我遇到的问题是我希望正态分布不仅在其均值周围,而且还希望在直线或圆上。 In latter case, I would expect the output to be similar to a volcano. 在后一种情况下,我希望输出类似于火山。 I guess I must first create some probabilities within a loop. 我想我必须首先在循环中创建一些概率。 How can I do this? 我怎样才能做到这一点? Or should I also use some surface command to plot the output? 还是我还应该使用一些Surface命令来绘制输出? I am pretty sure this has nothing to do with a bivariate normal though. 我很确定这与二元正态无关。

Best Fuji 最好的富士

The first part is easy: just don't let your z depend on y for instance: 第一部分很简单:例如,不要让z依赖y

z = outer(x,y, function(x,y) dnorm(x,2.5,1))
persp3d(x, y, z,col = rainbow(100))

For the second part, you can imagine that the means of the normal distribution lie on the x^2+y^2=1 circle. 对于第二部分,您可以想象正态分布的均值位于x^2+y^2=1圆上。 You will have infinite normal distributions with radial directions. 您将拥有无限的径向正态分布。 Try this: 尝试这个:

#define the volcano function
volcano<-function(x,y,sigma=1/2) {
  alpha<-atan(y/x)+pi*(x<0)
  d<-sqrt((cos(alpha)-x)^2 + (sin(alpha)-y)^2)
  dnorm(d,0,sigma)
}
x<-seq(-2,2,length.out=100)
y<-seq(-2,2,length.out=100)
z<-outer(x,y,volcano)
persp3d(x, y, z,col = rainbow(100))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在R?中绘制以y为点,x和z为向量的3d。 - Plot 3d with y as point, x and z as vectors in R? R 中的 3D 曲面图,给定 x,y,z 坐标 - 3D surface plot in R, given x,y,z coordinates R:将2D坐标与3D绘图中的线连接,并根据坐标添加正态分布pdf - R: Connect 2D coordinates with lines in 3D plot and add a normal distribution pdf based on the coordinates 如何在R中为二元正态分布绘制密度函数的动态和可旋转3D - How to plot dynamic and rotatable 3D of the density function for the bivariate normal distribution in R 在R中,如何绘制随时间变化的x,y值(3D或动画)? - In R, how can I plot x,y values over time (3D or animation)? 在 r 中具有 Plot_ly 的 3D 曲面,具有 x、y、z 坐标 - 3D Surface with Plot_ly in r, with x,y,z coordinates 3元组的3d图或轮廓图,其中x&y不在网格中,并且在R中不等距 - 3d plot or contourplot of 3-tuples where x&y are NOT in a grid and NOT equally spaced in R R,想要一个可旋转的3d图,给定一个列表x,y; z =每个提供的不同x,y的计数 - R, want a rotatable 3d plot, given a list x,y; z = count of each different supplied x,y 使用R或Matlab的双变量分布的3D图 - 3D plot of bivariate distribution using R or Matlab 如何通过 R 中的 plot_ly 返回沿 xy 坐标的 z 值矩阵以使 3D 表面 plot? - How to return matrix of z values along x-y coordinates to make 3D surface plot by plot_ly in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM