本文介绍了如何绘制 R 中二元正态分布的密度函数的动态和可旋转 3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
install.packages("scatterplot3d")
library(scatterplot3d)
library("mvtnorm")
x1 <- x2 <- seq(-10, 10, length = 51)
dens <- matrix(dmvnorm(expand.grid(x1, x2),
sigma = rbind(c(3, 2), c(2, 3))),
ncol = length(x1))
s3d <- scatterplot3d(x1, x2,
seq(min(dens), max(dens), length = length(x1)),
type = "n", grid = FALSE, angle = 70,
zlab = expression(f(x[1], x[2])),
xlab = expression(x[1]), ylab = expression(x[2]),
main = "Bivariate normal distribution")
text(s3d$xyz.convert(-1, 10, 0.07),
labels = expression(f(x) == frac(1, sqrt((2 * pi)^n *phantom(".") * det(Sigma[X]))) *
phantom(".") * exp * {bgroup("(", - scriptstyle(frac(1, 2) * phantom(".")) *
(x - mu)^T * Sigma[X]^-1 * (x - mu), ")")}))
text(s3d$xyz.convert(1.5, 10, 0.05),
labels = expression("with" * phantom("m") *mu == bgroup("(", atop(0, 0), ")") *
phantom(".") * "," *phantom(0) *
{Sigma[X] == bgroup("(", atop(3 * phantom(0) * 2,2 * phantom(0) * 3), ")")}))
for(i in length(x1):1)
s3d$points3d(rep(x1[i], length(x2)), x2, dens[i,], type = "l")
for(i in length(x2):1)
s3d$points3d(x1, rep(x2[i], length(x1)), dens[,i], type = "l")
如何为 R 中的二元正态分布绘制动态和可旋转的密度函数的 3D?谢谢
How to plot dynamic and rotatable 3D of the density function for the bivariate normal distribution in R? Thanks
如何在 http://personal.kenyon.edu/hartlaub 中绘制第二个情节/MellonProject/Bivariate2.html
推荐答案
library(emdbook)
library(rgl)
curve3d(dmvnorm(c(x,y),mu=c(0,0),Sigma=diag(2)),
sys3d="rgl",col="blue",
xlim=c(-3,3),ylim=c(-3,3))
如果你想要一个线框图,那么
If you want a wireframe plot then
curve3d(dmvnorm(c(x,y),mu=c(0,0),Sigma=diag(2)),
sys3d="rgl",front="line",back="line",
xlim=c(-3,3),ylim=c(-3,3))
应该可以(见?rgl.material
).
如果您想向该图中添加其他元素,请参阅(例如)?lines3d
、?points3d
(您需要自己计算坐标:ellipse
包可能对此有用).
If you want to add additional elements to this plot, see (for example) ?lines3d
, ?points3d
(you will need to compute the coordinates yourself: the ellipse
package may be useful for this).
这篇关于如何绘制 R 中二元正态分布的密度函数的动态和可旋转 3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!