Re: [R] Problem with Integral of Indicator Function

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Sat 07 Jan 2006 - 05:19:33 EST

On Fri, 6 Jan 2006, Cal Stats wrote:

> Hi..
>
> i was trying to integrate the indicator funtion but had problems
> when limits where negative or equal to the indicator condition
>
> my function is
> ________________________
> fun1<-function(x){
> as.numeric(x>=2)
> }
> _________________________
>
> which should be Ind(x>=2)*x

No. It should be Ind(x>=2), and it is. You appear to want

   function(x) (x>=2)*x

         -thomas

> seems to work for the following two cases
> ------------------------------------------------------------
> > integrate(fun1,3,5)
> 2 with absolute error < 2.2e-14
>
> > integrate(fun1,5,100)
> 95 with absolute error < 1.1e-12
> ----------------------------------------------------------
> Does not work for the following
>
> > integrate(fun1,0,2)
> 0 with absolute error < 0 ( i was expecting = 2)
>
> > integrate(fun1,-1,5)
> 3 with absolute error < 3.3e-14 (i was expecting =5)
>
> > integrate(fun1,-2,5)
> 3 with absolute error < 5.3e-15 (i was expecting =5)
>
> Any suggestions?
>
> Thanks.
>
> Harsh,
>
>
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley@u.washington.edu	University of Washington, Seattle

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jan 07 05:40:46 2006

This archive was generated by hypermail 2.1.8 : Sat 07 Jan 2006 - 14:07:35 EST