Hi all,

I tried below two methods to calculate the integrate of a same function.
Two different results are given.
The first one should be the right answer.
Can any one help to explain why?
Another issue is, the first one is not convenient as I have to update the
mu and sigma outside the function. How can I modify the second one so I
could issue the parameters in the integrate function.
Thanks in advance,

Dan

test <- function(s){
       prod(1-pnorm(s,mu[-1],sigma[-1]))*dnorm(s,mu[1],sigma[1])

}
testV <- Vectorize(test)
mu=c(0,0,0,0)
sigma=c(1,1,1,1)
integrate(testV,lower=-Inf,upper=Inf)$value


test2 <- function(s, mu, sigma){
       prod(1-pnorm(s,mu[-1],sigma[-1]))*dnorm(s,mu[1],sigma[1])

}
integrate(test2,mu=c(0,0,0,0),sigma=c(1,1,1,1),lower=-Inf,upper=Inf)$value

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to