question with integrate function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

question with integrate function

li li-13
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]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: question with integrate function

li li-13
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 <[hidden email]>:

> 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]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: question with integrate function

Göran Broström-3
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 <[hidden email]>:
>
>> 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]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: question with integrate function

li li-13
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 <[hidden email]>:

> 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 <[hidden email]>:
>>
>> 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]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.