Hello,

You could do something like the following.


fun <- function(x, mean, sd1, sd2, p)
        dnorm(x, mean, sd1)*p + dnorm(x, mean, sd2)*(1 - p)

fun2 <- function(x1, x2, mean, sd1, sd2, p){
        p1 <- pnorm(x2, mean, sd1) - pnorm(x1, mean, sd1)
        p2 <- pnorm(x2, mean, sd2) - pnorm(x1, mean, sd2)
        p1*p + p2*(1 - p)
}

integrate(fun, 0, 1, mean = 0, sd1 = 1, sd2 = 2, p = 0.5)
fun2(0, 1, mean = 0, sd1 = 1, sd2 = 2, p = 0.5)


Hope this helps,

Rui Barradas


Em 30-01-2013 09:19, Johannes Radinger escreveu:
Hi,

I already found a conversation on the integration of a normal
distribution and two
suggested solutions
(https://stat.ethz.ch/pipermail/r-help/2007-January/124008.html):

1) integrate(dnorm, 0,1, mean = 0, sd = 1.2)

and

2) pnorm(1, mean = 0, sd = 1.2) - pnorm(0, mean = 0, sd = 1.2)

where the pnorm-approach is supposed to be faster and with higher precision.

I want to integrate a mixed normal distribution like:
normaldistr_1 * p + normaldistr_2 * (1-p)

where p is between 0 and 1 and the means for both distributions are 0
but the standard deviations differ.

In addition, I want to get the integrals from x to infinity or from -
infinity to x for
the mixed distribution.

Can that be done with high precision in R and if yes how?

best regards,

Johannes

______________________________________________
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.


______________________________________________
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