# [R] Why two curves and numerical integration look so different?

David Winsemius dwinsemius at comcast.net
Thu Feb 11 20:06:12 CET 2016

```> On Feb 11, 2016, at 9:20 AM, C W <tmrsg11 at gmail.com> wrote:
>
> I want to do numerical integration w.r.t. mu: P(mu) × N(mu, 0.00001)
>
> Because the variance is small, it results in density like: 7.978846e+94
>
> Is there any good suggestion for this?

So what's the difficulty? It's rather like the Dirac function.

> integrate( function(x) dnorm(x, sd=0.00001), -.0001,0.0001)
1 with absolute error < 7.4e-05

--
David.

>
> Thanks so much!
>
>
> On Thu, Feb 11, 2016 at 9:14 AM, C W <tmrsg11 at gmail.com> wrote:
>
>> Wow, thank you, that was very clear.  Let me give it some more runs and
>> investigate this.
>>
>> On Thu, Feb 11, 2016 at 12:31 AM, William Dunlap <wdunlap at tibco.com>
>> wrote:
>>
>>> Most of the mass of that distribution is within 3e-100 of 2.
>>> You have to be pretty lucky to have a point in sequence
>>> land there.  (You will get at most one point there because
>>> the difference between 2 and its nearest neightbors is on
>>> the order of 1e-16.)
>>>
>>> seq(-2,4,len=101), as used by default in curve, does include 2
>>> but seq(-3,4,len=101) and seq(-2,4,len=100) do not so
>>> curve(..., -3, 4, 101) and curve(..., -2, 4, 100) will not show the bump.
>>> The same principal holds for numerical integration.
>>>
>>>
>>> Bill Dunlap
>>> TIBCO Software
>>> wdunlap tibco.com
>>>
>>> On Wed, Feb 10, 2016 at 6:37 PM, C W <tmrsg11 at gmail.com> wrote:
>>>
>>>> Dear R,
>>>>
>>>> I am graphing the following normal density curve.  Why does it look so
>>>> different?
>>>>
>>>> # the curves
>>>> x <- seq(-2, 4, by=0.00001)
>>>> curve(dnorm(x, 2, 10^(-100)), -4, 4)  #right answer
>>>> curve(dnorm(x, 2, 10^(-100)), -3, 4)  #changed -4 to -3, I get wrong
>>>>
>>>> Why the second curve is flat?  I just changed it from -4 to -3.  There is
>>>> no density in that region.
>>>>
>>>>
>>>> Also, I am doing numerical integration.  Why are they so different?
>>>>
>>>>> x <- seq(-2, 4, by=0.00001)
>>>>> sum(x*dnorm(x, 2, 10^(-100)))*0.00001
>>>> [1] 7.978846e+94
>>>>> x <- seq(-1, 4, by=0.00001) #changed -2 to -1
>>>>> sum(x*dnorm(x, 2, 10^(-100)))*0.00001
>>>> [1] 0
>>>>
>>>> What is going here?  What a I doing wrong?
>>>>
>>>> Thanks so much!
>>>>
>>>>        [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>>
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

```