Dear R-users,

i have to integrate the following function

`fun1` <- function (a, l1, l2)
{
 exp(log(l1) * (a - 1) - l2 * lgamma(a))
}

but if l1 is large, i get the "non-finite function value" error, so my idea is to rescale with exp(-l1)

`fun2` <- function (a, l1, l2)
{
 exp(log(l1) * (a - 1) - l2 * lgamma(a) - l1)
}

but it seems this doesn't solve the problem, when l1=1.0e80. maybe i have to iterate between large values in integrate and large values in exp(l1) and then use the normal or the rescaled version?


> l1<-10; l2<-10;
> integrate(Vectorize(function(a) {fun1(a, l1=l1, l2=l2)}), 1, Inf)$val
[1] 11.65311
> integrate(Vectorize(function(a) {fun2(a, l1=l1, l2=l2)}), 1, Inf)$val * exp(l1)
[1] 11.65312
>
> l1<-1.0e12; l2=50;
> integrate(Vectorize(function(a) {fun1(a, l1=l1, l2=l2)}), 1, Inf)$val
[1] 929558588152
> integrate(Vectorize(function(a) {fun2(a, l1=l1, l2=l2)}), 1, Inf)$val * exp(l1)
[1] NaN
>
> l1<-1.0e20; l2=50;
> integrate(Vectorize(function(a) {fun1(a, l1=l1, l2=l2)}), 1, Inf)$val
[1] 5.005192e+24
> integrate(Vectorize(function(a) {fun2(a, l1=l1, l2=l2)}), 1, Inf)$val * exp(l1)
[1] NaN
>
> l1<-1.0e80; l2=50;
> integrate(Vectorize(function(a) {fun1(a, l1=l1, l2=l2)}), 1, Inf)$val
Fehler in integrate(Vectorize(function(a) { : non-finite function value
> integrate(Vectorize(function(a) {fun2(a, l1=l1, l2=l2)}), 1, Inf)$val * exp(l1)
[1] NaN


Many thanks if you have any advice for me!

best regards

Andreas

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to