Skip to content

Internal Documentation

Documentation for ModifiedDistributions's internal interface.

Contents

Index

Internal API

Distributions.ccdf Function
julia
ccdf(d::UnivariateDistribution, x::Real)

The complementary cumulative function evaluated at x, i.e. 1 - cdf(d, x).

source
julia
ccdf(d::ModifiedDistributions.Affine, y::Real) -> Any

Compute the complementary cumulative distribution function via change of variables (avoids the 1 - cdf fallback, keeping precision in the upper tail).

See also: cdf, logccdf

source
julia
ccdf(
    d::ModifiedDistributions.Affine,
    y::AbstractVector{<:Real}
) -> Any

Compute the complementary cumulative distribution function for a vector of observations, per point (a single batched inner call when available).

See also: ccdf

source
julia
ccdf(d::ModifiedDistributions.Weighted, x::Real) -> Any

Compute the complementary cumulative distribution function (delegates to underlying distribution).

See also: cdf

source
julia
ccdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Union{Function, Real}},
    x::Real
) -> Any

Compute the complementary cumulative distribution function.

See also: logccdf

source
julia
ccdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Discrete}, <:AbstractVector},
    x::Real
) -> Any

Compute the complementary cumulative distribution on the discrete per-bin path.

See also: cdf

source
Distributions.cdf Function
julia
cdf(d::UnivariateDistribution, x::Real)

Evaluate the cumulative probability at x.

See also ccdf, logcdf, and logccdf.

source
julia
cdf(d::ModifiedDistributions.Affine, y::Real) -> Any

Compute the cumulative distribution function.

See also: logcdf, quantile

source
julia
cdf(
    d::ModifiedDistributions.Affine,
    y::AbstractVector{<:Real}
) -> Any

Compute the cumulative distribution function for a vector of observations, per point (a single batched inner call when available).

See also: cdf

source
julia
cdf(d::ModifiedDistributions.Weighted, x::Real) -> Any

Compute the cumulative distribution function (delegates to underlying distribution).

See also: logcdf

source
julia
cdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Union{Function, Real}},
    x::Real
) -> Any

Compute the cumulative distribution function.

See also: ccdf, logcdf

source
julia
cdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Discrete}, <:AbstractVector},
    x::Real
) -> Any

Compute the cumulative distribution function on the discrete per-bin path.

See also: logcdf

source
ModifiedDistributions.combine_weights Function
julia
combine_weights(_::Missing, _::Missing) -> Missing

Combine constructor weight with observation weight using dispatch-based rules.

Weight combination rules:

  • missing, missing → missing (both missing means no weight)

  • w1, missing → w1 (use constructor weight)

  • missing, w2 → w2 (use observation weight)

  • w1, w2 → w1 * w2 (multiply weights)

Vector Extensions

For Product distributions, additional methods handle vectorised weight combinations:

  • Vector, Vector → combine_weights.(vector1, vector2) (element-wise combination)

  • Vector, missing → Vector (keep constructor weights)

  • Vector, scalar → [combine_weights(w, scalar) for w in Vector] (broadcast scalar)

source
Distributions.logccdf Function
julia
logccdf(d::UnivariateDistribution, x::Real)

The logarithm of the complementary cumulative function values evaluated at x, i.e. log(ccdf(x)).

source
julia
logccdf(d::ModifiedDistributions.Affine, y::Real) -> Any

Compute the log complementary cumulative distribution function.

See also: ccdf

source
julia
logccdf(
    d::ModifiedDistributions.Affine,
    y::AbstractVector{<:Real}
) -> Any

Compute the log complementary cumulative distribution function for a vector of observations, per point (a single batched inner call when available).

See also: logccdf

source
julia
logccdf(d::ModifiedDistributions.Weighted, x::Real) -> Any

Compute the log complementary cumulative distribution function (delegates to underlying distribution).

See also: logcdf

source
julia
logccdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real, ModifiedDistributions.HazardLink{typeof(log), typeof(exp)}},
    x::Real
) -> Any

Compute the log survival function on the proportional-hazards path.

See also: ccdf, logpdf

source
julia
logccdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real, ModifiedDistributions.HazardLink{typeof(identity), typeof(identity)}},
    x::Real
) -> Any

Compute the log survival function on the additive-hazards path.

See also: ccdf, logpdf

source
julia
logccdf(
    d::Union{ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Function}, ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real}},
    x::Real
) -> Any

Compute the log survival function on the numeric cumulative-hazard path.

See also: ccdf, logpdf

source
julia
logccdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Discrete}, <:AbstractVector},
    x::Real
)

Compute the log complementary cumulative distribution on the discrete per-bin path.

See also: ccdf

source
Distributions.logcdf Function
julia
logcdf(d::UnivariateDistribution, x::Real)

The logarithm of the cumulative function value(s) evaluated at x, i.e. log(cdf(x)).

source
julia
logcdf(d::ModifiedDistributions.Affine, y::Real) -> Any

Compute the log cumulative distribution function.

See also: cdf

source
julia
logcdf(
    d::ModifiedDistributions.Affine,
    y::AbstractVector{<:Real}
) -> Any

Compute the log cumulative distribution function for a vector of observations, per point (a single batched inner call when available).

See also: logcdf

source
julia
logcdf(d::ModifiedDistributions.Weighted, x::Real) -> Any

Compute the log cumulative distribution function (delegates to underlying distribution).

See also: cdf

source
julia
logcdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Union{Function, Real}},
    x::Real
) -> Any

Compute the log cumulative distribution function.

See also: cdf

source
julia
logcdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Discrete}, <:AbstractVector},
    x::Real
) -> Any

Compute the log cumulative distribution on the discrete per-bin path.

See also: cdf

source
StatsAPI.loglikelihood Function
julia
loglikelihood(model::StatisticalModel)
loglikelihood(model::StatisticalModel, observation)

Return the log-likelihood of the model.

With an observation argument, return the contribution of observation to the log-likelihood of model.

If observation is a Colon, return a vector of each observation's contribution to the log-likelihood of the model. In other words, this is the vector of the pointwise log-likelihood contributions.

In general, sum(loglikehood(model, :)) == loglikelihood(model).

source
Distributions.logpdf Function
julia
logpdf(d::Distribution{ArrayLikeVariate{N}}, x::AbstractArray{<:Real,N}) where {N}

Evaluate the logarithm of the probability density function of d at x.

This function checks if the size of x is compatible with distribution d. This check can be disabled by using @inbounds.

Implementation

Instead of logpdf one should implement _logpdf(d, x) which does not have to check the size of x.

See also: pdf, gradlogpdf.

source
julia
logpdf(d::Distribution{ArrayLikeVariate{N}}, x) where {N}

Evaluate the logarithm of the probability density function of d at every element in a collection x.

This function checks for every element of x if its size is compatible with distribution d. This check can be disabled by using @inbounds.

Here, x can be

  • an array of dimension > N with size(x)[1:N] == size(d), or

  • an array of arrays xi of dimension N with size(xi) == size(d).

source
julia
logpdf(d::UnivariateDistribution, x::Real)

Evaluate the logarithm of probability density (mass) at x.

See also: pdf.

source
julia
logpdf(d::Union{UnivariateMixture, MultivariateMixture}, x)

Evaluate the logarithm of the (mixed) probability density function over x. Here, x can be a single sample or an array of multiple samples.

source
julia
logpdf(d::ModifiedDistributions.Affine, y::Real) -> Any

Compute the log probability density function via change of variables. For a continuous inner distribution this includes the log-Jacobian -log(scale); for a discrete inner distribution the mass transforms without it.

See also: pdf, cdf

source
julia
logpdf(
    d::ModifiedDistributions.Affine,
    y::AbstractVector{<:Real}
) -> Any

Compute the log probability density for a vector of observations, per point.

The whole transformed batch reaches the inner distribution in one call when it provides a batched logpdf, then the log-Jacobian -log(scale) applies elementwise (continuous inner distributions only). A vector observation on a modifier is per-point (a vector result), unlike the Product{<:Weighted} joint-scalar convention.

See also: pdf

source
julia
logpdf(d::ModifiedDistributions.Weighted, x::Real) -> Any

Return the weighted log-probability for scalar observations.

See also: pdf

source
julia
logpdf(
    d::ModifiedDistributions.Weighted,
    x::AbstractVector{<:Real}
) -> Any

Return the weighted log-probability for a vector of observations, per point.

The whole batch reaches the base distribution in one logpdf call when it provides a batched implementation, then the weight applies elementwise with the scalar missing/zero-weight sentinel semantics (-Inf per point, AD-safe promoted eltype). A vector observation on a single Weighted is per-point (a vector result), unlike the Product{<:Weighted} joint-scalar convention.

See also: pdf

source
julia
logpdf(
    d::ModifiedDistributions.Weighted,
    obs::NamedTuple{(:value, :weight)}
) -> Any

Return the weighted log-probability for joint observations as NamedTuple.

Combines constructor weight with observation weight via multiplication. Expected format: (value = x, weight = w).

See also: pdf

source
julia
logpdf(
    d::Distributions.Product{<:Distributions.ValueSupport, <:ModifiedDistributions.Weighted, <:AbstractVector{<:ModifiedDistributions.Weighted}},
    obs::NamedTuple{(:values, :weights)}
) -> Any

Efficient vectorised log-probability computation for Product{<:ValueSupport, <:Weighted} with joint observations.

Handles joint observations and weight stacking. Expected format: (values = [...], weights = [...]).

See also: logpdf

source
julia
logpdf(
    d::Distributions.Product{<:Distributions.ValueSupport, <:ModifiedDistributions.Weighted, <:AbstractVector{<:ModifiedDistributions.Weighted}},
    x::AbstractVector{<:Real}
) -> Any

Efficient vectorised log-probability computation for Product{<:ValueSupport, <:Weighted} with vector observations.

See also: logpdf

source
julia
logpdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real, ModifiedDistributions.HazardLink{typeof(log), typeof(exp)}},
    x::Real
) -> Any

Compute the log probability density on the proportional-hazards path.

See also: pdf, ccdf

source
julia
logpdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real, ModifiedDistributions.HazardLink{typeof(identity), typeof(identity)}},
    x::Real
) -> Any

Compute the log probability density on the additive-hazards path.

See also: pdf, ccdf

source
julia
logpdf(
    d::Union{ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Function}, ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real}},
    x::Real
) -> Any

Compute the log probability density on the numeric cumulative-hazard path.

See also: pdf, ccdf

source
julia
logpdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Discrete}, <:AbstractVector},
    x::Real
)

Compute the log probability mass on the discrete per-bin path.

See also: pdf

source
Statistics.mean Method
julia
mean(d::ModifiedDistributions.Affine) -> Any

Compute the mean via the affine transform of the inner mean.

See also: var

source
Distributions.pdf Function
julia
pdf(d::Distribution{ArrayLikeVariate{N}}, x::AbstractArray{<:Real,N}) where {N}

Evaluate the probability density function of d at x.

This function checks if the size of x is compatible with distribution d. This check can be disabled by using @inbounds.

Implementation

Instead of pdf one should implement _pdf(d, x) which does not have to check the size of x. However, since the default definition of pdf(d, x) falls back to logpdf(d, x) usually it is sufficient to implement logpdf.

See also: logpdf.

source
julia
pdf(d::Distribution{ArrayLikeVariate{N}}, x) where {N}

Evaluate the probability density function of d at every element in a collection x.

This function checks for every element of x if its size is compatible with distribution d. This check can be disabled by using @inbounds.

Here, x can be

  • an array of dimension > N with size(x)[1:N] == size(d), or

  • an array of arrays xi of dimension N with size(xi) == size(d).

source
julia
pdf(d::UnivariateDistribution, x::Real)

Evaluate the probability density (mass) at x.

See also: logpdf.

source
julia
pdf(d::Union{UnivariateMixture, MultivariateMixture}, x)

Evaluate the (mixed) probability density function over x. Here, x can be a single sample or an array of multiple samples.

source
julia
pdf(d::ModifiedDistributions.Affine, y::Real) -> Any

Compute the probability density function.

See also: logpdf

source
julia
pdf(
    d::ModifiedDistributions.Affine,
    y::AbstractVector{<:Real}
) -> Any

Compute the probability density for a vector of observations, per point (one batched inner call through the vector logpdf).

See also: logpdf

source
julia
pdf(d::ModifiedDistributions.Weighted, x::Real) -> Any

Return the probability density from the underlying distribution (unweighted).

See also: logpdf

source
julia
pdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Union{Function, Real}},
    x::Real
) -> Any

Compute the probability density function.

See also: logpdf

source
julia
pdf(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Discrete}, <:AbstractVector},
    x::Real
) -> Any

Compute the probability mass for the bin containing x on the discrete per-bin reporting-hazard path.

See also: logpdf, cdf

source
Statistics.quantile Function
julia
quantile(d::UnivariateDistribution, q::Real)

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 for which cdf(d, x) ≥ q.

See also: cquantile, invlogcdf, and invlogccdf.

source
julia
quantile(d::ModifiedDistributions.Affine, p::Real) -> Any

Compute the quantile function (inverse CDF).

See also: cdf

source
julia
quantile(d::ModifiedDistributions.Weighted, p::Real) -> Any

Compute the quantile function (delegates to underlying distribution).

See also: cdf

source
julia
quantile(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real, ModifiedDistributions.HazardLink{typeof(log), typeof(exp)}},
    p::Real
) -> Any

Compute the quantile by closed-form inversion of the modified survival.

See also: cdf

source
julia
quantile(
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real, ModifiedDistributions.HazardLink{typeof(identity), typeof(identity)}},
    p::Real
) -> Any

Compute the quantile by monotone bisection of the modified CDF.

A non-negative additive effect only speeds events up, so the modified quantile sits between the support minimum and the base quantile. A negative additive effect widens the law and can leave it defective (its cdf converges below one); when the requested p exceeds the total mass the quantile is undefined and this throws an ArgumentError rather than returning a garbage bracket.

See also: cdf

source
julia
quantile(itr, p; sorted=false, alpha::Real=1.0, beta::Real=alpha)

Compute the quantile(s) of a collection itr at a specified probability or vector or tuple of probabilities p on the interval [0,1]. The keyword argument sorted indicates whether itr can be assumed to be sorted.

Samples quantile are defined by Q(p) = (1-γ)*x[j] + γ*x[j+1], where x[j] is the j-th order statistic of itr, j = floor(n*p + m), m = alpha + p*(1 - alpha - beta) and γ = n*p + m - j.

By default (alpha = beta = 1), quantiles are computed via linear interpolation between the points ((k-1)/(n-1), x[k]), for k = 1:n where n = length(itr). This corresponds to Definition 7 of Hyndman and Fan (1996), and is the same as the R and NumPy default.

The keyword arguments alpha and beta correspond to the same parameters in Hyndman and Fan, setting them to different values allows to calculate quantiles with any of the methods 4-9 defined in this paper:

  • Def. 4: alpha=0, beta=1

  • Def. 5: alpha=0.5, beta=0.5 (MATLAB default)

  • Def. 6: alpha=0, beta=0 (Excel PERCENTILE.EXC, Python default, Stata altdef)

  • Def. 7: alpha=1, beta=1 (Julia, R and NumPy default, Excel PERCENTILE and PERCENTILE.INC, Python 'inclusive')

  • Def. 8: alpha=1/3, beta=1/3

  • Def. 9: alpha=3/8, beta=3/8

Note

An ArgumentError is thrown if v contains NaN or missing values. Use the skipmissing function to omit missing entries and compute the quantiles of non-missing values.

References

  • Hyndman, R.J and Fan, Y. (1996) "Sample Quantiles in Statistical Packages", The American Statistician, Vol. 50, No. 4, pp. 361-365

  • Quantile on Wikipedia details the different quantile definitions

Examples

julia
julia> using Statistics

julia> quantile(0:20, 0.5)
10.0

julia> quantile(0:20, [0.1, 0.5, 0.9])
3-element Vector{Float64}:
  2.0
 10.0
 18.000000000000004

julia> quantile(skipmissing([1, 10, missing]), 0.5)
5.5
source
Base.rand Function
julia
rand([rng::AbstractRNG,] s::Sampleable)

Generate one sample for s.

julia
rand([rng::AbstractRNG,] s::Sampleable, n::Int)

Generate n samples from s. The form of the returned object depends on the variate form of s:

  • When s is univariate, it returns a vector of length n.

  • When s is multivariate, it returns a matrix with n columns.

  • When s is matrix-variate, it returns an array, where each element is a sample matrix. rand([rng::AbstractRNG,] s::Sampleable, dim1::Int, dim2::Int...) rand([rng::AbstractRNG,] s::Sampleable, dims::Dims)

Generate an array of samples from s whose shape is determined by the given dimensions.

source
julia
rand(rng::AbstractRNG, d::UnivariateDistribution)

Generate a scalar sample from d. The general fallback is quantile(d, rand()).

source
julia
rand(::AbstractRNG, ::Distributions.AbstractMvNormal)

Sample a random vector from the provided multi-variate normal distribution.

source
julia
rand(::AbstractRNG, ::Sampleable)

Samples from the sampler and returns the result.

source
julia
rand(d::Union{UnivariateMixture, MultivariateMixture})

Draw a sample from the mixture model d.

julia
rand(d::Union{UnivariateMixture, MultivariateMixture}, n)

Draw n samples from d.

source
julia
rand(
    rng::Random.AbstractRNG,
    d::ModifiedDistributions.Affine
) -> Any

Generate a random sample by transforming an inner draw.

See also: quantile

source
julia
rand(
    rng::Random.AbstractRNG,
    d::ModifiedDistributions.Weighted
) -> Any

Generate a random sample (delegates to underlying distribution).

See also: quantile

source
julia
rand(
    rng::Random.AbstractRNG,
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Continuous}, <:Real, ModifiedDistributions.HazardLink{typeof(log), typeof(exp)}}
) -> Any

Generate a random sample by closed-form inversion of the modified survival.

See also: quantile

source
julia
rand(
    rng::Random.AbstractRNG,
    d::ModifiedDistributions.Modified{<:Distributions.Distribution{Distributions.Univariate, Distributions.Discrete}, <:AbstractVector}
)

Generate a random sample by inversion of the reconstructed PMF.

See also: pdf

source
Statistics.var Method
julia
var(d::ModifiedDistributions.Affine) -> Any

Compute the variance via the affine transform of the inner variance.

See also: mean

source