[R] Problem with Integral of Indicator Function
Thomas Lumley
tlumley at u.washington.edu
Fri Jan 6 19:19:33 CET 2006
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 at 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 at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list