# Re: [R] Integration with 'adapt'

From: Rodrigo Drummond <rduarte_at_unicamp.br>
Date: Thu 29 Jul 2004 - 03:50:23 EST

Thank you for your answer to my question. Here is a reproducible example of the problem:

> A<-2
> B<--1
> C<-1
> linf<-c(-10,-1,0.0003)
> lsup<-c(10,1,0.0004)
> Integrand1<-function(v)

{exp(-1*(A*v[1]^2-B*v[1]+C+(((v[1]-v[2])^2)/(2*v[3]^2))))/(K*v[3])}
Warning message:
Ifail=2, lenwrk was too small. -- fix adapt() !  Check the returned relerr! in: adapt(3, linf, lsup, functn = Integrand1)

The problem is related to the small range of the third variable, (0.0003-0.0004), so I tried the change of variables z2<-z/(max(z)-min(z)):

> rang=0.0004-0.0003
> linf[3]<-linf[3]/rang
> lsup[3]<-lsup[3]/rang
> Integrand1<-function(v)

{exp(-1*(A*v[1]^2-B*v[1]+C+(((v[1]-v[2])^2)/(2*(rang^2)*(v[3]^2)))))/(K*v[3])}
> #With the change of variables, the constant "rang" appears in the function.
Warning message:
Ifail=2, lenwrk was too small. -- fix adapt() !  Check the returned relerr! in: adapt(3, linf, lsup, functn = Integrand1)

And the problem persists, probably because of the small value of "rang", what can be checked below:

> rang<-.01
> Integrand1<-function(v)

{exp(-1*(A*v[1]^2-B*v[1]+C+(((v[1]-v[2])^2)/(2*(rang^2)*(v[3]^2)))))/(K*v[3])}
> #The same function as before, with a bigger value for "rang"
> Const

[1] 8.766637e-05

How can I evaluate the integral, even with small values of rang? Thanks a lot for your help.
Best regards.
Rodrigo Drummond

>>>>>> "Rodrigo" == Rodrigo Drummond <rduarte@unicamp.br>
>>>>>> on Tue, 27 Jul 2004 15:31:07 -0300 (BRT) writes:
>
> Rodrigo> Hi all, I need to calculate a multidimensional
> Rodrigo> integration on R. I am using the command
>
> it's a "package", not a library.
>
> Rodrigo> sometimes I get the following error message:
>
> Rodrigo> Ifail=2, lenwrk was too small. -- fix adapt() !
> Rodrigo> Check the returned relerr! in: adapt(3, linf, lsup,
> Rodrigo> functn = Integrando1)
>
> If you could give as a *reproducible* example,
>
> we (the adapt authors) would have chance to do what the above
> message says, namely "fix adapt()" ..
>
>
> Rodrigo> I guess it happens because the domain of
> Rodrigo> integration is too small,
>
> maybe, maybe not. We need an example we can reproduce, see above.
>
> Rodrigo> although I tried a change of variables to avoid
> Rodrigo> this problem and it didn’t help. The command adapt
> Rodrigo> calls a fortran routine, but I don’t know fortran
> Rodrigo> enough to fix the problem.
>
> Martin Maechler, ETH Zurich
>

Rodrigo D. Drummond
Laboratorio Genoma Funcional