Re: [R] integration of two normal density

From: Matt Shotwell <shotwelm_at_musc.edu>
Date: Sat, 26 Jun 2010 09:54:11 -0400

On Fri, 2010-06-25 at 23:28 -0400, Carrie Li wrote:
> Hello everyone,
>
> I have a question about integration of two density function
> Intuitively, I think the value after integration should be 1, but they are
> not. Am I missing something here ?
>
> > t=function(y){dnorm(y, mean=3)*dnorm(y/2, mean=1.5)}
> > integrate(t, -Inf, Inf)

> 0.3568248 with absolute error < 4.9e-06

You've demonstrated (numerically) that the product of two normal density functions, with means 3, and 1.5 respectively and variance 1, doesn't result in a pdf. However, you could make a numerically normalized pdf by multiplying by 1/0.3568248.

> K <- integrate(t, -Inf, Inf)$value
> Kt <- function(y) 1/K * dnorm(y, 3) * dnorm(y/2, 1.5)
> integrate(Kt, -Inf, Inf)

1 with absolute error < 1.4e-05

Hence, the quantity you computed (K) is the normalization constant, with some small error. Note that this strategy _may_ not always work. Here's a good homework question: Can the product of two pdfs with identical support always be normalized to form a new pdf?

As for empirical multivariate integration, it's tough, especially if you want to enumerate the "area under the surface", which is exactly the strategy of functions like 'integrate' (search Wikipedia for numerical integration). This problem becomes increasingly difficult in additional dimensions; the dreaded "curse of dimensionality". On the bright side, Bayesian statistical methods have to deal with this all the time, and we have some good methods to compute numerical integrals. Check out Monte Carlo integration, and Markov chain Monte Carlo methods.

-Matt

>
>
> Also, is there any R function or package could do multivariate integration ?
>
> Thanks for any suggestions!
>
> Carrie
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_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.

-- 
Matthew S. Shotwell
Graduate Student
Division of Biostatistics and Epidemiology
Medical University of South Carolina
http://biostatmatt.com

______________________________________________
R-help_at_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.
Received on Sat 26 Jun 2010 - 13:57:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Jun 2010 - 14:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive