mvtnorm 包中的 mapply 命令中的命令
Command inside mapply command in mvtnorm package
当一些参数根据不同的函数同时改变值时,我想要一个具有不同双变量累积概率值的向量。我用 "mapply" 命令圆顶,在这种情况下:
library(mvtnorm)
m1<-c(1,2,3,4,5,5,5,5,5,5)
m2<-c(-1,-2,-3,-4,-5,-5,-5,-5,-5,-5)
m3<-c(0,0,0,0,0,1,2,3,4,5)
mapply(function(x,y,z)
pmvnorm(mean = c(18,12.72,(18*(x+y)+12.72*z)),sigma=matrix(c(5.7,0,5.7*(x+y),0,30.38,30.38*z,5.7*(x+y),30.38*z,5.7*(x+y)^2+30.38*(z)^2),3), lower=c(-Inf,-Inf,-Inf),upper=c(10,10,10)),
m1, m2, m3)
我的问题是我想插入命令
sigma[sigma == 0] <- 1e-20
用 sigma 矩阵中的小数字替换 0 值,以避免 0 或 NA 值。在这种情况下我应该在哪里插入这个命令?
非常感谢
可能有帮助
mapply(function(x,y,z) pmvnorm(mean = c(18, 12.72,
(18*(x+y) +12.72*z)),
sigma= {
s1 <- matrix(c(5.7,0,5.7*(x+y),0,30.38,30.38*z,5.7*(x+y),
30.38*z,5.7*(x+y)^2+30.38*(z)^2),3)
replace(s1,s1==0, 1e-20)
},
lower=c(-Inf,-Inf,-Inf),
upper=c(10,10,10)),
m1, m2, m3)
#[1] 1.252187e-04 1.252187e-04 1.252187e-04 1.252187e-04 1.252187e-04 1.252187e-04 3.249459e-05 1.783926e-05 1.283275e-05 1.043073e-05
当一些参数根据不同的函数同时改变值时,我想要一个具有不同双变量累积概率值的向量。我用 "mapply" 命令圆顶,在这种情况下:
library(mvtnorm)
m1<-c(1,2,3,4,5,5,5,5,5,5)
m2<-c(-1,-2,-3,-4,-5,-5,-5,-5,-5,-5)
m3<-c(0,0,0,0,0,1,2,3,4,5)
mapply(function(x,y,z)
pmvnorm(mean = c(18,12.72,(18*(x+y)+12.72*z)),sigma=matrix(c(5.7,0,5.7*(x+y),0,30.38,30.38*z,5.7*(x+y),30.38*z,5.7*(x+y)^2+30.38*(z)^2),3), lower=c(-Inf,-Inf,-Inf),upper=c(10,10,10)),
m1, m2, m3)
我的问题是我想插入命令
sigma[sigma == 0] <- 1e-20
用 sigma 矩阵中的小数字替换 0 值,以避免 0 或 NA 值。在这种情况下我应该在哪里插入这个命令?
非常感谢
可能有帮助
mapply(function(x,y,z) pmvnorm(mean = c(18, 12.72,
(18*(x+y) +12.72*z)),
sigma= {
s1 <- matrix(c(5.7,0,5.7*(x+y),0,30.38,30.38*z,5.7*(x+y),
30.38*z,5.7*(x+y)^2+30.38*(z)^2),3)
replace(s1,s1==0, 1e-20)
},
lower=c(-Inf,-Inf,-Inf),
upper=c(10,10,10)),
m1, m2, m3)
#[1] 1.252187e-04 1.252187e-04 1.252187e-04 1.252187e-04 1.252187e-04 1.252187e-04 3.249459e-05 1.783926e-05 1.283275e-05 1.043073e-05