fl=function(q,a=-23.0344,b=10.0249) (b/q)*dnorm((a+b*log(q)),0,1)
Fl=function(h) integrate(fl,lower=0,upper=h)$value
Fz=function(z){
integrand=function(x){
Fl((x-z)*10)*fl(10*x)
}
1-10*integrate(integrand,0,Inf)$value
}
library(GoFKernel)
inv=inverse(Fz,lower=-100000,upper=100000)
why do i get this error? "Error in integrate(fl, lower = 0, upper = h) : 'upper' must be of length one"
how can i solve it?
As suggested in the comments, when you run
integrate(), it tries to evaluate the integrand for a vector of values.I tried vectorizing the
Flfunction (there are a variety of ways of doing this:Vectorize,Map,purrr::map,vapply(), ... but I used a good old-fashionedforloop)Once this is fixed we hit.
We also get a warning that
log(q)is being called for negative values ofq, which will produce anNaNwhich will mess everything up downstream.We can set
options(error = browser), but I had trouble with that. Instead, I set up a checkpoint if negative values ofqare used (which will inevitably lead to trouble):When I get thrown in the browser I try:
So you'll have to think about what you're doing (TBH I haven't tried to figure out the logic of your code) and whether you're inadvertently evaluating expressions over negative ranges when they're not allowed.