Skip to content

Commit

Permalink
Fix fit docs (#1746)
Browse files Browse the repository at this point in the history
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
  • Loading branch information
3 people authored May 17, 2024
1 parent 818814f commit b09dcd7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/src/fit.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The function `fit_mle` is for maximum likelihood estimation.
### Synopsis

```@docs
fit(D, x)
fit(D, x, w)
fit_mle(D, x)
fit_mle(D, x, w)
```
Expand Down
13 changes: 13 additions & 0 deletions src/genericfit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ fit_mle(dt::Type{D}, x::AbstractArray, w::AbstractArray) where {D<:UnivariateDis
fit_mle(dt::Type{D}, x::AbstractMatrix) where {D<:MultivariateDistribution} = fit_mle(D, suffstats(D, x))
fit_mle(dt::Type{D}, x::AbstractMatrix, w::AbstractArray) where {D<:MultivariateDistribution} = fit_mle(D, suffstats(D, x, w))

"""
fit(D, args...)
Fit a distribution of type `D` to `args`.
The fit function will choose a reasonable way to fit the distribution, which,
in most cases, is maximum likelihood estimation. Note that this algorithm may
change; for a function that will behave consistently across versions, see
`fit_mle`.
By default, the fallback is [`fit_mle(D, args...)`](@ref); developers can change this default
for a specific distribution type `D <: Distribution` by defining a `fit(::Type{D}, args...)` method.
"""
fit(dt::Type{D}, x) where {D<:Distribution} = fit_mle(D, x)
fit(dt::Type{D}, args...) where {D<:Distribution} = fit_mle(D, args...)
11 changes: 2 additions & 9 deletions src/univariate/continuous/beta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,8 @@ function rand(rng::AbstractRNG, d::Beta{T}) where T
end
end

#### Fit model
"""
fit_mle(::Type{<:Beta}, x::AbstractArray{T})

Maximum Likelihood Estimate of `Beta` Distribution via Newton's Method
"""

function fit_mle(::Type{<:Beta}, x::AbstractArray{T};
maxiter::Int=1000, tol::Float64=1e-14) where T<:Real

Expand All @@ -240,11 +236,8 @@ function fit_mle(::Type{<:Beta}, x::AbstractArray{T};
return Beta(θ[1], θ[2])
end

"""
fit(::Type{<:Beta}, x::AbstractArray{T})

fit a `Beta` distribution
"""

function fit(::Type{<:Beta}, x::AbstractArray{T}) where T<:Real
x_bar = mean(x)
v_bar = varm(x, x_bar)
Expand Down

0 comments on commit b09dcd7

Please sign in to comment.