But if you use a smaller sdlog value then integrate does get it wrong because it does not find the delta-like function hidden somewhere between 0 and infinity. > integrate(function(x){dlnorm(x,meanlog=-0.3,sdlog=0.00041)},0,Inf) 0 with absolute error < 0 > integrate(function(x){dlnorm(x,meanlog=-0.3,sdlog=0.00041)},0,1) 0 with absolute error < 0 Tell it where the bulk of the mass is and it works > integrate(function(x)dlnorm(x,-0.3,0.00041), 0.738, 0.743, subdivisions=10^3) 1 with absolute error < 4.4e-05
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Rolf Turner > Sent: Wednesday, November 21, 2012 12:57 PM > To: Rehena Sultana > Cc: r-help@r-project.org > Subject: Re: [R] Integration in R > > On 21/11/12 22:26, Rehena Sultana wrote: > > Dear R - Experts, > > > > I am trying to integrate lognormal distribution (mu = -0.3 and sigma2 = > > 0.00041.. ) > based on the some hypothetical data. But I am getting 0 as the result. I have > checked > that my R-code is correct as code is giving me result for some other data. > > > > As I understand, when I am integrating some pdf with in the range of (0, > > Inf), I should > not get 0. How to handle this kind of problem? > > > > Please help. Looking forward for your reply. > > Reproducible example? > > When I do > > integrate(function(x){dlnorm(x,meanlog=-0.3,sdlog=sqrt(0.00041))},0,Inf) > > I get > > 1 with absolute error < 3.5e-06 > > No problema. > > Why do you want to integrate it anyhow? You know the answer is 1. > > Or if you want the integral from 0 to x for some x < infinity, just use > plnorm(). (???) > > cheers, > > Rolf Turner > > ______________________________________________ > 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.