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 Also, is there any R function or package could do multivariate integration ? Thanks for any suggestions! Carrie [[alternative HTML version deleted]]
Your intuition is wrong and R is right. Why should the product of two probability density functions be a normalized pdf also? -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Carrie Li Sent: Saturday, 26 June 2010 1:28 PM To: r-help Subject: [R] integration of two normal density 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 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.
I sent you a "doubble integration" solution a couple of days ago, that answered your question. You did not have the coureteousy to acknowledge that. Now, you are asking a different question that is "incorrectly" formulated. What you are doing is not "multivariate" integration. You are just integrating a univariate function, which as Prof. Venables pointed out, is not even a density. Ravi. ____________________________________________________________________ Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvaradhan at jhmi.edu ----- Original Message ----- From: Carrie Li <carrieandstat at gmail.com> Date: Friday, June 25, 2010 11:29 pm Subject: [R] integration of two normal density To: r-help <R-help at r-project.org>> 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 > > > 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 > > PLEASE do read the posting guide > and provide commented, minimal, self-contained, reproducible code.
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-06You'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
Inline Below Bert Gunter Genentech Nonclinical Biostatistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Bill.Venables at csiro.au Sent: Friday, June 25, 2010 10:53 PM To: carrieandstat at gmail.com; R-help at r-project.org Subject: Re: [R] integration of two normal density Your intuition is wrong and R is right. Why should the product of two probability density functions be a normalized pdf also? -- as is trivially seen with two uniforms on [0,2], with pdf= 1/2, product 1/4 on [0,2] . -- Bert -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Carrie Li Sent: Saturday, 26 June 2010 1:28 PM To: r-help Subject: [R] integration of two normal density 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 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. ______________________________________________ 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.