Skip to content

Commit

Permalink
Implement fit_mle for pareto distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff committed Aug 20, 2015
1 parent 62df2e8 commit 1b4f4cb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/fit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The ``fit_mle`` method has been implemented for the following distributions:
- :ref:`gamma`
- :ref:`geometric`
- :ref:`laplace`
- :ref:`pareto`
- :ref:`poisson`
- :ref:`uniform`

Expand Down
20 changes: 20 additions & 0 deletions src/univariate/continuous/pareto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,23 @@ quantile(d::Pareto, p::Float64) = cquantile(d, 1.0 - p)
#### Sampling

rand(d::Pareto) = d.θ * exp(randexp() / d.α)


## Fitting

function fit_mle{T <: Real}(::Type{Pareto}, x::AbstractArray{T})
# Based on
# https://en.wikipedia.org/wiki/Pareto_distribution#Parameter_estimation

θ = minimum(x)

n = length(x)
= log(θ)
temp1 = zero(T)
for i=1:n
temp1 += log(x[i]) -
end
α = n/temp1

return Pareto(α, θ)
end
8 changes: 8 additions & 0 deletions test/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ d = fit(Laplace, rand(Laplace(5.0, 3.0), N))
@test_approx_eq_eps location(d) 5.0 0.1
@test_approx_eq_eps scale(d) 3.0 0.2

# Pareto

x = rand(Pareto(3., 7.), n0)
d = fit(Pareto, x)

@test isa(d, Pareto)
@test_approx_eq_eps shape(d) 3. 0.1
@test_approx_eq_eps scale(d) 7. 0.1

# Poisson

Expand Down

0 comments on commit 1b4f4cb

Please sign in to comment.