# ForwardDiff on CDF for Beta distribution

**URL:** https://discourse.julialang.org/t/forwarddiff-on-cdf-for-beta-distribution/101110
**Category:** Statistics
**Created:** [July 3, 2023, 8:33am UTC](https://discourse.julialang.org/t/forwarddiff-on-cdf-for-beta-distribution/101110 "2023-07-03T08:33:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![matvil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matvil/32/15727_2.png) [@matvil](https://discourse.julialang.org/u/matvil)
#### Post date: [July 3, 2023, 8:33am UTC](https://discourse.julialang.org/t/forwarddiff-on-cdf-for-beta-distribution/101110/1 "2023-07-03T08:33:40Z")

</div>

I am trying to autodiff a function that depends on the CDF for a Beta distribution, but I get an error since this function depends on rmath, which only accepts Float64, not Reals, which I understand is required for Dual numbers to pass through the CDF function. This is all taken from the following open issue (since 2017): [Limited Support for ForwardDiff on CDFs · Issue #638 · JuliaStats/Distributions.jl · GitHub](https://github.com/JuliaStats/Distributions.jl/issues/638).

The CDF of a Beta is the regularized incomplete Beta function, so I really just need autodiff to work on this function. I found an old v0.0.1 package ([GitHub - jkovacic/IncGammaBeta.jl: A Julia package that computes incomplete gamma and beta functions and their inverses.](https://github.com/jkovacic/IncGammaBeta.jl)) but it downgrades too many packages for me.

Any advice, except implementing the incomplete beta myself? Thanks.

---

<div class="post-metadata">

### Author: ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)
#### Post date: [July 3, 2023, 9:31am UTC](https://discourse.julialang.org/t/forwarddiff-on-cdf-for-beta-distribution/101110/2 "2023-07-03T09:31:41Z")

</div>

I just added a comment to the issue you linked to [Limited Support for ForwardDiff on CDFs · Issue #638 · JuliaStats/Distributions.jl · GitHub](https://github.com/JuliaStats/Distributions.jl/issues/638#issuecomment-1617717270). Which derivative are you trying to compute? Wrt to one of the parameters or the “argument”?

---

<div class="post-metadata">

### Author: ![matvil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matvil/32/15727_2.png) [@matvil](https://discourse.julialang.org/u/matvil)
#### Post date: [July 3, 2023, 9:55am UTC](https://discourse.julialang.org/t/forwarddiff-on-cdf-for-beta-distribution/101110/3 "2023-07-03T09:55:26Z")

</div>

Thanks for the quick reply! I need the derivative wrt the parameter, not the argument. I interpret the reply of @devmotion to your comment on the github issue that this is now solved in ForwardDiff for the gamma distribution (gamma\_inc) but still not for the beta distribution (beta\_inc).

---

<div class="post-metadata">

### Author: ![matvil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matvil/32/15727_2.png) [@matvil](https://discourse.julialang.org/u/matvil)
#### Post date: [July 3, 2023, 1:44pm UTC](https://discourse.julialang.org/t/forwarddiff-on-cdf-for-beta-distribution/101110/4 "2023-07-03T13:44:04Z")

</div>

The incomplete beta function in the package IncGammaBeta.jl has the same issues:

```julia
using IncGammaBeta
using ForwardDiff: Dual
IncGammaBeta.inc_beta_lower_reg(1.2, 2.3, 0.45)
0.6913216388655349 # works with Float64
IncGammaBeta.inc_beta_lower_reg(1.2, 2.3, Dual(0.45,0)) # Errors with Dual numbers
julia> ERROR: MethodError: no method matching incBeta(::Float64, ::Float64, ::Dual{Nothing, Float64, …}, ::Bool, ::Bool)

```
