Skip to content
1

Internal Documentation

Documentation for ForecastEnsembles's internal interface.

Contents

Index

Internal API

ForecastEnsembles.QuantileDistribution Type
julia
QuantileDistribution(probs, vals)

A 1-D distribution reconstructed from the (probability, value) quantile pairs probs and vals. probs must be strictly increasing in (0,1); vals must be non-decreasing and the same length.

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::QuantileDistribution, x)

Return P(X ≤ x).

source
ForecastEnsembles.from_samples Function
julia
from_samples(df; task_id_cols = nothing,
              model_col = :model, sample_col = :sample, value_col = :predicted)
-> ForecastTable

Convert a sample-shaped frame (one row per draw) to a ForecastTable with output_type = :sample. Mirrors the input expected by lopensemble::mixture_from_samples.

source
ForecastEnsembles.from_scoringutils Function
julia
from_scoringutils(df; task_id_cols = nothing) -> ForecastTable

Convert a scoringutils::forecast_quantile-shaped frame (columns model, quantile_level, predicted, plus task vars) to a ForecastTable with output_type = :quantile.

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::QuantileDistribution, u)

Return the value of d at probability u ∈ (0,1).

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, d::QuantileDistribution, n)

Draw n samples from d by inverse-CDF sampling.

source