[R] help on integrate function

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jan 12 10:17:02 CET 2005


On Tue, 11 Jan 2005, Francisca xuan wrote:

> here is a function I wrote
>
> cdfest=function(t,lambda,delta,x,y){
>   a1=mean(x< t)
>   a2=mean(x< t-delta)
>   a3=mean(y1< t)
>  s=((1-lambda)*a1+lambda*a2-a3)^2
>  s
> }
>
> when I try to integrate over t, I got this message:
>
>> integrate(cdfest,0,4,lambda=0.3,delta=1,x=x,y=y1)
> Error in integrate(cdfest, 0, 4, lambda = 0.3, delta = 1, x = x, y = y1) :
>       evaluation of function gave a result of wrong length
>
> but the function is definitely in one dimension. what is wrong?

Please read the help page:

        f: an R function taking a numeric first argument and returning a
           numeric vector of the same length.  Returning a non-finite
           element will generate an error.

Your function does not do that: it returns a scalar for a vector input of 
length > 1, as the message clearly says.

> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list