[R] BesselI(.) {was "Existence of non-vectorised functions"}

Martin Maechler maechler at stat.math.ethz.ch
Wed Nov 27 09:08:18 CET 2002


>>>>> "Ravi" == Ravi Varadhan <rvaradha at jhsph.edu>
>>>>>     on Tue, 26 Nov 2002 11:17:45 -0500 writes:

    Ravi> Dear R-Group: Recently, I ran into a problem.  I was
    Ravi> using a function called "I.1", which evaluates the
    Ravi> first-order modified Bessel function of the first
    Ravi> kind, in the package "CircStats". This function is not
    Ravi> vectorized, since it uses a couple of "if" conditions....

    Ravi> <...........>

If you use  library(help = "CircStats")
(something you should do for any package when you find problems!)
you see that it has been ported from S (probably S-plus).

In R, the Bessel functions have been available for long time,
in fast and vectorized form  --- although for "numeric" (i.e
non-complex) arguments only, and help(bessel) {e.g.} gives you

     besselI(x, nu, expon.scaled = FALSE)
     besselK(x, nu, expon.scaled = FALSE)
     besselJ(x, nu)
     besselY(x, nu)

i.e. I.0(x) = besselI(x,0) \
     I.1(x) = besselI(x,1)  > when x is numeric
     I.p(x) = besselI(x,p) /

Only if you are interested in the non-numeric complex case,
you (and even more the maintainer of CircStats) should
investigate improving I.1 (and I.p) to work vectorized and you
are right,  ifelse() might a good way to do so.

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list