- 42
- 0
- 约1.46千字
- 约 2页
- 2021-11-17 发布于浙江
- 举报
基于r软件的二维正态分布密度函数图的构建程序
# 基于R软件的二维正态分布密度函数图的构建程序
mu1-0 # setting the expected value of x1
mu2-0 # setting the expected value of x2
s11-10 # setting the variance of x1
s12-15 # setting the covariance between x1 and x2 s22-10 # setting the variance of x2
rho-0.5 # setting the correlation coefficient between x1 and x2 x1-seq(-10,10,length=41) # generating the vector series x1 x2-x1 # copying x1 to x2
#
f-function(x1,x2){
term1 - 1/(2*pi*sqrt(s11*s22*(1-rho^2)))
term2 - -1/(2*(1-rho^2))
term3 - (x1-mu1)^2/s11
term4 - (x2-mu2)^2/s22
term5 - -2*rho*((x1-mu1)*(x2-mu2))/(sqrt(s11)*sqrt(s22))
term1*exp(term2*(term3+term4-term5))
} # setting up the function of the multivariate normal density #
z-outer(x1,x2,f) # calculating the density values #
persp(x1, x2, z,
main=Two dimensional Normal Distribution,
sub=expression(italic(f)~(bold(x))==frac(1,2~pi~sqrt(sigma[11]~
sigma[22]~(1-rho^2)))~phantom(0)~exp~bgroup({,
list(-frac(1,2(1-rho^2)),
bgroup([, frac((x[1]~-~mu[1])^2, sigma[11])~-~2~rho~frac(x[1]~-~mu[1],
sqrt(sigma[11]))~ frac(x[2]~-~mu[2],sqrt(sigma[22]))~+~
frac((x[2]~-~mu[2])^2, sigma[22]),])),})),
col=lightgreen,
theta=45, phi=20,
r=50,
d=0.1,
expand=0.5,
ltheta=90, lphi=180,
shade=0.75,
ticktype=detailed,
nticks=5) # produces the 3-D plot
# adding a text line to the graph
mtext(expression(list(mu[1]==0,mu[2]==0,sigma[11]==10,sigma[22]==10,sigma[12]==15,rho==
0.5)), side=3)
您可能关注的文档
最近下载
- 博林特电梯MPK708C调试-故障说明手册.pdf VIP
- 《锅炉》课后习题答案-西安交大版.pdf VIP
- 唐山中浩化工有限公司利用锅炉余压发电技改项目环境影响报告书(简本).doc VIP
- 二年级(下)语文1-4单元一课一练含答案.docx
- Cultural!Learning!Alliance!! (联盟文化!学习! ! !).pdf VIP
- 人教版2024~2025学年七年级上册数学核心素养全册教案.doc VIP
- 项目经理部穿透式管理实施细则.doc VIP
- 2025自动化工程师岗试题及答案.doc VIP
- DLT2617-2023 20kV配电线路带电作业技术规范.pdf VIP
- 18黄伯荣、廖序东《现代汉语》增订6版课件_第5章 语法 第八、九、十节.pptx VIP
原创力文档

文档评论(0)