A wrapper for creating a vector of distributions.

Value

Returns an R6 object of class VectorDistribution.

Details

A vector distribution is intented to vectorize distributions more efficiently than storing a list of distributions. To improve speed and reduce memory usage, distributions are only constructed when methods (e.g. d/p/q/r) are called. Whilst it is recommended to first extract distributions using [ before querying them for results, all common methods are available in VectorDistribution as they are wrapped in apply.

Constructor

VectorDistribution$new(distlist = NULL, distribution = NULL, params = NULL, name = NULL, short_name = NULL, description = NULL, decorators = NULL)

Constructor Arguments

ArgumentTypeDetails
distlistlistList of distributions.
distributioncharacterDistribution to wrap.
paramsa R objectEither list of parameters or matrix-type frame, see examples.
shared_paramsa R objectEither list of shared parameters or matrix-type frame, see examples.
namelistOptional new name for distribution.
short_namelistOptional new short_name for distribution.
descriptionlistOptional new description for distribution.
decoratorslistDecorators to pass to wrapped distributions on construction.

Constructor Details

A vector distribution can either be constructed by a list of distributions passed to distlist or by passing the name of one or more distributions implemented in distr6 to distribution, as well as a list or table of parameters to params. The former case provides more flexibility in the ability to use wrapped distributions but the latter is vastly faster for distributions of class SDistribution or custom distributions. The shared_params parameter decreases memory usage and improves speed by storing any parameters shared between distributions only once (instead of repeated in a list).

Public Variables

VariableReturn
nameName of distribution.
short_nameId of distribution.
descriptionBrief description of distribution.
packageThe package d/p/q/r are implemented in.

Public Methods

Accessor MethodsLink
wrappedModels(model = NULL)wrappedModels
decorators()decorators
traits()traits
valueSupport()valueSupport
variateForm()variateForm
type()type
properties()properties
support()support
symmetry()symmetry
sup()sup
inf()inf
dmax()dmax
dmin()dmin
skewnessType()skewnessType
kurtosisType()kurtosisType
d/p/q/r MethodsLink
pdf(x1, ..., log = FALSE, simplify = TRUE)pdf
cdf(x1, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE)cdf
quantile(p, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE)quantile.Distribution
rand(n, simplify = TRUE)rand
Statistical MethodsLink
prec()prec
stdev()stdev
median()median.Distribution
iqr()iqr
cor()cor
Parameter MethodsLink
parameters(id)parameters
getParameterValue(id, error = "warn")getParameterValue
setParameterValue(..., lst = NULL, error = "warn")setParameterValue
Validation MethodsLink
liesInSupport(x, all = TRUE, bound = FALSE)liesInSupport
liesInType(x, all = TRUE, bound = FALSE)liesInType
Representation MethodsLink
strprint(n = 2)strprint
print(n = 2)print
summary(full = T)summary.Distribution

See also

Examples

# not run to save time if (FALSE) { vecDist <- VectorDistribution$new(list(Binomial$new(prob = 0.5, size = 10), Normal$new(mean = 15))) vecDist$pdf(x1 = 2, x2 =3) # Equivalently vecDist[1]$pdf(2); vecDist[2]$pdf(3) # Or to evaluate every distribution at the same point vecDist$pdf(1) # Same wrapping for statistical functions vecDist$mean() c(vecDist[1]$mean(), vecDist[2]$mean()) vecDist$entropy() c(vecDist[1]$entropy(), vecDist[2]$entropy()) vecDist$cdf(1:5, 12:16) vecDist$rand(10) vecBin = VectorDistribution$new(distribution = "Binomial", params = list(list(prob = 0.1, size = 2), list(prob = 0.6, size = 4), list(prob = 0.2, size = 6))) vecBin$pdf(x1=1,x2=2,x3=3) vecBin$cdf(x1=1,x2=2,x3=3) vecBin$rand(10) #Equivalently vecBin = VectorDistribution$new(distribution = "Binomial", params = data.table::data.table(prob = c(0.1,0.6,0.2), size = c(2,4,6))) vecBin$pdf(x1=1,x2=2,x3=3) vecBin$cdf(x1=1,x2=2,x3=3) vecBin$rand(10) # sharedparams is very useful for vectorized custom distributions shared_params = list(name = "A Distribution", short_name = "Dist", type = Reals$new()) params = list(list(pdf = function(x) return(1)), list(pdf = function(x) return(2))) vecdist = VectorDistribution$new(distribution = "Distribution", params = params, shared_params = shared_params) vecdist$pdf(1) }