楼主: willing0909
3641 9

[求助]如何模拟三维正态图? [推广有奖]

  • 0关注
  • 1粉丝

已卖:504份资源

本科生

38%

还不是VIP/贵宾

-

威望
0
论坛币
28 个
通用积分
0.3241
学术水平
1 点
热心指数
0 点
信用等级
0 点
经验
1684 点
帖子
37
精华
0
在线时间
122 小时
注册时间
2008-1-4
最后登录
2022-4-5

楼主
willing0909 发表于 2009-3-13 12:14:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

老板布置任务,刚开始学习R,不太熟习,请教大家

先谢谢啦!!!!

现在,我用命令

library(MASS)

sigma<-matrix(c(1,0.5,0.5,1),2,2);

X<-mvrnorm(100,c(0,0),sigma);

产生了100个二维正态随机数,怎么产生它的三维图表示?

请大侠指点!!

[em12][em12]
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Library Sigma BRARY mass mas 求助 模拟 三维

回帖推荐

程娟 发表于5楼  查看完整内容

If you want to plot 3D. you can also use the function contour(),the details you can get form the help files.

vrooadk 发表于4楼  查看完整内容

that expression "exp(-(x^2-2*sigma*x*y+y^2)/2/(1-sigma^2))/2/pi/sqrt(1-sigma^2)" is the expression for bivariate-normal distribution density function. if you have no prior knowledge about the distribution of your data. there is not too much you can do. maybe use some non-parametric methods to estimate their potential distributions.

vrooadk 发表于2楼  查看完整内容

You need to calculate the density for each element of an array whose rows correspond to x values, and columns to y values. And then use persp to draw the 3d plot. Hope the following helps. library(MASS)sigma<-matrix(c(1,0.5,0.5,1),2,2);X<-mvrnorm(100,c(0,0),sigma);x<-seq(-3,3,by=.01)y<-xphi<-function(x,y) {sigma=cor(X)[1,2]exp(-(x^2-2*sigma*x*y+y^2)/2/(1-sigma^2))/2/pi/sqrt(1-sigma^2)} ...

本帖被以下文库推荐

沙发
vrooadk 发表于 2009-3-14 00:54:00
You need to calculate the density for each element of an array whose rows correspond to x values, and columns to y values. And then use persp to draw the 3d plot. Hope the following helps.

library(MASS)
sigma<-matrix(c(1,0.5,0.5,1),2,2);
X<-mvrnorm(100,c(0,0),sigma);


x<-seq(-3,3,by=.01)
y<-x
phi<-function(x,y)
{sigma=cor(X)[1,2]
exp(-(x^2-2*sigma*x*y+y^2)/2/(1-sigma^2))/2/pi/sqrt(1-sigma^2)
}
z <- outer(x, y, phi)
persp(x,y,z,theta=30,phi=30,col="lightblue",shade=.3,border=NA)
title(paste("bivariate normal distribution with cor=",round(cor(X)[1,2],3)))

藤椅
willing0909 发表于 2009-3-14 11:59:00

 


Thank you!


This sentence ‘exp(-(x^2-2*sigma*x*y+y^2)/2/(1-sigma^2))/2/pi/sqrt(1-sigma^2)’


is puzzling for me!


If we don't know these data is obtained from the normal distrbution,


we only have these data,how can I do?


I found a package 'rgl' which is used for 3D ,



#**********************alpha正态污染图*****************************
alpha=0.1;sigma=5;
fn=function(x,y){(1-alpha)/(2*pi)*exp(-(x^2+y^2)/2)+
alpha/(2*pi*sigma)*exp(-(x^2+y^2)/(2*sigma))  }


x<-seq(-2,2,len=17);y<-seq(-2,2,len=17);
z<-outer(x,y,fn);
color<-rainbow(41)[1+round(10*outer(x,y,fn))]  ;
library(rgl)         #rgl为专门画3D图的包
persp3d(x,y,z,color=color,smooth=FALSE)
surface3d(x,y,z+0.01,front="lines",back="culled")
#******************使图像自动旋转**********************************
M <- par3d("userMatrix")
play3d( par3dinterp( userMatrix=list(M,
                                     rotate3d(M, pi/2, 1, 0, 0),
                                     rotate3d(M, pi/2, 0, 1, 0) ) ),
        duration=4 )
movie3d( spin3d(), duration=5 )
#******************************************************************


Please check for me ,if you can draw a little time!


Thank you very much!


 


 

[此贴子已经被作者于2009-3-14 11:59:36编辑过]

已有 1 人评分学术水平 收起 理由
rmp + 1 很有用啊

总评分: 学术水平 + 1   查看全部评分

板凳
vrooadk 发表于 2009-3-20 22:26:00
that expression "exp(-(x^2-2*sigma*x*y+y^2)/2/(1-sigma^2))/2/pi/sqrt(1-sigma^2)" is the expression for bivariate-normal distribution density function.

if you have no prior knowledge about the distribution of your data. there is not too much you can do. maybe use some non-parametric methods to estimate their potential distributions.

报纸
程娟 发表于 2009-3-21 09:58:00
If you want to plot 3D. you can also use the function contour(),the details you can get form the help files.

地板
吉生保和马淑娟 发表于 2009-3-21 12:29:00

7
willing0909 发表于 2009-3-23 11:19:00

 

thank you very much!

he,I have found a package scatterplot3d

which can be used to plot 3 dim scatterplot.

 

 

[em01][em01][em01]

8
AVC 在职认证  发表于 2009-11-13 00:43:09
2# vrooadk

那如果有两个二维正态分布呢?要想把它们的分布图在一张图里画出来,可以么?谢谢~~~

9
kk22boy 发表于 2009-11-24 15:29:14
How to get rgl? I can not find it

10
rmp 发表于 2010-6-21 17:28:09
顶下,我正找3D的包

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-5 20:35