[R] Need help to understand integrate function
R_help Help
rhelpacc at gmail.com
Thu Aug 12 03:43:02 CEST 2010
Hi,
I'm running into a wall when trying to use the integrate function. I
have the following setting:
powerLaw2 <- function(x,l1,l2,c0,t0) {
idx <- which(x <= 0);
if (length(idx) > 0) {
x[idx] <- 0;
}
xl <- (-l1+l2)*log(x/t0);
L <- log(c0)-l1*log(x)-log(1+exp(xl));
L <- exp(L);
return(L);
}
plCDF2 <- function(x,l1,l2,c0,t0) {
print(c(l1,l2,c0,t0));
cdf <- integrate(f=powerLaw2,lower=x,upper=Inf,l1=l1,l2=l2,c0=c0,t0=t0,stop.on.error=T);
return(cdf$value);
}
I know that as long as my l1 > 1 and l2 < 1 the integration above
should converge. However, this doesn't seem to be the case when I call
integrate function with the following parameter:
Browse[1]> integrate(f=powerLaw2,lower=1e-09,upper=Inf,l1=1.8980185,l2=-0.0804259,c0=1,t0=259.78,stop.on.error=T)
failed with message 'the integral is probably divergent'
Would you please shed some light? And how could I prevent this
situation? Thank you.
Rgds,
Rob
More information about the R-help
mailing list