A wrapper for creating a vector of distributions.
Returns an R6 object of class VectorDistribution.
VectorDistribution$new(distlist = NULL, distribution = NULL, params = NULL, name = NULL, short_name = NULL, description = NULL, decorators = NULL)
Argument | Type | Details |
distlist |
list | List of distributions. |
distribution |
character | Distribution to wrap. |
params |
a R object | Either list of parameters or matrix-type frame, see examples. |
shared_params |
a R object | Either list of shared parameters or matrix-type frame, see examples. |
name |
list | Optional new name for distribution. |
short_name |
list | Optional new short_name for distribution. |
description |
list | Optional new description for distribution. |
decorators |
list | Decorators to pass to wrapped distributions on construction. |
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).
Variable | Return |
name |
Name of distribution. |
short_name |
Id of distribution. |
description |
Brief description of distribution. |
Accessor Methods | Link |
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 Methods | Link |
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 Methods | Link |
prec() |
prec |
stdev() |
stdev |
median() |
median.Distribution |
iqr() |
iqr |
cor() |
cor |
Parameter Methods | Link |
parameters(id) |
parameters |
getParameterValue(id, error = "warn") |
getParameterValue |
setParameterValue(..., lst = NULL, error = "warn") |
setParameterValue |
Validation Methods | Link |
liesInSupport(x, all = TRUE, bound = FALSE) |
liesInSupport |
liesInType(x, all = TRUE, bound = FALSE) |
liesInType |
Representation Methods | Link |
strprint(n = 2) |
strprint |
print(n = 2) |
print |
summary(full = T) |
summary.Distribution |
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`.
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab