Dear R users,

I run into the following problem and hope someone can help me out. Thank you
in advance for your time.

I have a function defined recursively as follows:
recFun = function(k,x){ #i is less than 10. x can be any real number. I need
the value of recFun(k=1,2,3,4, x=0.12).
 if(k==1)
  integrand = function(z) (1 + pi*exp(z+0.9*x+0.012))^(-1.5) * dnorm(z)
 else
  integrand = function(z) (1 + pi*exp(z+0.9*x+0.012))^(-1.5) *
recFun(k-1,z+0.9*x+0.012) * dnorm(z)
 integrate(integrand, -Inf, Inf)
}

The goal of the function is to evaluate a quantity satisfying the recursive
relation that
$$I(1,x)=\int_{-\infty }^{\infty }\left( 1+\pi
e^{z+0.9x+0.012}\right)^{-1.5}\Phi (dz),$$ and
$$I(k,x)=\int_{-\infty }^{\infty }\left( 1+\pi e^{z+0.9x+0.012}\right)
^{-1.5} I(k-1,z+0.9x+0.012)\Phi (dz),$$
where $\Phi$ is the distribution function of the standard normal
distribution.

But for k>=2, a roundoff error occurs:
> recFun(2,0.12)
Error in integrate(integrand, -Inf, Inf) : roundoff error was detected

Can someone suggest a solution to this problem? Thanks a lot.

Best,
Zhongyi

	[[alternative HTML version deleted]]

