richarddmorey / BayesFactor

BayesFactor R package for Bayesian data analysis with common statistical models.
https://richarddmorey.github.io/BayesFactor/
132 stars 49 forks source link

Infinite integral in regression when R^2 is very large #19

Closed richarddmorey closed 10 years ago

richarddmorey commented 10 years ago

The following code returns an error:

> n = 850
> R2 = 0.9338147
> p = 2
> linearReg.R2stat(N = n, p = p, R2 = R2, rscale = sqrt(2)/4)
Error in integrate(integrand.regression, lower = 0, upper = Inf, N = N,  : 
  non-finite function value

This is due to the integral value being so large. This can probably be fixed by evaluating the log of the integrand at the mode (see Liang et al appendix) and subtracting this from the integrand before exponentiating then adding the value back to the log of the result.