R中的双变量(mvtnorm软件包) [英] Bivariate in R (mvtnorm package)

查看:847
本文介绍了R中的双变量(mvtnorm软件包)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个彼此独立的普通r.v.(因此相关性$ \ rho = 0 $).这两个r.v.来自以下两个正态分布,即$ X \ sim N(18,5.7)$和$ Y \ sim N(12.72,30.38)$.

I have two normal r.v.'s that are independent of each other (so the correlation $\rho= 0$). The two r.v.'s come from the following two Normal distributions, i.e., $X\sim N(18, 5.7)$ and $Y\sim N(12.72, 30.38)$.

我想计算$ Pr(X> 10,Y< 10)$.当然,由于它们是独立的,因此我可以计算边际密度的乘积,其结果应为$ Pr(X> 10,Y< 10)= Pr(X> 10)\乘以Pr(Y< 10)= 0.3106美元.

I want to calculate $Pr(X>10, Y<10)$. Of course, as they are independent, I can calculate the product of the marginal density and the result should be $Pr(X>10, Y<10) = Pr(X>10)\times Pr(Y<10)=0.3106$.

但是,我开始学习如何在R中使用mvtnorm软件包,并且根据本文

However, I'm starting to learn how to use the mvtnorm package in R and,according to this article https://cran.r-project.org/web/packages/mvtnorm/vignettes/MVT_Rnews.pdf, this is how you should solve the problem:

> library(mvtnorm)
> m<-2
> corr<-diag(2)
> corr[2,1]<-0
> pmvnorm(mean=c(18,12.72),corr,lower=c(10,-Inf), upper=c(+Inf,10))

但结果是:0.003264096

but the result is: 0.003264096

我的逻辑错误在哪里?

推荐答案

您忘记了包含随机变量的方差.无需指定相关矩阵,只需指定协方差矩阵即可.这是R的代码:

You were forgetting to include the variance of your random variables. Instead of specifying the correlation matrix, just specify the covariance matrix. Here is the R code to do it:

library(mvtnorm)

   mu = c(18,12.72)
   covariance = diag(c(5.7,30.38),2)
   X = c(10,-Inf)
   Y = c(Inf,10)

   pmvnorm(mean=mu,sigma=covariance,lower=X,upper=Y)

这篇关于R中的双变量(mvtnorm软件包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆