# [R] question with integrate function

li li hannah.hlx at gmail.com
Tue Feb 6 20:36:54 CET 2018

```Oh ok. Thanks very much. I will have to restrict to a shorter interval.
Hanna

2018-02-06 14:33 GMT-05:00 Göran Broström <goran.brostrom at umu.se>:

> Hi Hanna,
>
> your function is essentially zero outside a short interval around 9. And
> the help page states: "If the function is approximately constant (in
> particular, zero) over nearly all its range it is possible that the result
> and error estimate may be seriously wrong."
>
> You could try to integrate over a finite interval, say (7, 12).
>
> Göran Broström
>
>
> On 2018-02-06 19:40, li li wrote:
>
>> Sorry. I meant in the previous email that the function h() is a monotone
>> decreasing function. Thanks very much.
>>
>> 2018-02-06 13:32 GMT-05:00 li li <hannah.hlx at gmail.com>:
>>
>> Hi all,
>>>    The function h below is a function of c and it should be a monotone
>>> increasing function since the integrand is nonnegative and integral is
>>> taken from c to infinity. However, as we can see from the plot, it is not
>>> shown to be monotone. Something wrong with the usage of integrate
>>> function?
>>> Thanks so much for your help.
>>>      Hanna
>>>
>>>
>>>
>>> h <- function(c){
>>>      g <- function(x){pnorm(x-8.8, mean=0.4, sd=0.3,
>>> lower.tail=TRUE)*dnorm(x, mean=9,sd=0.15)}
>>>      integrate(g, lower=c, upper=Inf)\$value}
>>>
>>> xx <- seq(-20,20,by=0.001)
>>> y <- xx
>>> for (i in 1:length(xx)){y[i] <- h(xx[i])}
>>> plot(xx, y)
>>>
>>>
>>>
>>         [[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