Reputation: 175
I would like a vector with the different values of cumulative probability of a bivariate when some parameters change value simultaneously according to different function. I've dome with "mapply" command as in this case:
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)
My problem is that I would like to insert the command
sigma[sigma == 0] <- 1e-20
to substitute 0 value with a small number in the sigma matrix, to avoid 0 or NA values. Where should I insert this command in this case?
Thank you very much
Upvotes: 1
Views: 65
Reputation: 887531
May be this helps
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
Upvotes: 1