Command inside mapply command in mvtnorm package

柔情痞子 提交于 2019-12-11 11:44:55

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/34861182/command-inside-mapply-command-in-mvtnorm-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!