[R] problem with function involving ifelse and integrate
Faheem Mitha
faheem at email.unc.edu
Sat Apr 15 22:03:49 CEST 2000
Dear R people,
There is probably a simple explanation for the following, but I have been
unable to come up with one.
I want to integrate x(1-x)^{-1/3} over intervals of the form [0,a] where a
is between 0 and 1.
Hence, consider:
fm <- function(x) ifelse(x==0 | x==1 ,0,(x*(1-x))^(-1/3))
inbeta <- function(x)
{
ifelse(x==0,0,integrate(fm,0,x,maxpts = NULL, eps=0.01))
}
Comments:
integrate(fm,0,x,maxpts = NULL, eps=0.01) works ok for everything I tried
it for except x = 0 for some reason, hence the ifelse above.
The problem is with inbeta. Trying inbeta(x) for any value of x other than
0 gives the error "Error in rep(no, length = length(ans)) : Unimplemented
feature in rep" For 0, of course, it returns the value 0.
I can't see anything obviously wrong with this. Can someone help to figure
it out?
Also, I was wondering what method of numerical quadrature is used for
integrate. The documentation is silent about this. Also, the error
messages for
integrate(fm,0,0,maxpts = NULL, eps=0.01)
refers to something called lenwrk. What is this?
Sincerely, Faheem Mitha.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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