Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify definitions of inverse CDF functions #1814

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/univariates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ std(d::UnivariateDistribution) = sqrt(var(d))
"""
median(d::UnivariateDistribution)

Return the median value of distribution `d`. The median is the smallest `x` such that `cdf(d, x) ≥ 1/2`.
Return the median value of distribution `d`. The median is the smallest `x` in the support
of `d` for which `cdf(d, x) ≥ 1/2`.
Corresponding to this definition as 1/2-quantile, a fallback is provided calling the `quantile` function.
"""
median(d::UnivariateDistribution) = quantile(d, 1//2)
Expand Down Expand Up @@ -381,7 +382,10 @@ logccdf(d::UnivariateDistribution, x::Real) = log(ccdf(d, x))
"""
quantile(d::UnivariateDistribution, q::Real)

Evaluate the inverse cumulative distribution function at `q`.
Evaluate the (generalized) inverse cumulative distribution function at `q`.

For a given `0 ≤ q ≤ 1`, `quantile(d, q)` is the smallest value `x` in the support of `d`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think it good to include the accurate definition, I feel like it would be helpful to state the simplified version before stating the precise but also more complicated definition. For most people, in most situations, the simple but slightly inaccurate definitions is probably more helpful. For the same reason, maybe put "generalized" in parentheses as many people might not know what it means. Same comment applies to the other changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

for which `cdf(d, x) ≥ q`.

See also: [`cquantile`](@ref), [`invlogcdf`](@ref), and [`invlogccdf`](@ref).
"""
Expand All @@ -397,14 +401,20 @@ cquantile(d::UnivariateDistribution, p::Real) = quantile(d, 1.0 - p)
"""
invlogcdf(d::UnivariateDistribution, lp::Real)

The inverse function of logcdf.
The (generalized) inverse function of [`logcdf`](@ref).

For a given `lp ≤ 0`, `invlogcdf(d, lp)` is the smallest value `x` in the support of `d` for
which `logcdf(d, x) ≥ lp`.
"""
invlogcdf(d::UnivariateDistribution, lp::Real) = quantile(d, exp(lp))

"""
invlogccdf(d::UnivariateDistribution, lp::Real)

The inverse function of logccdf.
The (generalized) inverse function of [`logccdf`](@ref).

For a given `lp ≤ 0`, `invlogccdf(d, lp)` is the smallest value `x` in the support of `d`
for which `logccdf(d, x) ≤ lp`.
"""
invlogccdf(d::UnivariateDistribution, lp::Real) = quantile(d, -expm1(lp))

Expand Down
Loading