Skip to content

Commit b09dcd7

Browse files
Carlos ParadadevmotionViralBShah
authored
Fix fit docs (#1746)
Co-authored-by: David Widmann <[email protected]> Co-authored-by: Viral B. Shah <[email protected]>
1 parent 818814f commit b09dcd7

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

docs/src/fit.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The function `fit_mle` is for maximum likelihood estimation.
2727
### Synopsis
2828

2929
```@docs
30+
fit(D, x)
31+
fit(D, x, w)
3032
fit_mle(D, x)
3133
fit_mle(D, x, w)
3234
```

src/genericfit.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,18 @@ fit_mle(dt::Type{D}, x::AbstractArray, w::AbstractArray) where {D<:UnivariateDis
3030
fit_mle(dt::Type{D}, x::AbstractMatrix) where {D<:MultivariateDistribution} = fit_mle(D, suffstats(D, x))
3131
fit_mle(dt::Type{D}, x::AbstractMatrix, w::AbstractArray) where {D<:MultivariateDistribution} = fit_mle(D, suffstats(D, x, w))
3232

33+
"""
34+
fit(D, args...)
35+
36+
Fit a distribution of type `D` to `args`.
37+
38+
The fit function will choose a reasonable way to fit the distribution, which,
39+
in most cases, is maximum likelihood estimation. Note that this algorithm may
40+
change; for a function that will behave consistently across versions, see
41+
`fit_mle`.
42+
43+
By default, the fallback is [`fit_mle(D, args...)`](@ref); developers can change this default
44+
for a specific distribution type `D <: Distribution` by defining a `fit(::Type{D}, args...)` method.
45+
"""
3346
fit(dt::Type{D}, x) where {D<:Distribution} = fit_mle(D, x)
3447
fit(dt::Type{D}, args...) where {D<:Distribution} = fit_mle(D, args...)

src/univariate/continuous/beta.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,8 @@ function rand(rng::AbstractRNG, d::Beta{T}) where T
208208
end
209209
end
210210

211-
#### Fit model
212-
"""
213-
fit_mle(::Type{<:Beta}, x::AbstractArray{T})
214211

215-
Maximum Likelihood Estimate of `Beta` Distribution via Newton's Method
216-
"""
212+
217213
function fit_mle(::Type{<:Beta}, x::AbstractArray{T};
218214
maxiter::Int=1000, tol::Float64=1e-14) where T<:Real
219215

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

243-
"""
244-
fit(::Type{<:Beta}, x::AbstractArray{T})
245239

246-
fit a `Beta` distribution
247-
"""
240+
248241
function fit(::Type{<:Beta}, x::AbstractArray{T}) where T<:Real
249242
x_bar = mean(x)
250243
v_bar = varm(x, x_bar)

0 commit comments

Comments
 (0)