Gamma function should not take any negative value as an argument. Look at the code below where strange thing happens. Is this some problem with R?
I was using function optim
to optimize some function containing:
gamma(sum(alpha))
with respect to alpha
. R returns negative alpha
.
> gamma(sum(alpha))
[1] 3.753+14
>sum(alpha)
[1] -3
gamma(-3)
[1] NaN
Warning message:
In gamma(-3) NaN's produced.
Can somebody explain? Or any suggestion for the optimization?
Thanks!
sum(alpha)
is not-3
just do simplysum(alpha)==-3
it will give you false. Sincesum(alpha)
is technically close to -3 but is not -3,identical(sum(alpha),-3)
– Onyambu?gamma
help page. – IRTFMThe gamma function is defined by (Abramowitz and Stegun section 6.1.1, page 255) Γ(x) = integral_0^Inf t^(x-1) exp(-t) dt for all real x except zero and negative integers (when NaN is returned).
– Surensum(alpha)
is near-3L-0.0000000000000004
– IRTFM