R函数pmvnorm : Why do values and errors differ every time I run this function with the same inputs?

标签 r distribution gaussian normal-distribution

根据我的理解,mvtnorm 库中的 pmvnorm 是一个计算多元正态分布上的 CDF 的函数。所以它是一个确定性函数。但是,我发现每次使用相同的输入运行此函数时,结果都会发生变化。这是一个小例子。

 library(mvtnorm)
 lower <- c( -Inf, -0.07,  0.81,  -Inf,  0.89,  -Inf,  1.33,  1.21,  -Inf)
 upper <- c( 1.00,  0.34,  0.98, -0.04,  1.07,  0.01,  1.48,  1.38,  0.09)

 sigma <- matrix(c(0.03, 0.00, -0.01, 0.00, 0.00, 0.00, 0.00, 0.00, 0.02,
                   0.00, 1.00,  0.66, 0.64, 0.64, 0.64, 0.64, 0.64, 0.64,
                  -0.01, 0.66,  0.99, 0.66, 0.64, 0.64, 0.64, 0.64, 0.64,
                   0.00, 0.64,  0.66, 1.00, 0.66, 0.64, 0.64, 0.64, 0.64,
                   0.00, 0.64,  0.64, 0.66, 1.00, 0.66, 0.64, 0.64, 0.64,
                   0.00, 0.64,  0.64, 0.64, 0.66, 1.00, 0.66, 0.64, 0.64,
                   0.00, 0.64,  0.64, 0.64, 0.64, 0.66, 1.00, 0.66, 0.64,
                   0.00, 0.64,  0.64, 0.64, 0.64, 0.64, 0.66, 1.00, 0.66,
                   0.02, 0.64,  0.64, 0.64, 0.64, 0.64, 0.64, 0.66, 1.00),
                   byrow=TRUE,length(lower))

 set.seed(1)
 (try1 <- pmvnorm(lower=lower,upper=upper,sigma=sigma))

这给了我值(value)观:

 [1] 4.42436e-09
 attr(,"error")
 [1] 4.312159e-13
 attr(,"msg")
 [1] "Normal Completion"

现在我用不同的种子重新评估该函数。

 set.seed(2)
 (try2 <- pmvnorm(lower=lower,upper=upper,sigma=sigma))

然后我得到:

 [1] 4.424396e-09
 attr(,"error")
 [1] 4.048187e-13
 attr(,"msg")
 [1] "Normal Completion"

还有

 try1 == try2 

给我:

 [1] FALSE

谁能解释一下为什么会发生这种情况?

最佳答案

查看 ?pmvnorm 中给出的第一个引用。例如http://www.math.wsu.edu/faculty/genz/papers/mvn.pdf 。简而言之,pmvnorm使用蒙特卡罗采样算法来计算多元正态分布的分布函数。

关于R函数pmvnorm : Why do values and errors differ every time I run this function with the same inputs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21823193/

相关文章:

r - 如何使用新(测试)数据重新创建相同的 DocumentTermMatrix

重新加载带有编译扩展的 R 包

R : replace elements in different columns after multiple comparisons

r - R 中的数据 ("dataset") 有什么用?

matlab - 在 MATLAB 中测试单峰(Unimodality)或双峰(Bimodality)分布

algorithm - 应该采取多少样本来捕获具有给定误差的原始集合的均值和方差?

r - 提取直方图 R 后面的数字

python - 使用python对二维散点图进行高斯求和

math - Gnuplot 中的高斯峰值不重叠

matlab - 使用经过训练的高斯混合模型标记新数据