title: "non-finite function value" when using integrate() in R
body: <p>I am using the following R code, taken from a published paper (citation below).  This is the code:</p>
  
  <pre><code>int2=function(x,r,n,p) {
      (1+x)^((n-1-p)/2)*(1+(1-r^2)*x)^(-(n-1)/2)*x^(-3/2)*exp(-n/(2*x))}
  integrate(f=int2,lower=0,upper=Inf,n=530,r=sqrt(.245),p=3, stop.on.error=FALSE)
  </code></pre>
  
  <p>When I run it, I get the error "non-finite function value". Yet Maple is able to compute this as 4.046018765*10^27.</p>
  
  <p>I tried using "integral" in package pracma, which gives me a different error:
  Error in if (delta &lt; tol) break : missing value where TRUE/FALSE needed</p>
  
  <p>The overall goal is to compute a ratio of two integrals, as described in Wetzels &amp; Wagenmakers (2012) "A default Bayesian hypothesis test for correlations" (<a href="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3505519/" rel="nofollow">http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3505519/</a>).  The entire function is as follows:</p>
  
  <pre><code>jzs.pcorbf = function(r0, r1, p0, p1, n) {
    int = function(r,n,p,g) {
      (1+g)^((n-1-p)/2)*(1+(1-r^2)*g)^(-(n-1)/2)*g^(-3/2)*exp(-n/(2*g))};
    bf10=integrate(int, lower=0,upper=Inf,r=r1,p=p1,n=n)$value/
         integrate(int,lower=0,upper=Inf,r=r0,p=p0,n=n)$value;
    return(bf10)
  }
  </code></pre>
  
  <p>Thanks!</p>