Examples
This page contains reproducible examples for AdditionalDistributions.jl, a Julia package that extends Distributions.jl with additional probability distributions.
The examples show how to use AdditionalDistributions.jl for simulation, risk modeling, count data, multivariate probabilities, hypothesis testing, copula-based modeling, and Bayesian inference with Turing.jl.
The examples are available in the examples/scripts/ directory of the repository and can be run with:
julia --project=examples examples/scripts/01_distributions_api.jlTo run all examples:
for f in examples/scripts/*.jl; do
echo ""
echo "=============================="
echo "Running $f"
echo "=============================="
julia --project=examples "$f"
doneBasic Distributions.jl interface
File:
examples/scripts/01_distributions_api.jlThis example checks that several distributions support the standard Distributions.jl interface, including pdf, logpdf, cdf, quantile, rand, and moments when available.
It includes examples such as:
Lomax(2.5, 1.0)
Burr(2.0, 3.0)
Dagum(2.0, 3.0)
Maxwell(1.5)
Gompertz(1.2, 0.8)
PERT(0.0, 0.6, 1.0)Heavy-tailed risk models
File:
examples/scripts/02_heavy_tail_risk.jlThis example uses positive heavy-tailed distributions to simulate loss models and estimate empirical risk measures such as Value-at-Risk and Expected Shortfall.
It compares models such as:
Lomax(2.2, 1_000.0)
Burr(1.6, 2.5, 1_000.0)
Dagum(2.0, 1_000.0, 1.5)Discrete count models
File:
examples/scripts/03_count_models.jlThis example illustrates count distributions such as zero-inflated and heavy-tailed discrete models.
Examples include:
ZIP(2.0, 0.35)
ZINB(5, 0.30, 0.45)
BetaNegBinomial(10, 2.0, 5.0)
Delaporte(2.0, 5.0, 0.45)
Yule(2.5)
Zeta(2.2)Some of these distributions may have infinite or undefined theoretical moments. In those cases, empirical summaries can be unstable for moderate sample sizes, which is expected for heavy-tailed count models.
Multivariate Gaussian rectangular probabilities
File:
examples/scripts/04_mvgaussian_cdf.jlThis example computes a rectangular probability for a multivariate Gaussian distribution:
res = cdf_result(
d,
lower,
upper;
rng=rng,
m=100_000,
abseps=1e-5,
releps=1e-5,
)The returned object includes the estimated probability, an error estimate, the number of evaluations, an algorithm label, and an inform flag.
Multivariate Student-t rectangular probabilities
File:
examples/scripts/05_mvstudent_cdf.jlThis example computes a rectangular probability for a multivariate Student-t distribution using randomized quasi-Monte Carlo integration.
The multivariate Student-t case is handled differently from the Gaussian case because the common radial scale induces dependence even when the scale matrix is diagonal.
HypothesisTests.jl workflows
File:
examples/scripts/06_hypothesistests.jlThis example shows two workflows.
First, it compares two positive heavy-tailed samples using classical univariate tests:
ApproximateTwoSampleKSTest(x, y)
MannWhitneyUTest(x, y)Second, it uses simulated multivariate Gaussian samples together with multivariate tests from HypothesisTests.jl:
UnequalCovHotellingT2Test(X, Y)
EqualCovHotellingT2Test(X, Y)
BartlettTest(X, Y)This demonstrates how MvGaussian samples from AdditionalDistributions.jl can be used directly in downstream statistical testing workflows.
Copulas.jl and SklarDist
File:
examples/scripts/07_copulas_sklar.jlThis example builds a joint distribution using a Gaussian copula and marginal distributions from AdditionalDistributions.jl:
C = GaussianCopula(Σ)
marginals = (
Burr(1.6, 2.5, 1_000.0),
Dagum(2.0, 1_000.0, 1.5),
)
joint = SklarDist(C, marginals)It then simulates from the joint model and estimates marginal summaries, rank correlation, and the probability of a joint upper-tail event.
Turing.jl Bayesian model
File:
examples/scripts/08_turing_model.jlThis example uses Maxwell inside a Bayesian model defined with Turing.jl:
@model function maxwell_model(x)
σ ~ truncated(Normal(1.5, 0.5), 0.1, 5.0)
for i in eachindex(x)
x[i] ~ Maxwell(σ)
end
endA short NUTS chain recovers the true scale parameter from simulated data, illustrating compatibility with probabilistic programming workflows.