Internal Documentation
Documentation for ForecastEnsembles's internal interface.
Contents
Index
ForecastEnsembles.QuantileDistributionBase.randDistributions.cdfForecastEnsembles.from_samplesForecastEnsembles.from_scoringutilsStatistics.quantile
Internal API
ForecastEnsembles.QuantileDistribution Type
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.
Distributions.cdf Function
cdf(d::UnivariateDistribution, x::Real)Evaluate the cumulative probability at x.
See also ccdf, logcdf, and logccdf.
cdf(d::QuantileDistribution, x)Return P(X ≤ x).
sourceForecastEnsembles.from_samples Function
from_samples(df; task_id_cols = nothing,
model_col = :model, sample_col = :sample, value_col = :predicted)
-> ForecastTableConvert a sample-shaped frame (one row per draw) to a ForecastTable with output_type = :sample. Mirrors the input expected by lopensemble::mixture_from_samples.
ForecastEnsembles.from_scoringutils Function
from_scoringutils(df; task_id_cols = nothing) -> ForecastTableConvert a scoringutils::forecast_quantile-shaped frame (columns model, quantile_level, predicted, plus task vars) to a ForecastTable with output_type = :quantile.
Statistics.quantile Function
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.
quantile(d::QuantileDistribution, u)Return the value of d at probability u ∈ (0,1).
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=1Def. 5:
alpha=0.5,beta=0.5(MATLAB default)Def. 6:
alpha=0,beta=0(ExcelPERCENTILE.EXC, Python default, Stataaltdef)Def. 7:
alpha=1,beta=1(Julia, R and NumPy default, ExcelPERCENTILEandPERCENTILE.INC, Python'inclusive')Def. 8:
alpha=1/3,beta=1/3Def. 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> 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.5Base.rand Function
rand([rng::AbstractRNG,] s::Sampleable)Generate one sample for s.
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
sis univariate, it returns a vector of lengthn.When
sis multivariate, it returns a matrix withncolumns.When
sis 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.
rand(rng::AbstractRNG, d::UnivariateDistribution)Generate a scalar sample from d. The general fallback is quantile(d, rand()).
rand(::AbstractRNG, ::Distributions.AbstractMvNormal)Sample a random vector from the provided multi-variate normal distribution.
sourcerand(::AbstractRNG, ::Sampleable)Samples from the sampler and returns the result.
sourcerand(d::Union{UnivariateMixture, MultivariateMixture})Draw a sample from the mixture model d.
rand(d::Union{UnivariateMixture, MultivariateMixture}, n)Draw n samples from d.
rand(rng, d::QuantileDistribution, n)Draw n samples from d by inverse-CDF sampling.