From 31c95d394c5f593d23ce18c2b4a4999aa9e9ffd0 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Fri, 3 Nov 2023 11:16:08 +0000 Subject: [PATCH] build based on 91cbb95 --- dev/.documenter-siteinfo.json | 2 +- dev/api/index.html | 4 +- dev/gamma/index.html | 2 +- dev/index.html | 8 +-- .../{f2283b31.svg => cb64cade.svg} | 72 +++++++++---------- dev/logitnormal/index.html | 4 +- dev/lognormal/index.html | 8 +-- dev/partype/index.html | 6 +- dev/search_index.js | 2 +- dev/set_optimize/index.html | 2 +- dev/weibull/index.html | 2 +- dev/z_autodocs/index.html | 8 +-- 12 files changed, 60 insertions(+), 60 deletions(-) rename dev/logitnormal/{f2283b31.svg => cb64cade.svg} (86%) diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 551394e..5084a66 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-11-01T08:28:18","documenter_version":"1.1.2"}} \ No newline at end of file +{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-11-03T11:16:02","documenter_version":"1.1.2"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html index 0f22d92..93495af 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -1,5 +1,5 @@ API · DistributionFits.jl

API

AbstractMoments

The concept of first and higher order moments is captured by its own type. This allows dispatching the fit method.

DistributionFits.AbstractMomentsType
AbstractMoments{N}

A representation of statistical moments of a distribution

The following functions are supported

  • n_moments(m): get the number of recorded moments

The following getters return a single moment or throw an error if the moment has not been recorded (>N)

  • mean(m): get the first momemnt, i.e. the mean
  • var(m): get the second moment, i.e. the variance
  • skewness(m): get the third moment, i.e. the skewness
  • kurtosis(m): get the fourth moment, i.e. the kurtosis
  • getindex(m,i): get the ith moment, i.e. indexing m[i]

The basic implementation Moments is immutable and convert(AbstractArray, m::Moments) returns an SArray{N,T}.

Examples

m = Moments(1,0.2);
 n_moments(m) == 2
-var(m) == m[2]
kurtosis(m) # throws error because its above 2nd moment
source
DistributionFits.momentsFunction
moments(D, ::Val{N} = Val(2))

Get the first N moments of a distribution.

Procudes an object of type AbstractMoments.

Examples

moments(LogNormal(), Val(4))  # first four moments 
-moments(Normal())  # mean and variance
source

QuantilePoint

The concept of a pair (p,q), i.e. a probability in [0,1] and associated quantile is captured by its own type. This allows dispatching the fit method.

DistributionFits.QuantilePointType
QuantilePoint

A representation of a pair (p,q), i.e. (percentile,quantile).

Notes

Several macros help to construct QuantilePoints

  • @qp(q,p) quantile at specified p: QuantilePoint(q,p)

For Float64-based percentiles there are shortcuts

  • @qp_ll(q0_025) quantile at very low p: QuantilePoint(q0_025,0.025)
  • @qp_l(q0_05) quantile at low p: QuantilePoint(q0_05,0.05)
  • @qp_m(median) quantile at median: QuantilePoint(median,0.5)
  • @qp_u(q0_95) quantile at high p: QuantilePoint(q0_95,0.95)
  • @qp_uu(q0_975) quantile at very high p: QuantilePoint(q0_975,0.975)

For constructing QuantilePoints with type of percentiles other than Float64, use the corresponding functions, that create a percentiles of the type of given quantile. E.g. for a Float32-based QuantilePoint at very low percentile

  • qp_ll(0.2f0) constructs a QuantilePoint(0.2f0,0.025f0)

There are macros/functions for some commonly used sets of QuantilePoints: 90% and 95% confidence intervals:

  • @qs_cf90(q0_05,q0_95)
  • @qs_cf95(q0_025,q0_975) -> Set([QuantilePoint(q0_025,0.025),QuantilePoint(q0_975,0.975)]))
source
+var(m) == m[2]
kurtosis(m) # throws error because its above 2nd moment
source
DistributionFits.momentsFunction
moments(D, ::Val{N} = Val(2))

Get the first N moments of a distribution.

Produces an object of type AbstractMoments.

Examples

moments(LogNormal(), Val(4))  # first four moments 
+moments(Normal())  # mean and variance
source

QuantilePoint

The concept of a pair (p,q), i.e. a probability in [0,1] and associated quantile is captured by its own type. This allows dispatching the fit method.

DistributionFits.QuantilePointType
QuantilePoint

A representation of a pair (p,q), i.e. (percentile,quantile).

Notes

Several macros help to construct QuantilePoints

  • @qp(q,p) quantile at specified p: QuantilePoint(q,p)

For Float64-based percentiles there are shortcuts

  • @qp_ll(q0_025) quantile at very low p: QuantilePoint(q0_025,0.025)
  • @qp_l(q0_05) quantile at low p: QuantilePoint(q0_05,0.05)
  • @qp_m(median) quantile at median: QuantilePoint(median,0.5)
  • @qp_u(q0_95) quantile at high p: QuantilePoint(q0_95,0.95)
  • @qp_uu(q0_975) quantile at very high p: QuantilePoint(q0_975,0.975)

For constructing QuantilePoints with type of percentiles other than Float64, use the corresponding functions, that create a percentiles of the type of given quantile. E.g. for a Float32-based QuantilePoint at very low percentile

  • qp_ll(0.2f0) constructs a QuantilePoint(0.2f0,0.025f0)

There are macros/functions for some commonly used sets of QuantilePoints: 90% and 95% confidence intervals:

  • @qs_cf90(q0_05,q0_95)
  • @qs_cf95(q0_025,q0_975) -> Set([QuantilePoint(q0_025,0.025),QuantilePoint(q0_975,0.975)]))
source
diff --git a/dev/gamma/index.html b/dev/gamma/index.html index d357425..429e159 100644 --- a/dev/gamma/index.html +++ b/dev/gamma/index.html @@ -1,3 +1,3 @@ Gamma · DistributionFits.jl

Gamma distribution

The Gamma distribution has a scale and a shape parameter. It can be fitted using two quantiles.

d = fit(Gamma, @qp_m(0.5), @qp_uu(5));
-median(d) ≈ 0.5 && quantile(d, 0.975) ≈ 5

Fitting by mean or mode is not yet implemented.

+median(d) ≈ 0.5 && quantile(d, 0.975) ≈ 5

Fitting by mean or mode is not yet implemented.

diff --git a/dev/index.html b/dev/index.html index 84db992..354df2b 100644 --- a/dev/index.html +++ b/dev/index.html @@ -10,13 +10,13 @@ (mean(d), var(d)) .≈ (3.2,4.6)
d = fit(LogNormal, moments(Normal(3,1.2)));
 (mean(d), std(d)) .≈ (3,1.2)
# using StatsPlots
 plot(d, label = "lognormal", ylab="probability density")
-plot!(Normal(3,1.2), label = "normal")
source

Fit to several quantile points

StatsAPI.fitMethod
fit(D, lower::QuantilePoint, upper::QuantilePoint)

Fit a statistical distribution to a set of quantiles

Arguments

  • D: The type of the distribution to fit
  • lower: lower QuantilePoint (p,q)
  • upper: upper QuantilePoint (p,q)

Examples

d = fit(LogNormal, @qp_m(3), @qp_uu(5));
-quantile.(d, [0.5, 0.975]) ≈ [3,5]
source

Fit to mean, mode, median and a quantile point

StatsAPI.fitMethod
fit(D, val, qp, ::Val{stats} = Val(:mean))

Fit a statistical distribution to a quantile and given statistics

Arguments

  • D: The type of distribution to fit
  • val: The value of statistics
  • qp: QuantilePoint(q,p)
  • stats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)

Examples

d = fit(LogNormal, 5.0, @qp_uu(14));
+plot!(Normal(3,1.2), label = "normal")
source

Fit to several quantile points

StatsAPI.fitMethod
fit(D, lower::QuantilePoint, upper::QuantilePoint)

Fit a statistical distribution to a set of quantiles

Arguments

  • D: The type of the distribution to fit
  • lower: lower QuantilePoint (p,q)
  • upper: upper QuantilePoint (p,q)

Examples

d = fit(LogNormal, @qp_m(3), @qp_uu(5));
+quantile.(d, [0.5, 0.975]) ≈ [3,5]
source

Fit to mean, mode, median and a quantile point

StatsAPI.fitMethod
fit(D, val, qp, ::Val{stats} = Val(:mean))

Fit a statistical distribution to a quantile and given statistics

Arguments

  • D: The type of distribution to fit
  • val: The value of statistics
  • qp: QuantilePoint(q,p)
  • stats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)

Examples

d = fit(LogNormal, 5.0, @qp_uu(14));
 (mean(d),quantile(d, 0.975)) .≈ (5,14)
d = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));
-(mode(d),quantile(d, 0.975)) .≈ (5,14)
source

Currently supported distributions

Univariate continuous

Implementing support for another distribution

In order to use the fitting framework for a distribution MyDist, one needs to implement the following four methods.

fit(::Type{MyDist}, m::AbstractMoments)
+(mode(d),quantile(d, 0.975)) .≈ (5,14)
source

Currently supported distributions

Univariate continuous

Implementing support for another distribution

In order to use the fitting framework for a distribution MyDist, one needs to implement the following four methods.

fit(::Type{MyDist}, m::AbstractMoments)
 
 fit_mean_quantile(::Type{MyDist}, mean, qp::QuantilePoint)
 
 fit_mode_quantile(::Type{MyDist}, mode, qp::QuantilePoint)
 
-fit(::Type{MyDist}, lower::QuantilePoint, upper::QuantilePoint)

The default method for fit with stats = :median already works based on the methods for two quantile points. If the general method on two quantile points cannot be specified, one can alternatively implement method:

fit_median_quantile(::Type{MyDist}, median, qp::QuantilePoint)
+fit(::Type{MyDist}, lower::QuantilePoint, upper::QuantilePoint)

The default method for fit with stats = :median already works based on the methods for two quantile points. If the general method on two quantile points cannot be specified, one can alternatively implement method:

fit_median_quantile(::Type{MyDist}, median, qp::QuantilePoint)
diff --git a/dev/logitnormal/f2283b31.svg b/dev/logitnormal/cb64cade.svg similarity index 86% rename from dev/logitnormal/f2283b31.svg rename to dev/logitnormal/cb64cade.svg index 4965783..3440501 100644 --- a/dev/logitnormal/f2283b31.svg +++ b/dev/logitnormal/cb64cade.svg @@ -1,50 +1,50 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/logitnormal/index.html b/dev/logitnormal/index.html index 003f95f..bf13abc 100644 --- a/dev/logitnormal/index.html +++ b/dev/logitnormal/index.html @@ -1,6 +1,6 @@ LogitNormal · DistributionFits.jl

LogitNormal distribution

Aggregate statistics

The logitnormal distribution has no analytical formula for mean, variance nor its mode. This package estimates those by numerically integrating the distribution.

d = fit(LogitNormal, 0.8, @qp_u(0.9), Val(:mode))
 mean(d), var(d)
-mode(d) ≈ 0.8

Specifying a logitnormal distribution by mode and peakedness

It is sometimes difficult to specify a precise upper quantile, because the logitnormal distribution is already constrained in (0,1). However, user might have an idea of the spread, or the inverse: peakedness, of the distribution.

With increasing spread, the logitnormal distribution becomes bimodal. The following functiion estimates the most spread, i.e most flat distribution that has a single mode at the given location.

DistributionFits.fit_mode_flatFunction
fit_mode_flat(::Type{LogitNormal}, mode::T; peakedness = 1.0)

Find the maximum-spread logitnormal distribution that has a single mode at given location.

More peaked distributions with given single mode can be optained by increasing argument peakedness. They will have a spread by originally inferred σ² devidied by peakedness.

Examples

m = 0.6
+mode(d) ≈ 0.8

Specifying a logitnormal distribution by mode and peakedness

It is sometimes difficult to specify a precise upper quantile, because the logitnormal distribution is already constrained in (0,1). However, user might have an idea of the spread, or the inverse: peakedness, of the distribution.

With increasing spread, the logitnormal distribution becomes bimodal. The following function estimates the most spread, i.e most flat distribution that has a single mode at the given location.

DistributionFits.fit_mode_flatFunction
fit_mode_flat(::Type{LogitNormal}, mode::T; peakedness = 1.0)

Find the maximum-spread logitnormal distribution that has a single mode at given location.

More peaked distributions with given single mode can be obtained by increasing argument peakedness. They will have a spread by originally inferred σ² devidied by peakedness.

Examples

m = 0.6
 d = fit_mode_flat(LogitNormal, m; peakedness = 1.5)
-mode(d) ≈ m
source

The found maximum spread parameter, σ, is devided by the peakedness argument to specify distributions given the mode that are more peaked.

Example block output

A shifted and scaled version of this distribution can be used as a moother alternative to the Bounded uniform distribution.

DistributionFits.shifloNormalFunction
shifloNormal(lower,upper)

Get a Shifted Flat LogitNormal distribution that is most spread with an extent between lower and upper. This is a more smooth alternative to the bounded uniform distribution.

source
+mode(d) ≈ msource

The found maximum spread parameter, σ, is divided by the peakedness argument to specify distributions given the mode that are more peaked.

Example block output

A shifted and scaled version of this distribution can be used as a moother alternative to the Bounded uniform distribution.

DistributionFits.shifloNormalFunction
shifloNormal(lower,upper)

Get a Shifted Flat LogitNormal distribution that is most spread with an extent between lower and upper. This is a more smooth alternative to the bounded uniform distribution.

source
diff --git a/dev/lognormal/index.html b/dev/lognormal/index.html index de0909b..51e20a1 100644 --- a/dev/lognormal/index.html +++ b/dev/lognormal/index.html @@ -2,7 +2,7 @@ LogNormal · DistributionFits.jl

LogNormal distribution

The LogNormal distribution can be characterized by the exponent of its parameters:

  • exp(μ): the median
  • exp(σ): the multiplicative standard deviation $\sigma^*$.

Function σstar returns the multiplicative standard deviation.

A distribution can be specified by taking the log of median and $\sigma^*$

d = LogNormal(log(2), log(1.2))
 σstar(d) == 1.2

Alternatively the distribution can be specified by its mean and $\sigma^*$ using type AbstractΣstar

d = fit(LogNormal, 2, Σstar(1.2))
 (mean(d), σstar(d)) == (2, 1.2)

Detailed API

DistributionFits.σstarMethod
σstar(d)

Get the multiplicative standard deviation of LogNormal distribution d.

Arguments

  • d: The type of distribution to fit

Examples

d = LogNormal(2,log(1.2))
-σstar(d) == 1.2
source
StatsAPI.fitMethod
fit(D, mean, σstar)

Fit a statistical distribution of type D to mean and multiplicative standard deviation.

Arguments

  • D: The type of distribution to fit
  • mean: The moments of the distribution
  • σstar::AbstractΣstar: The multiplicative standard deviation

See also σstar, AbstractΣstar.

Examples

d = fit(LogNormal, 2, Σstar(1.1));
-(mean(d), σstar(d)) == (2, 1.1)
source
DistributionFits.AbstractΣstarType
Σstar <: AbstractΣstar

Represent the multiplicative standard deviation of a LogNormal distribution.

Supports dispatch of fit. Invoking the type as a function returns its single value.

Examples

a = Σstar(4.2)
-a() == 4.2
source
DistributionFits.fit_mean_relerrorFunction
fit_mean_relerror(D, mean, relerror)

Fit a distribution of type D to mean and relative error.

Arguments

  • D: The type of distribution to fit
  • mean: The first moment of the distribution
  • relerror: The relative error, i.e. the coefficient of variation

Examples

d = fit_mean_relerror(LogNormal, 10.0, 0.03);
-(mean(d), std(d)/mean(d)) .≈ (10.0, 0.03)
source
+σstar(d) == 1.2source
StatsAPI.fitMethod
fit(D, mean, σstar)

Fit a statistical distribution of type D to mean and multiplicative standard deviation.

Arguments

  • D: The type of distribution to fit
  • mean: The moments of the distribution
  • σstar::AbstractΣstar: The multiplicative standard deviation

See also σstar, AbstractΣstar.

Examples

d = fit(LogNormal, 2, Σstar(1.1));
+(mean(d), σstar(d)) == (2, 1.1)
source
DistributionFits.AbstractΣstarType
Σstar <: AbstractΣstar

Represent the multiplicative standard deviation of a LogNormal distribution.

Supports dispatch of fit. Invoking the type as a function returns its single value.

Examples

a = Σstar(4.2)
+a() == 4.2
source
DistributionFits.fit_mean_relerrorFunction
fit_mean_relerror(D, mean, relerror)

Fit a distribution of type D to mean and relative error.

Arguments

  • D: The type of distribution to fit
  • mean: The first moment of the distribution
  • relerror: The relative error, i.e. the coefficient of variation

Examples

d = fit_mean_relerror(LogNormal, 10.0, 0.03);
+(mean(d), std(d)/mean(d)) .≈ (10.0, 0.03)
source
diff --git a/dev/partype/index.html b/dev/partype/index.html index 42ddbdb..c627ad8 100644 --- a/dev/partype/index.html +++ b/dev/partype/index.html @@ -1,7 +1,7 @@ -Parameter type · DistributionFits.jl

Creating Distributions with specific parameter types

Default type of distribution parameters is Float64. Many Distributions of Distributions.jl support also other Number types, such as duals numbers or Float32 for type parameters.

The fit function allow to specify the concrete parametric types of the resulting fitted distribution. Note the Float32 parametric type in the following example.

d = fit(LogNormal{Float32}, @qp_ll(1.0), @qp_uu(8))
-partype(d) == Float32

Infering the parametric type from other arguments.

If the parametric type is omitted, default Float64 is assumed, or inferred from other parameters of the fitting function. Since quantiles and median are rather sample-like measures than paraemter-like measures, they do not influence the inferred parameter type.

d = fit(LogitNormal, 0.3f0, @qp_u(0.8f0), Val(:median)) #f0 indicates Float32 literals
+Parameter type · DistributionFits.jl

Creating Distributions with specific parameter types

Default type of distribution parameters is Float64. Many Distributions of Distributions.jl support also other Number types, such as duals numbers or Float32 for type parameters.

The fit function allow to specify the concrete parametric types of the resulting fitted distribution. Note the Float32 parametric type in the following example.

d = fit(LogNormal{Float32}, @qp_ll(1.0), @qp_uu(8))
+partype(d) == Float32

Inferring the parametric type from other arguments.

If the parametric type is omitted, default Float64 is assumed, or inferred from other parameters of the fitting function. Since quantiles and median are rather sample-like measures than paraemter-like measures, they do not influence the inferred parameter type.

d = fit(LogitNormal, 0.3f0, @qp_u(0.8f0), Val(:median)) #f0 indicates Float32 literals
 partype(d) == Float64

Parameter type, however, can be inferred from provided moments, mean, and mode.

d = fit(Exponential, Moments(3f0))  #f0 indicates Float32 literals
 partype(d) == Float32
d = fit(LogNormal, 3f0, @qp_uu(8))
 partype(d) == Float32
d = fit(LogNormal, 3f0, @qp_uu(8), Val(:mode))
-partype(d) == Float32
+partype(d) == Float32
diff --git a/dev/search_index.js b/dev/search_index.js index 0190675..a7a3f39 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"api/#API","page":"API","title":"API","text":"","category":"section"},{"location":"api/#AbstractMoments","page":"API","title":"AbstractMoments","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"The concept of first and higher order moments is captured by its own type. This allows dispatching the fit method.","category":"page"},{"location":"api/","page":"API","title":"API","text":"AbstractMoments\nmoments","category":"page"},{"location":"api/#DistributionFits.AbstractMoments","page":"API","title":"DistributionFits.AbstractMoments","text":"AbstractMoments{N}\n\nA representation of statistical moments of a distribution\n\nThe following functions are supported\n\nn_moments(m): get the number of recorded moments\n\nThe following getters return a single moment or throw an error if the moment has not been recorded (>N)\n\nmean(m): get the first momemnt, i.e. the mean\nvar(m): get the second moment, i.e. the variance\nskewness(m): get the third moment, i.e. the skewness\nkurtosis(m): get the fourth moment, i.e. the kurtosis\ngetindex(m,i): get the ith moment, i.e. indexing m[i]\n\nThe basic implementation Moments is immutable and convert(AbstractArray, m::Moments) returns an SArray{N,T}.\n\nExamples\n\nm = Moments(1,0.2);\nn_moments(m) == 2\nvar(m) == m[2]\n\nkurtosis(m) # throws error because its above 2nd moment\n\n\n\n\n\n","category":"type"},{"location":"api/#DistributionFits.moments","page":"API","title":"DistributionFits.moments","text":"moments(D, ::Val{N} = Val(2))\n\nGet the first N moments of a distribution.\n\nProcudes an object of type AbstractMoments.\n\nExamples\n\nmoments(LogNormal(), Val(4)) # first four moments \nmoments(Normal()) # mean and variance\n\n\n\n\n\n","category":"function"},{"location":"api/#QuantilePoint","page":"API","title":"QuantilePoint","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"The concept of a pair (p,q), i.e. a probability in [0,1] and associated quantile is captured by its own type. This allows dispatching the fit method.","category":"page"},{"location":"api/","page":"API","title":"API","text":"QuantilePoint","category":"page"},{"location":"api/#DistributionFits.QuantilePoint","page":"API","title":"DistributionFits.QuantilePoint","text":"QuantilePoint\n\nA representation of a pair (p,q), i.e. (percentile,quantile).\n\nNotes\n\nSeveral macros help to construct QuantilePoints\n\n@qp(q,p) quantile at specified p: QuantilePoint(q,p)\n\nFor Float64-based percentiles there are shortcuts\n\n@qp_ll(q0_025) quantile at very low p: QuantilePoint(q0_025,0.025) \n@qp_l(q0_05) quantile at low p: QuantilePoint(q0_05,0.05) \n@qp_m(median) quantile at median: QuantilePoint(median,0.5) \n@qp_u(q0_95) quantile at high p: QuantilePoint(q0_95,0.95) \n@qp_uu(q0_975) quantile at very high p: QuantilePoint(q0_975,0.975) \n\nFor constructing QuantilePoints with type of percentiles other than Float64, use the corresponding functions, that create a percentiles of the type of given quantile. E.g. for a Float32-based QuantilePoint at very low percentile\n\nqp_ll(0.2f0) constructs a QuantilePoint(0.2f0,0.025f0) \n\nThere are macros/functions for some commonly used sets of QuantilePoints: 90% and 95% confidence intervals:\n\n@qs_cf90(q0_05,q0_95) \n@qs_cf95(q0_025,q0_975) -> Set([QuantilePoint(q0_025,0.025),QuantilePoint(q0_975,0.975)]))\n\n\n\n\n\n","category":"type"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"CurrentModule = DistributionFits","category":"page"},{"location":"z_autodocs/#DistributionFits","page":"DistributionFits","title":"DistributionFits","text":"","category":"section"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"Documentation for DistributionFits.","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"[comment]: # (```@autodocs)","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"[comment]: # (Modules = [DistributionFits])","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"[comment]: # (```)","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"taken care of in index.md called only internally from fit, documented in docstring via \",\"","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"fit_median_quantile\nfit_mean_quantile\nfit_mode_quantile","category":"page"},{"location":"z_autodocs/#DistributionFits.fit_median_quantile","page":"DistributionFits","title":"DistributionFits.fit_median_quantile","text":"fit(D, val, qp, ::Val{stats} = Val(:mean))\n\nFit a statistical distribution to a quantile and given statistics\n\nArguments\n\nD: The type of distribution to fit\nval: The value of statistics\nqp: QuantilePoint(q,p)\nstats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)\n\nExamples\n\nd = fit(LogNormal, 5.0, @qp_uu(14));\n(mean(d),quantile(d, 0.975)) .≈ (5,14)\n\nd = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));\n(mode(d),quantile(d, 0.975)) .≈ (5,14)\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/#DistributionFits.fit_mean_quantile","page":"DistributionFits","title":"DistributionFits.fit_mean_quantile","text":"fit(D, val, qp, ::Val{stats} = Val(:mean))\n\nFit a statistical distribution to a quantile and given statistics\n\nArguments\n\nD: The type of distribution to fit\nval: The value of statistics\nqp: QuantilePoint(q,p)\nstats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)\n\nExamples\n\nd = fit(LogNormal, 5.0, @qp_uu(14));\n(mean(d),quantile(d, 0.975)) .≈ (5,14)\n\nd = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));\n(mode(d),quantile(d, 0.975)) .≈ (5,14)\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/#DistributionFits.fit_mode_quantile","page":"DistributionFits","title":"DistributionFits.fit_mode_quantile","text":"fit(D, val, qp, ::Val{stats} = Val(:mean))\n\nFit a statistical distribution to a quantile and given statistics\n\nArguments\n\nD: The type of distribution to fit\nval: The value of statistics\nqp: QuantilePoint(q,p)\nstats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)\n\nExamples\n\nd = fit(LogNormal, 5.0, @qp_uu(14));\n(mean(d),quantile(d, 0.975)) .≈ (5,14)\n\nd = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));\n(mode(d),quantile(d, 0.975)) .≈ (5,14)\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"internals","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"meanFunOfProb\nofLogitNormalModeUpper","category":"page"},{"location":"z_autodocs/#DistributionFits.meanFunOfProb","page":"DistributionFits","title":"DistributionFits.meanFunOfProb","text":"compute mean over a function(uniformly distributed probabilities)\n\nused to estimate moments of logitnorm\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/#DistributionFits.ofLogitNormalModeUpper","page":"DistributionFits","title":"DistributionFits.ofLogitNormalModeUpper","text":"objective function used by matchModeUpper(LogitNormal,...)\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"[comment]: # (fit(Type{LogNormal}, Any, AbstractΣstar))","category":"page"},{"location":"gamma/","page":"Gamma","title":"Gamma","text":"CurrentModule = DistributionFits","category":"page"},{"location":"gamma/#Gamma-distribution","page":"Gamma","title":"Gamma distribution","text":"","category":"section"},{"location":"gamma/","page":"Gamma","title":"Gamma","text":"The Gamma distribution has a scale and a shape parameter. It can be fitted using two quantiles.","category":"page"},{"location":"gamma/","page":"Gamma","title":"Gamma","text":"d = fit(Gamma, @qp_m(0.5), @qp_uu(5));\nmedian(d) ≈ 0.5 && quantile(d, 0.975) ≈ 5","category":"page"},{"location":"gamma/","page":"Gamma","title":"Gamma","text":"Fitting by mean or mode is not yet implemented.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"CurrentModule = DistributionFits","category":"page"},{"location":"logitnormal/#LogitNormal-distribution","page":"LogitNormal","title":"LogitNormal distribution","text":"","category":"section"},{"location":"logitnormal/#Aggregate-statistics","page":"LogitNormal","title":"Aggregate statistics","text":"","category":"section"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"The logitnormal distribution has no analytical formula for mean, variance nor its mode. This package estimates those by numerically integrating the distribution.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"d = fit(LogitNormal, 0.8, @qp_u(0.9), Val(:mode))\nmean(d), var(d)\nmode(d) ≈ 0.8","category":"page"},{"location":"logitnormal/#Specifying-a-logitnormal-distribution-by-mode-and-peakedness","page":"LogitNormal","title":"Specifying a logitnormal distribution by mode and peakedness","text":"","category":"section"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"It is sometimes difficult to specify a precise upper quantile, because the logitnormal distribution is already constrained in (0,1). However, user might have an idea of the spread, or the inverse: peakedness, of the distribution.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"With increasing spread, the logitnormal distribution becomes bimodal. The following functiion estimates the most spread, i.e most flat distribution that has a single mode at the given location.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"fit_mode_flat","category":"page"},{"location":"logitnormal/#DistributionFits.fit_mode_flat","page":"LogitNormal","title":"DistributionFits.fit_mode_flat","text":"fit_mode_flat(::Type{LogitNormal}, mode::T; peakedness = 1.0)\n\nFind the maximum-spread logitnormal distribution that has a single mode at given location.\n\nMore peaked distributions with given single mode can be optained by increasing argument peakedness. They will have a spread by originally inferred σ² devidied by peakedness.\n\nExamples\n\nm = 0.6\nd = fit_mode_flat(LogitNormal, m; peakedness = 1.5)\nmode(d) ≈ m\n\n\n\n\n\n","category":"function"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"The found maximum spread parameter, σ, is devided by the peakedness argument to specify distributions given the mode that are more peaked.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"using DistributionFits,Optim\nusing StatsPlots # do not forget to add to docs environment\npeakedness_vec = 1:0.5:2\nm = 0.6\np = plot(\n legend = :topleft, ylab=\"probability density\", legendtitle = \"peakedness\",\n palette = :Dark2_3,)\nfor peakedness in peakedness_vec\n d = fit_mode_flat(LogitNormal, m; peakedness)\n plot!(p, d, label = peakedness)\nend\n#savefig(p, \"logitnormal_peakedness.svg\")\n#![](logitnormal_peakedness.svg)","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"p # hide","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"A shifted and scaled version of this distribution can be used as a moother alternative to the Bounded uniform distribution.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"shifloNormal","category":"page"},{"location":"logitnormal/#DistributionFits.shifloNormal","page":"LogitNormal","title":"DistributionFits.shifloNormal","text":"shifloNormal(lower,upper)\n\nGet a Shifted Flat LogitNormal distribution that is most spread with an extent between lower and upper. This is a more smooth alternative to the bounded uniform distribution.\n\n\n\n\n\n","category":"function"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"CurrentModule = DistributionFits","category":"page"},{"location":"lognormal/#LogNormal-distribution","page":"LogNormal","title":"LogNormal distribution","text":"","category":"section"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"The LogNormal distribution can be characterized by the exponent of its parameters:","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"exp(μ): the median\nexp(σ): the multiplicative standard deviation sigma^*.","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"Function σstar returns the multiplicative standard deviation.","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"A distribution can be specified by taking the log of median and sigma^*","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"d = LogNormal(log(2), log(1.2))\nσstar(d) == 1.2","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"Alternatively the distribution can be specified by its mean and sigma^* using type AbstractΣstar","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"d = fit(LogNormal, 2, Σstar(1.2))\n(mean(d), σstar(d)) == (2, 1.2)","category":"page"},{"location":"lognormal/#Detailed-API","page":"LogNormal","title":"Detailed API","text":"","category":"section"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"σstar(::LogNormal)","category":"page"},{"location":"lognormal/#DistributionFits.σstar-Tuple{LogNormal}","page":"LogNormal","title":"DistributionFits.σstar","text":"σstar(d)\n\nGet the multiplicative standard deviation of LogNormal distribution d.\n\nArguments\n\nd: The type of distribution to fit\n\nExamples\n\nd = LogNormal(2,log(1.2))\nσstar(d) == 1.2\n\n\n\n\n\n","category":"method"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"fit(::Type{LogNormal}, ::T, ::AbstractΣstar) where T<:Real","category":"page"},{"location":"lognormal/#StatsAPI.fit-Union{Tuple{T}, Tuple{Type{LogNormal}, T, AbstractΣstar}} where T<:Real","page":"LogNormal","title":"StatsAPI.fit","text":"fit(D, mean, σstar)\n\nFit a statistical distribution of type D to mean and multiplicative standard deviation.\n\nArguments\n\nD: The type of distribution to fit\nmean: The moments of the distribution\nσstar::AbstractΣstar: The multiplicative standard deviation\n\nSee also σstar, AbstractΣstar. \n\nExamples\n\nd = fit(LogNormal, 2, Σstar(1.1));\n(mean(d), σstar(d)) == (2, 1.1)\n\n\n\n\n\n","category":"method"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"AbstractΣstar","category":"page"},{"location":"lognormal/#DistributionFits.AbstractΣstar","page":"LogNormal","title":"DistributionFits.AbstractΣstar","text":"Σstar <: AbstractΣstar\n\nRepresent the multiplicative standard deviation of a LogNormal distribution.\n\nSupports dispatch of fit. Invoking the type as a function returns its single value.\n\nExamples\n\na = Σstar(4.2)\na() == 4.2\n\n\n\n\n\n","category":"type"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"fit_mean_relerror","category":"page"},{"location":"lognormal/#DistributionFits.fit_mean_relerror","page":"LogNormal","title":"DistributionFits.fit_mean_relerror","text":"fit_mean_relerror(D, mean, relerror)\n\nFit a distribution of type D to mean and relative error.\n\nArguments\n\nD: The type of distribution to fit\nmean: The first moment of the distribution\nrelerror: The relative error, i.e. the coefficient of variation\n\nExamples\n\nd = fit_mean_relerror(LogNormal, 10.0, 0.03);\n(mean(d), std(d)/mean(d)) .≈ (10.0, 0.03)\n\n\n\n\n\n","category":"function"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"CurrentModule = DistributionFits","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"partype/#Creating-Distributions-with-specific-parameter-types","page":"Parameter type","title":"Creating Distributions with specific parameter types","text":"","category":"section"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"Default type of distribution parameters is Float64. Many Distributions of Distributions.jl support also other Number types, such as duals numbers or Float32 for type parameters.","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"The fit function allow to specify the concrete parametric types of the resulting fitted distribution. Note the Float32 parametric type in the following example.","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(LogNormal{Float32}, @qp_ll(1.0), @qp_uu(8))\npartype(d) == Float32","category":"page"},{"location":"partype/#Infering-the-parametric-type-from-other-arguments.","page":"Parameter type","title":"Infering the parametric type from other arguments.","text":"","category":"section"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"If the parametric type is omitted, default Float64 is assumed, or inferred from other parameters of the fitting function. Since quantiles and median are rather sample-like measures than paraemter-like measures, they do not influence the inferred parameter type.","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(LogitNormal, 0.3f0, @qp_u(0.8f0), Val(:median)) #f0 indicates Float32 literals\npartype(d) == Float64","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"Parameter type, however, can be inferred from provided moments, mean, and mode.","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(Exponential, Moments(3f0)) #f0 indicates Float32 literals\npartype(d) == Float32","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(LogNormal, 3f0, @qp_uu(8))\npartype(d) == Float32","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(LogNormal, 3f0, @qp_uu(8), Val(:mode))\npartype(d) == Float32","category":"page"},{"location":"","page":"Home","title":"Home","text":"CurrentModule = DistributionFits","category":"page"},{"location":"#DistributionFits","page":"Home","title":"DistributionFits","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Package DistributionFits allows fitting a distribution to a given set of aggregate statistics.","category":"page"},{"location":"","page":"Home","title":"Home","text":"to specified moments","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(LogNormal, Moments(3.0,4.0))\n(mean(d), var(d)) .≈ (3.0, 4.0)","category":"page"},{"location":"","page":"Home","title":"Home","text":"mean and upper quantile point","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(LogNormal, 3.0, @qp_uu(8))\n(mean(d), quantile(d, 0.975)) .≈ (3.0, 8.0)","category":"page"},{"location":"","page":"Home","title":"Home","text":"to mode and upper quantile point","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(LogNormal, 3.0, @qp_uu(8), Val(:mode))\n(mode(d), quantile(d, 0.975)) .≈ (3.0, 8.0)","category":"page"},{"location":"","page":"Home","title":"Home","text":"to median and upper quantile point","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(LogitNormal, 0.3, @qp_u(0.8), Val(:median))\n(median(d), quantile(d, 0.95)) .≈ (0.3, 0.8)","category":"page"},{"location":"","page":"Home","title":"Home","text":"to two quantiles, i.e confidence range","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(Normal, @qp_ll(1.0), @qp_uu(8))\n(quantile(d, 0.025), quantile(d, 0.975)) .≈ (1.0, 8.0)","category":"page"},{"location":"","page":"Home","title":"Home","text":"approximate a different distribution by matching moments","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"dn = Normal(3,2)\nd = fit(LogNormal, moments(dn))\n(mean(d), var(d)) .≈ (3.0, 4.0)","category":"page"},{"location":"#Fit-to-statistical-moments","page":"Home","title":"Fit to statistical moments","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"fit(::Type{D}, ::AbstractMoments) where {D<:Distribution}","category":"page"},{"location":"#StatsAPI.fit-Union{Tuple{D}, Tuple{Type{D}, AbstractMoments}} where D<:Distribution","page":"Home","title":"StatsAPI.fit","text":"fit(D, m)\n\nFit a statistical distribution of type D to given moments m.\n\nArguments\n\nD: The type of distribution to fit\nm: The moments of the distribution\n\nNotes\n\nThis can be used to approximate one distribution by another.\n\nSee also AbstractMoments, moments. \n\nExamples\n\nd = fit(LogNormal, Moments(3.2,4.6));\n(mean(d), var(d)) .≈ (3.2,4.6)\n\nd = fit(LogNormal, moments(Normal(3,1.2)));\n(mean(d), std(d)) .≈ (3,1.2)\n\n# using StatsPlots\nplot(d, label = \"lognormal\", ylab=\"probability density\")\nplot!(Normal(3,1.2), label = \"normal\")\n\n\n\n\n\n","category":"method"},{"location":"#Fit-to-several-quantile-points","page":"Home","title":"Fit to several quantile points","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"fit(::Type{D}, ::QuantilePoint, ::QuantilePoint) where {D<:Distribution}","category":"page"},{"location":"#StatsAPI.fit-Union{Tuple{D}, Tuple{Type{D}, QuantilePoint, QuantilePoint}} where D<:Distribution","page":"Home","title":"StatsAPI.fit","text":"fit(D, lower::QuantilePoint, upper::QuantilePoint)\n\nFit a statistical distribution to a set of quantiles \n\nArguments\n\nD: The type of the distribution to fit\nlower: lower QuantilePoint (p,q)\nupper: upper QuantilePoint (p,q)\n\nExamples\n\nd = fit(LogNormal, @qp_m(3), @qp_uu(5));\nquantile.(d, [0.5, 0.975]) ≈ [3,5]\n\n\n\n\n\n","category":"method"},{"location":"#Fit-to-mean,-mode,-median-and-a-quantile-point","page":"Home","title":"Fit to mean, mode, median and a quantile point","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"fit(::Type{D}, ::Any, ::QuantilePoint, ::Val{stats} = Val(:mean)) where {D<:Distribution, stats}","category":"page"},{"location":"#StatsAPI.fit-Union{Tuple{stats}, Tuple{D}, Tuple{Type{D}, Any, QuantilePoint}, Tuple{Type{D}, Any, QuantilePoint, Val{stats}}} where {D<:Distribution, stats}","page":"Home","title":"StatsAPI.fit","text":"fit(D, val, qp, ::Val{stats} = Val(:mean))\n\nFit a statistical distribution to a quantile and given statistics\n\nArguments\n\nD: The type of distribution to fit\nval: The value of statistics\nqp: QuantilePoint(q,p)\nstats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)\n\nExamples\n\nd = fit(LogNormal, 5.0, @qp_uu(14));\n(mean(d),quantile(d, 0.975)) .≈ (5,14)\n\nd = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));\n(mode(d),quantile(d, 0.975)) .≈ (5,14)\n\n\n\n\n\n","category":"method"},{"location":"#Currently-supported-distributions","page":"Home","title":"Currently supported distributions","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Univariate continuous","category":"page"},{"location":"","page":"Home","title":"Home","text":"Normal\nLogNormal distribution\nLogitNormal distribution\nExponential\nLaplace\nWeibull distribution\nGamma distribution","category":"page"},{"location":"#Implementing-support-for-another-distribution","page":"Home","title":"Implementing support for another distribution","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"In order to use the fitting framework for a distribution MyDist, one needs to implement the following four methods.","category":"page"},{"location":"","page":"Home","title":"Home","text":"fit(::Type{MyDist}, m::AbstractMoments)\n\nfit_mean_quantile(::Type{MyDist}, mean, qp::QuantilePoint)\n\nfit_mode_quantile(::Type{MyDist}, mode, qp::QuantilePoint)\n\nfit(::Type{MyDist}, lower::QuantilePoint, upper::QuantilePoint)","category":"page"},{"location":"","page":"Home","title":"Home","text":"The default method for fit with stats = :median already works based on the methods for two quantile points. If the general method on two quantile points cannot be specified, one can alternatively implement method:","category":"page"},{"location":"","page":"Home","title":"Home","text":"fit_median_quantile(::Type{MyDist}, median, qp::QuantilePoint)","category":"page"},{"location":"set_optimize/","page":"Dependencies","title":"Dependencies","text":"CurrentModule = DistributionFits","category":"page"},{"location":"set_optimize/#Setting-the-optimize-configuration","page":"Dependencies","title":"Setting the optimize configuration","text":"","category":"section"},{"location":"set_optimize/","page":"Dependencies","title":"Dependencies","text":"AbstractDistributionFitOptimizer","category":"page"},{"location":"set_optimize/#DistributionFits.AbstractDistributionFitOptimizer","page":"Dependencies","title":"DistributionFits.AbstractDistributionFitOptimizer","text":"AbstractDistributionFitOptimizer\nOptimOptimizer <: AbstractDistributionFitOptimizer\nset_optimizer(::AbstractDistributionFitOptimizer)\n\nDistributionFits.jl uses the following interface to opimize an univariate function f on bounded interval [lower,upper]:\n\noptimize(f, ::AbstractDistributionFitOptimizer, lower, upper)\n\nReturning an object with fields minimizer and converged.\n\nDistributionFits.set_optimizer(::AbstractDistributionFitOptimizer) sets the specific AbstractDistributionFitOptimizer that is used throughout the package for calling the optimize function. Specializing this function with a concrete type, allows using different optimization packages. \n\nBy default, when the Optim.jl package is in scope, the OptimOptimizer is set, which implements the interface by using Optim's optimize function.\n\nHence, the module using DistributionFits.jl has to either\n\nexplicitly invoke using Optim, or\ncall set_optimizer with the concrete subtype of AbstractDistributionFitOptimizer for which the corresponding optimize method is implemented. \n\nDevelopers implementing usage of a different specific optimizer see code in ext/DistributionFitsOptimExt.\n\n\n\n\n\n","category":"type"},{"location":"weibull/","page":"Weibull","title":"Weibull","text":"CurrentModule = DistributionFits","category":"page"},{"location":"weibull/#Weibull-distribution","page":"Weibull","title":"Weibull distribution","text":"","category":"section"},{"location":"weibull/","page":"Weibull","title":"Weibull","text":"The Weibull distribution has a scale and a shape parameter. It can be fitted using two quantiles.","category":"page"},{"location":"weibull/","page":"Weibull","title":"Weibull","text":"d = fit(Weibull, @qp_m(0.5), @qp_uu(5));\nmedian(d) == 0.5 && quantile(d, 0.975) ≈ 5","category":"page"},{"location":"weibull/","page":"Weibull","title":"Weibull","text":"Fitting by mean or mode is not yet implemented.","category":"page"}] +[{"location":"api/#API","page":"API","title":"API","text":"","category":"section"},{"location":"api/#AbstractMoments","page":"API","title":"AbstractMoments","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"The concept of first and higher order moments is captured by its own type. This allows dispatching the fit method.","category":"page"},{"location":"api/","page":"API","title":"API","text":"AbstractMoments\nmoments","category":"page"},{"location":"api/#DistributionFits.AbstractMoments","page":"API","title":"DistributionFits.AbstractMoments","text":"AbstractMoments{N}\n\nA representation of statistical moments of a distribution\n\nThe following functions are supported\n\nn_moments(m): get the number of recorded moments\n\nThe following getters return a single moment or throw an error if the moment has not been recorded (>N)\n\nmean(m): get the first momemnt, i.e. the mean\nvar(m): get the second moment, i.e. the variance\nskewness(m): get the third moment, i.e. the skewness\nkurtosis(m): get the fourth moment, i.e. the kurtosis\ngetindex(m,i): get the ith moment, i.e. indexing m[i]\n\nThe basic implementation Moments is immutable and convert(AbstractArray, m::Moments) returns an SArray{N,T}.\n\nExamples\n\nm = Moments(1,0.2);\nn_moments(m) == 2\nvar(m) == m[2]\n\nkurtosis(m) # throws error because its above 2nd moment\n\n\n\n\n\n","category":"type"},{"location":"api/#DistributionFits.moments","page":"API","title":"DistributionFits.moments","text":"moments(D, ::Val{N} = Val(2))\n\nGet the first N moments of a distribution.\n\nProduces an object of type AbstractMoments.\n\nExamples\n\nmoments(LogNormal(), Val(4)) # first four moments \nmoments(Normal()) # mean and variance\n\n\n\n\n\n","category":"function"},{"location":"api/#QuantilePoint","page":"API","title":"QuantilePoint","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"The concept of a pair (p,q), i.e. a probability in [0,1] and associated quantile is captured by its own type. This allows dispatching the fit method.","category":"page"},{"location":"api/","page":"API","title":"API","text":"QuantilePoint","category":"page"},{"location":"api/#DistributionFits.QuantilePoint","page":"API","title":"DistributionFits.QuantilePoint","text":"QuantilePoint\n\nA representation of a pair (p,q), i.e. (percentile,quantile).\n\nNotes\n\nSeveral macros help to construct QuantilePoints\n\n@qp(q,p) quantile at specified p: QuantilePoint(q,p)\n\nFor Float64-based percentiles there are shortcuts\n\n@qp_ll(q0_025) quantile at very low p: QuantilePoint(q0_025,0.025) \n@qp_l(q0_05) quantile at low p: QuantilePoint(q0_05,0.05) \n@qp_m(median) quantile at median: QuantilePoint(median,0.5) \n@qp_u(q0_95) quantile at high p: QuantilePoint(q0_95,0.95) \n@qp_uu(q0_975) quantile at very high p: QuantilePoint(q0_975,0.975) \n\nFor constructing QuantilePoints with type of percentiles other than Float64, use the corresponding functions, that create a percentiles of the type of given quantile. E.g. for a Float32-based QuantilePoint at very low percentile\n\nqp_ll(0.2f0) constructs a QuantilePoint(0.2f0,0.025f0) \n\nThere are macros/functions for some commonly used sets of QuantilePoints: 90% and 95% confidence intervals:\n\n@qs_cf90(q0_05,q0_95) \n@qs_cf95(q0_025,q0_975) -> Set([QuantilePoint(q0_025,0.025),QuantilePoint(q0_975,0.975)]))\n\n\n\n\n\n","category":"type"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"CurrentModule = DistributionFits","category":"page"},{"location":"z_autodocs/#DistributionFits","page":"DistributionFits","title":"DistributionFits","text":"","category":"section"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"Documentation for DistributionFits.","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"[comment]: # (```@autodocs)","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"[comment]: # (Modules = [DistributionFits])","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"[comment]: # (```)","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"taken care of in index.md called only internally from fit, documented in docstring via \",\"","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"fit_median_quantile\nfit_mean_quantile\nfit_mode_quantile","category":"page"},{"location":"z_autodocs/#DistributionFits.fit_median_quantile","page":"DistributionFits","title":"DistributionFits.fit_median_quantile","text":"fit(D, val, qp, ::Val{stats} = Val(:mean))\n\nFit a statistical distribution to a quantile and given statistics\n\nArguments\n\nD: The type of distribution to fit\nval: The value of statistics\nqp: QuantilePoint(q,p)\nstats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)\n\nExamples\n\nd = fit(LogNormal, 5.0, @qp_uu(14));\n(mean(d),quantile(d, 0.975)) .≈ (5,14)\n\nd = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));\n(mode(d),quantile(d, 0.975)) .≈ (5,14)\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/#DistributionFits.fit_mean_quantile","page":"DistributionFits","title":"DistributionFits.fit_mean_quantile","text":"fit(D, val, qp, ::Val{stats} = Val(:mean))\n\nFit a statistical distribution to a quantile and given statistics\n\nArguments\n\nD: The type of distribution to fit\nval: The value of statistics\nqp: QuantilePoint(q,p)\nstats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)\n\nExamples\n\nd = fit(LogNormal, 5.0, @qp_uu(14));\n(mean(d),quantile(d, 0.975)) .≈ (5,14)\n\nd = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));\n(mode(d),quantile(d, 0.975)) .≈ (5,14)\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/#DistributionFits.fit_mode_quantile","page":"DistributionFits","title":"DistributionFits.fit_mode_quantile","text":"fit(D, val, qp, ::Val{stats} = Val(:mean))\n\nFit a statistical distribution to a quantile and given statistics\n\nArguments\n\nD: The type of distribution to fit\nval: The value of statistics\nqp: QuantilePoint(q,p)\nstats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)\n\nExamples\n\nd = fit(LogNormal, 5.0, @qp_uu(14));\n(mean(d),quantile(d, 0.975)) .≈ (5,14)\n\nd = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));\n(mode(d),quantile(d, 0.975)) .≈ (5,14)\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"internals","category":"page"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"meanFunOfProb\nofLogitNormalModeUpper","category":"page"},{"location":"z_autodocs/#DistributionFits.meanFunOfProb","page":"DistributionFits","title":"DistributionFits.meanFunOfProb","text":"compute mean over a function(uniformly distributed probabilities)\n\nused to estimate moments of logitnorm\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/#DistributionFits.ofLogitNormalModeUpper","page":"DistributionFits","title":"DistributionFits.ofLogitNormalModeUpper","text":"objective function used by matchModeUpper(LogitNormal,...)\n\n\n\n\n\n","category":"function"},{"location":"z_autodocs/","page":"DistributionFits","title":"DistributionFits","text":"[comment]: # (fit(Type{LogNormal}, Any, AbstractΣstar))","category":"page"},{"location":"gamma/","page":"Gamma","title":"Gamma","text":"CurrentModule = DistributionFits","category":"page"},{"location":"gamma/#Gamma-distribution","page":"Gamma","title":"Gamma distribution","text":"","category":"section"},{"location":"gamma/","page":"Gamma","title":"Gamma","text":"The Gamma distribution has a scale and a shape parameter. It can be fitted using two quantiles.","category":"page"},{"location":"gamma/","page":"Gamma","title":"Gamma","text":"d = fit(Gamma, @qp_m(0.5), @qp_uu(5));\nmedian(d) ≈ 0.5 && quantile(d, 0.975) ≈ 5","category":"page"},{"location":"gamma/","page":"Gamma","title":"Gamma","text":"Fitting by mean or mode is not yet implemented.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"CurrentModule = DistributionFits","category":"page"},{"location":"logitnormal/#LogitNormal-distribution","page":"LogitNormal","title":"LogitNormal distribution","text":"","category":"section"},{"location":"logitnormal/#Aggregate-statistics","page":"LogitNormal","title":"Aggregate statistics","text":"","category":"section"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"The logitnormal distribution has no analytical formula for mean, variance nor its mode. This package estimates those by numerically integrating the distribution.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"d = fit(LogitNormal, 0.8, @qp_u(0.9), Val(:mode))\nmean(d), var(d)\nmode(d) ≈ 0.8","category":"page"},{"location":"logitnormal/#Specifying-a-logitnormal-distribution-by-mode-and-peakedness","page":"LogitNormal","title":"Specifying a logitnormal distribution by mode and peakedness","text":"","category":"section"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"It is sometimes difficult to specify a precise upper quantile, because the logitnormal distribution is already constrained in (0,1). However, user might have an idea of the spread, or the inverse: peakedness, of the distribution.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"With increasing spread, the logitnormal distribution becomes bimodal. The following function estimates the most spread, i.e most flat distribution that has a single mode at the given location.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"fit_mode_flat","category":"page"},{"location":"logitnormal/#DistributionFits.fit_mode_flat","page":"LogitNormal","title":"DistributionFits.fit_mode_flat","text":"fit_mode_flat(::Type{LogitNormal}, mode::T; peakedness = 1.0)\n\nFind the maximum-spread logitnormal distribution that has a single mode at given location.\n\nMore peaked distributions with given single mode can be obtained by increasing argument peakedness. They will have a spread by originally inferred σ² devidied by peakedness.\n\nExamples\n\nm = 0.6\nd = fit_mode_flat(LogitNormal, m; peakedness = 1.5)\nmode(d) ≈ m\n\n\n\n\n\n","category":"function"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"The found maximum spread parameter, σ, is divided by the peakedness argument to specify distributions given the mode that are more peaked.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"using DistributionFits,Optim\nusing StatsPlots # do not forget to add to docs environment\npeakedness_vec = 1:0.5:2\nm = 0.6\np = plot(\n legend = :topleft, ylab=\"probability density\", legendtitle = \"peakedness\",\n palette = :Dark2_3,)\nfor peakedness in peakedness_vec\n d = fit_mode_flat(LogitNormal, m; peakedness)\n plot!(p, d, label = peakedness)\nend\n#savefig(p, \"logitnormal_peakedness.svg\")\n#![](logitnormal_peakedness.svg)","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"p # hide","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"A shifted and scaled version of this distribution can be used as a moother alternative to the Bounded uniform distribution.","category":"page"},{"location":"logitnormal/","page":"LogitNormal","title":"LogitNormal","text":"shifloNormal","category":"page"},{"location":"logitnormal/#DistributionFits.shifloNormal","page":"LogitNormal","title":"DistributionFits.shifloNormal","text":"shifloNormal(lower,upper)\n\nGet a Shifted Flat LogitNormal distribution that is most spread with an extent between lower and upper. This is a more smooth alternative to the bounded uniform distribution.\n\n\n\n\n\n","category":"function"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"CurrentModule = DistributionFits","category":"page"},{"location":"lognormal/#LogNormal-distribution","page":"LogNormal","title":"LogNormal distribution","text":"","category":"section"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"The LogNormal distribution can be characterized by the exponent of its parameters:","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"exp(μ): the median\nexp(σ): the multiplicative standard deviation sigma^*.","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"Function σstar returns the multiplicative standard deviation.","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"A distribution can be specified by taking the log of median and sigma^*","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"d = LogNormal(log(2), log(1.2))\nσstar(d) == 1.2","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"Alternatively the distribution can be specified by its mean and sigma^* using type AbstractΣstar","category":"page"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"d = fit(LogNormal, 2, Σstar(1.2))\n(mean(d), σstar(d)) == (2, 1.2)","category":"page"},{"location":"lognormal/#Detailed-API","page":"LogNormal","title":"Detailed API","text":"","category":"section"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"σstar(::LogNormal)","category":"page"},{"location":"lognormal/#DistributionFits.σstar-Tuple{LogNormal}","page":"LogNormal","title":"DistributionFits.σstar","text":"σstar(d)\n\nGet the multiplicative standard deviation of LogNormal distribution d.\n\nArguments\n\nd: The type of distribution to fit\n\nExamples\n\nd = LogNormal(2,log(1.2))\nσstar(d) == 1.2\n\n\n\n\n\n","category":"method"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"fit(::Type{LogNormal}, ::T, ::AbstractΣstar) where T<:Real","category":"page"},{"location":"lognormal/#StatsAPI.fit-Union{Tuple{T}, Tuple{Type{LogNormal}, T, AbstractΣstar}} where T<:Real","page":"LogNormal","title":"StatsAPI.fit","text":"fit(D, mean, σstar)\n\nFit a statistical distribution of type D to mean and multiplicative standard deviation.\n\nArguments\n\nD: The type of distribution to fit\nmean: The moments of the distribution\nσstar::AbstractΣstar: The multiplicative standard deviation\n\nSee also σstar, AbstractΣstar. \n\nExamples\n\nd = fit(LogNormal, 2, Σstar(1.1));\n(mean(d), σstar(d)) == (2, 1.1)\n\n\n\n\n\n","category":"method"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"AbstractΣstar","category":"page"},{"location":"lognormal/#DistributionFits.AbstractΣstar","page":"LogNormal","title":"DistributionFits.AbstractΣstar","text":"Σstar <: AbstractΣstar\n\nRepresent the multiplicative standard deviation of a LogNormal distribution.\n\nSupports dispatch of fit. Invoking the type as a function returns its single value.\n\nExamples\n\na = Σstar(4.2)\na() == 4.2\n\n\n\n\n\n","category":"type"},{"location":"lognormal/","page":"LogNormal","title":"LogNormal","text":"fit_mean_relerror","category":"page"},{"location":"lognormal/#DistributionFits.fit_mean_relerror","page":"LogNormal","title":"DistributionFits.fit_mean_relerror","text":"fit_mean_relerror(D, mean, relerror)\n\nFit a distribution of type D to mean and relative error.\n\nArguments\n\nD: The type of distribution to fit\nmean: The first moment of the distribution\nrelerror: The relative error, i.e. the coefficient of variation\n\nExamples\n\nd = fit_mean_relerror(LogNormal, 10.0, 0.03);\n(mean(d), std(d)/mean(d)) .≈ (10.0, 0.03)\n\n\n\n\n\n","category":"function"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"CurrentModule = DistributionFits","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"partype/#Creating-Distributions-with-specific-parameter-types","page":"Parameter type","title":"Creating Distributions with specific parameter types","text":"","category":"section"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"Default type of distribution parameters is Float64. Many Distributions of Distributions.jl support also other Number types, such as duals numbers or Float32 for type parameters.","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"The fit function allow to specify the concrete parametric types of the resulting fitted distribution. Note the Float32 parametric type in the following example.","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(LogNormal{Float32}, @qp_ll(1.0), @qp_uu(8))\npartype(d) == Float32","category":"page"},{"location":"partype/#Inferring-the-parametric-type-from-other-arguments.","page":"Parameter type","title":"Inferring the parametric type from other arguments.","text":"","category":"section"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"If the parametric type is omitted, default Float64 is assumed, or inferred from other parameters of the fitting function. Since quantiles and median are rather sample-like measures than paraemter-like measures, they do not influence the inferred parameter type.","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(LogitNormal, 0.3f0, @qp_u(0.8f0), Val(:median)) #f0 indicates Float32 literals\npartype(d) == Float64","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"Parameter type, however, can be inferred from provided moments, mean, and mode.","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(Exponential, Moments(3f0)) #f0 indicates Float32 literals\npartype(d) == Float32","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(LogNormal, 3f0, @qp_uu(8))\npartype(d) == Float32","category":"page"},{"location":"partype/","page":"Parameter type","title":"Parameter type","text":"d = fit(LogNormal, 3f0, @qp_uu(8), Val(:mode))\npartype(d) == Float32","category":"page"},{"location":"","page":"Home","title":"Home","text":"CurrentModule = DistributionFits","category":"page"},{"location":"#DistributionFits","page":"Home","title":"DistributionFits","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Package DistributionFits allows fitting a distribution to a given set of aggregate statistics.","category":"page"},{"location":"","page":"Home","title":"Home","text":"to specified moments","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(LogNormal, Moments(3.0,4.0))\n(mean(d), var(d)) .≈ (3.0, 4.0)","category":"page"},{"location":"","page":"Home","title":"Home","text":"mean and upper quantile point","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(LogNormal, 3.0, @qp_uu(8))\n(mean(d), quantile(d, 0.975)) .≈ (3.0, 8.0)","category":"page"},{"location":"","page":"Home","title":"Home","text":"to mode and upper quantile point","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(LogNormal, 3.0, @qp_uu(8), Val(:mode))\n(mode(d), quantile(d, 0.975)) .≈ (3.0, 8.0)","category":"page"},{"location":"","page":"Home","title":"Home","text":"to median and upper quantile point","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(LogitNormal, 0.3, @qp_u(0.8), Val(:median))\n(median(d), quantile(d, 0.95)) .≈ (0.3, 0.8)","category":"page"},{"location":"","page":"Home","title":"Home","text":"to two quantiles, i.e confidence range","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"d = fit(Normal, @qp_ll(1.0), @qp_uu(8))\n(quantile(d, 0.025), quantile(d, 0.975)) .≈ (1.0, 8.0)","category":"page"},{"location":"","page":"Home","title":"Home","text":"approximate a different distribution by matching moments","category":"page"},{"location":"","page":"Home","title":"Home","text":"DocTestSetup = :(using Statistics,DistributionFits,Optim)","category":"page"},{"location":"","page":"Home","title":"Home","text":"dn = Normal(3,2)\nd = fit(LogNormal, moments(dn))\n(mean(d), var(d)) .≈ (3.0, 4.0)","category":"page"},{"location":"#Fit-to-statistical-moments","page":"Home","title":"Fit to statistical moments","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"fit(::Type{D}, ::AbstractMoments) where {D<:Distribution}","category":"page"},{"location":"#StatsAPI.fit-Union{Tuple{D}, Tuple{Type{D}, AbstractMoments}} where D<:Distribution","page":"Home","title":"StatsAPI.fit","text":"fit(D, m)\n\nFit a statistical distribution of type D to given moments m.\n\nArguments\n\nD: The type of distribution to fit\nm: The moments of the distribution\n\nNotes\n\nThis can be used to approximate one distribution by another.\n\nSee also AbstractMoments, moments. \n\nExamples\n\nd = fit(LogNormal, Moments(3.2,4.6));\n(mean(d), var(d)) .≈ (3.2,4.6)\n\nd = fit(LogNormal, moments(Normal(3,1.2)));\n(mean(d), std(d)) .≈ (3,1.2)\n\n# using StatsPlots\nplot(d, label = \"lognormal\", ylab=\"probability density\")\nplot!(Normal(3,1.2), label = \"normal\")\n\n\n\n\n\n","category":"method"},{"location":"#Fit-to-several-quantile-points","page":"Home","title":"Fit to several quantile points","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"fit(::Type{D}, ::QuantilePoint, ::QuantilePoint) where {D<:Distribution}","category":"page"},{"location":"#StatsAPI.fit-Union{Tuple{D}, Tuple{Type{D}, QuantilePoint, QuantilePoint}} where D<:Distribution","page":"Home","title":"StatsAPI.fit","text":"fit(D, lower::QuantilePoint, upper::QuantilePoint)\n\nFit a statistical distribution to a set of quantiles \n\nArguments\n\nD: The type of the distribution to fit\nlower: lower QuantilePoint (p,q)\nupper: upper QuantilePoint (p,q)\n\nExamples\n\nd = fit(LogNormal, @qp_m(3), @qp_uu(5));\nquantile.(d, [0.5, 0.975]) ≈ [3,5]\n\n\n\n\n\n","category":"method"},{"location":"#Fit-to-mean,-mode,-median-and-a-quantile-point","page":"Home","title":"Fit to mean, mode, median and a quantile point","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"fit(::Type{D}, ::Any, ::QuantilePoint, ::Val{stats} = Val(:mean)) where {D<:Distribution, stats}","category":"page"},{"location":"#StatsAPI.fit-Union{Tuple{stats}, Tuple{D}, Tuple{Type{D}, Any, QuantilePoint}, Tuple{Type{D}, Any, QuantilePoint, Val{stats}}} where {D<:Distribution, stats}","page":"Home","title":"StatsAPI.fit","text":"fit(D, val, qp, ::Val{stats} = Val(:mean))\n\nFit a statistical distribution to a quantile and given statistics\n\nArguments\n\nD: The type of distribution to fit\nval: The value of statistics\nqp: QuantilePoint(q,p)\nstats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)\n\nExamples\n\nd = fit(LogNormal, 5.0, @qp_uu(14));\n(mean(d),quantile(d, 0.975)) .≈ (5,14)\n\nd = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));\n(mode(d),quantile(d, 0.975)) .≈ (5,14)\n\n\n\n\n\n","category":"method"},{"location":"#Currently-supported-distributions","page":"Home","title":"Currently supported distributions","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Univariate continuous","category":"page"},{"location":"","page":"Home","title":"Home","text":"Normal\nLogNormal distribution\nLogitNormal distribution\nExponential\nLaplace\nWeibull distribution\nGamma distribution","category":"page"},{"location":"#Implementing-support-for-another-distribution","page":"Home","title":"Implementing support for another distribution","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"In order to use the fitting framework for a distribution MyDist, one needs to implement the following four methods.","category":"page"},{"location":"","page":"Home","title":"Home","text":"fit(::Type{MyDist}, m::AbstractMoments)\n\nfit_mean_quantile(::Type{MyDist}, mean, qp::QuantilePoint)\n\nfit_mode_quantile(::Type{MyDist}, mode, qp::QuantilePoint)\n\nfit(::Type{MyDist}, lower::QuantilePoint, upper::QuantilePoint)","category":"page"},{"location":"","page":"Home","title":"Home","text":"The default method for fit with stats = :median already works based on the methods for two quantile points. If the general method on two quantile points cannot be specified, one can alternatively implement method:","category":"page"},{"location":"","page":"Home","title":"Home","text":"fit_median_quantile(::Type{MyDist}, median, qp::QuantilePoint)","category":"page"},{"location":"set_optimize/","page":"Dependencies","title":"Dependencies","text":"CurrentModule = DistributionFits","category":"page"},{"location":"set_optimize/#Setting-the-optimize-configuration","page":"Dependencies","title":"Setting the optimize configuration","text":"","category":"section"},{"location":"set_optimize/","page":"Dependencies","title":"Dependencies","text":"AbstractDistributionFitOptimizer","category":"page"},{"location":"set_optimize/#DistributionFits.AbstractDistributionFitOptimizer","page":"Dependencies","title":"DistributionFits.AbstractDistributionFitOptimizer","text":"AbstractDistributionFitOptimizer\nOptimOptimizer <: AbstractDistributionFitOptimizer\nset_optimizer(::AbstractDistributionFitOptimizer)\n\nDistributionFits.jl uses the following interface to opimize an univariate function f on bounded interval [lower,upper]:\n\noptimize(f, ::AbstractDistributionFitOptimizer, lower, upper)\n\nReturning an object with fields minimizer and converged.\n\nDistributionFits.set_optimizer(::AbstractDistributionFitOptimizer) sets the specific AbstractDistributionFitOptimizer that is used throughout the package for calling the optimize function. Specializing this function with a concrete type, allows using different optimization packages. \n\nBy default, when the Optim.jl package is in scope, the OptimOptimizer is set, which implements the interface by using Optim's optimize function.\n\nHence, the module using DistributionFits.jl has to either\n\nexplicitly invoke using Optim, or\ncall set_optimizer with the concrete subtype of AbstractDistributionFitOptimizer for which the corresponding optimize method is implemented. \n\nDevelopers implementing usage of a different specific optimizer see code in ext/DistributionFitsOptimExt.\n\n\n\n\n\n","category":"type"},{"location":"weibull/","page":"Weibull","title":"Weibull","text":"CurrentModule = DistributionFits","category":"page"},{"location":"weibull/#Weibull-distribution","page":"Weibull","title":"Weibull distribution","text":"","category":"section"},{"location":"weibull/","page":"Weibull","title":"Weibull","text":"The Weibull distribution has a scale and a shape parameter. It can be fitted using two quantiles.","category":"page"},{"location":"weibull/","page":"Weibull","title":"Weibull","text":"d = fit(Weibull, @qp_m(0.5), @qp_uu(5));\nmedian(d) == 0.5 && quantile(d, 0.975) ≈ 5","category":"page"},{"location":"weibull/","page":"Weibull","title":"Weibull","text":"Fitting by mean or mode is not yet implemented.","category":"page"}] } diff --git a/dev/set_optimize/index.html b/dev/set_optimize/index.html index 8b06d0e..12622b1 100644 --- a/dev/set_optimize/index.html +++ b/dev/set_optimize/index.html @@ -1,4 +1,4 @@ Dependencies · DistributionFits.jl

Setting the optimize configuration

DistributionFits.AbstractDistributionFitOptimizerType
AbstractDistributionFitOptimizer
 OptimOptimizer <: AbstractDistributionFitOptimizer
-set_optimizer(::AbstractDistributionFitOptimizer)

DistributionFits.jl uses the following interface to opimize an univariate function f on bounded interval [lower,upper]:

optimize(f, ::AbstractDistributionFitOptimizer, lower, upper)

Returning an object with fields minimizer and converged.

DistributionFits.set_optimizer(::AbstractDistributionFitOptimizer) sets the specific AbstractDistributionFitOptimizer that is used throughout the package for calling the optimize function. Specializing this function with a concrete type, allows using different optimization packages.

By default, when the Optim.jl package is in scope, the OptimOptimizer is set, which implements the interface by using Optim's optimize function.

Hence, the module using DistributionFits.jl has to either

  • explicitly invoke using Optim, or
  • call set_optimizer with the concrete subtype of AbstractDistributionFitOptimizer for which the corresponding optimize method is implemented.

Developers implementing usage of a different specific optimizer see code in ext/DistributionFitsOptimExt.

source
+set_optimizer(::AbstractDistributionFitOptimizer)

DistributionFits.jl uses the following interface to opimize an univariate function f on bounded interval [lower,upper]:

optimize(f, ::AbstractDistributionFitOptimizer, lower, upper)

Returning an object with fields minimizer and converged.

DistributionFits.set_optimizer(::AbstractDistributionFitOptimizer) sets the specific AbstractDistributionFitOptimizer that is used throughout the package for calling the optimize function. Specializing this function with a concrete type, allows using different optimization packages.

By default, when the Optim.jl package is in scope, the OptimOptimizer is set, which implements the interface by using Optim's optimize function.

Hence, the module using DistributionFits.jl has to either

  • explicitly invoke using Optim, or
  • call set_optimizer with the concrete subtype of AbstractDistributionFitOptimizer for which the corresponding optimize method is implemented.

Developers implementing usage of a different specific optimizer see code in ext/DistributionFitsOptimExt.

source diff --git a/dev/weibull/index.html b/dev/weibull/index.html index 72d03f7..4a44e87 100644 --- a/dev/weibull/index.html +++ b/dev/weibull/index.html @@ -1,3 +1,3 @@ Weibull · DistributionFits.jl

Weibull distribution

The Weibull distribution has a scale and a shape parameter. It can be fitted using two quantiles.

d = fit(Weibull, @qp_m(0.5), @qp_uu(5));
-median(d) == 0.5 && quantile(d, 0.975) ≈ 5

Fitting by mean or mode is not yet implemented.

+median(d) == 0.5 && quantile(d, 0.975) ≈ 5

Fitting by mean or mode is not yet implemented.

diff --git a/dev/z_autodocs/index.html b/dev/z_autodocs/index.html index 641ff36..2a8055d 100644 --- a/dev/z_autodocs/index.html +++ b/dev/z_autodocs/index.html @@ -1,8 +1,8 @@ -DistributionFits · DistributionFits.jl

DistributionFits

Documentation for DistributionFits.

[comment]: # (```@autodocs)

[comment]: # (Modules = [DistributionFits])

[comment]: # (```)

taken care of in index.md called only internally from fit, documented in docstring via ","

DistributionFits.fit_median_quantileFunction
fit(D, val, qp, ::Val{stats} = Val(:mean))

Fit a statistical distribution to a quantile and given statistics

Arguments

  • D: The type of distribution to fit
  • val: The value of statistics
  • qp: QuantilePoint(q,p)
  • stats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)

Examples

d = fit(LogNormal, 5.0, @qp_uu(14));
+DistributionFits · DistributionFits.jl

DistributionFits

Documentation for DistributionFits.

[comment]: # (```@autodocs)

[comment]: # (Modules = [DistributionFits])

[comment]: # (```)

taken care of in index.md called only internally from fit, documented in docstring via ","

DistributionFits.fit_median_quantileFunction
fit(D, val, qp, ::Val{stats} = Val(:mean))

Fit a statistical distribution to a quantile and given statistics

Arguments

  • D: The type of distribution to fit
  • val: The value of statistics
  • qp: QuantilePoint(q,p)
  • stats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)

Examples

d = fit(LogNormal, 5.0, @qp_uu(14));
 (mean(d),quantile(d, 0.975)) .≈ (5,14)
d = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));
-(mode(d),quantile(d, 0.975)) .≈ (5,14)
source
DistributionFits.fit_mean_quantileFunction
fit(D, val, qp, ::Val{stats} = Val(:mean))

Fit a statistical distribution to a quantile and given statistics

Arguments

  • D: The type of distribution to fit
  • val: The value of statistics
  • qp: QuantilePoint(q,p)
  • stats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)

Examples

d = fit(LogNormal, 5.0, @qp_uu(14));
+(mode(d),quantile(d, 0.975)) .≈ (5,14)
source
DistributionFits.fit_mean_quantileFunction
fit(D, val, qp, ::Val{stats} = Val(:mean))

Fit a statistical distribution to a quantile and given statistics

Arguments

  • D: The type of distribution to fit
  • val: The value of statistics
  • qp: QuantilePoint(q,p)
  • stats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)

Examples

d = fit(LogNormal, 5.0, @qp_uu(14));
 (mean(d),quantile(d, 0.975)) .≈ (5,14)
d = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));
-(mode(d),quantile(d, 0.975)) .≈ (5,14)
source
DistributionFits.fit_mode_quantileFunction
fit(D, val, qp, ::Val{stats} = Val(:mean))

Fit a statistical distribution to a quantile and given statistics

Arguments

  • D: The type of distribution to fit
  • val: The value of statistics
  • qp: QuantilePoint(q,p)
  • stats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)

Examples

d = fit(LogNormal, 5.0, @qp_uu(14));
+(mode(d),quantile(d, 0.975)) .≈ (5,14)
source
DistributionFits.fit_mode_quantileFunction
fit(D, val, qp, ::Val{stats} = Val(:mean))

Fit a statistical distribution to a quantile and given statistics

Arguments

  • D: The type of distribution to fit
  • val: The value of statistics
  • qp: QuantilePoint(q,p)
  • stats Which statistics to fit: defaults to Val(:mean). Alternatives are: Val(:mode), Val(:median)

Examples

d = fit(LogNormal, 5.0, @qp_uu(14));
 (mean(d),quantile(d, 0.975)) .≈ (5,14)
d = fit(LogNormal, 5.0, @qp_uu(14), Val(:mode));
-(mode(d),quantile(d, 0.975)) .≈ (5,14)
source

internals

[comment]: # (fit(Type{LogNormal}, Any, AbstractΣstar))

+(mode(d),quantile(d, 0.975)) .≈ (5,14)
source

internals

[comment]: # (fit(Type{LogNormal}, Any, AbstractΣstar))