A wrapper for creating the joint distribution of multiple independent probability distributions.

Value

Returns an R6 object of class ProductDistribution.

Details

Exploits the following relationships of independent distributions $$f_P(X1 = x1,...,XN = xN) = f_{X1}(x1) * ... * f_{XN}(xn)$$ $$F_P(X1 = x1,...,XN = xN) = F_{X1}(x1) * ... * F_{XN}(xn)$$ where \(f_P\)/\(F_P\) is the pdf/cdf of the joint (product) distribution \(P\) and \(X1,...,XN\) are independent distributions.

ProductDistribution inherits all methods from Distribution and DistributionWrapper.

Constructor

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

Constructor Arguments

ArgumentTypeDetails
distlistlistList of distributions.
distributiondistributionDistribution to wrap.
paramsa R objectEither list of parameters or matrix-type frame, see examples.
namelistOptional new name for distribution.
short_namelistOptional new short_name for distribution.
descriptionlistOptional new description for distribution.

Constructor Details

A product distribution can either be constructed by a list of distributions passed to distlist or by passing the name of a distribution 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 multiple distributions but the latter is useful for quickly combining many distributions of the same type. See examples.

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
decoratorsdecorators
traitstraits
valueSupportvalueSupport
variateFormvariateForm
typetype
propertiesproperties
supportsupport
symmetrysymmetry
supsup
infinf
dmaxdmax
dmindmin
skewnessTypeskewnessType
kurtosisTypekurtosisType
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

prodBin <- ProductDistribution$new(list(Binomial$new(prob = 0.5, size = 10), Normal$new(mean = 15))) prodBin$pdf(x1 = 2, x2 =3)
#> [1] 9.43235e-34
prodBin$cdf(1:5, 12:16)
#> [1] 1.450086e-05 1.244148e-03 2.726887e-02 1.884766e-01 5.241972e-01
prodBin$quantile(c(0.1,0.2),c(0.3,0.4))
#> NULL
prodBin$rand(10)
#> Binom Norm #> 1: 2 16.66885 #> 2: 2 14.85696 #> 3: 4 16.59575 #> 4: 4 14.88856 #> 5: 5 13.91600 #> 6: 5 14.76132 #> 7: 6 13.04117 #> 8: 7 15.61909 #> 9: 4 15.33413 #> 10: 8 13.95794
prodBin = ProductDistribution$new(distribution = Binomial, params = list(list(prob = 0.1, size = 2), list(prob = 0.6, size = 4), list(prob = 0.2, size = 6))) prodBin$pdf(x1=1,x2=2,x3=3)
#> [1] 0.005096079
prodBin$cdf(x1=1,x2=2,x3=3)
#> [1] 0.5107404
prodBin$rand(10)
#> Binom1 Binom2 Binom3 #> 1: 1 2 0 #> 2: 0 3 1 #> 3: 0 2 0 #> 4: 0 2 1 #> 5: 0 0 0 #> 6: 0 2 2 #> 7: 0 3 1 #> 8: 0 3 2 #> 9: 0 2 0 #> 10: 1 3 4
#Equivalently prodBin = ProductDistribution$new(distribution = Binomial, params = data.table::data.table(prob = c(0.1,0.6,0.2), size = c(2,4,6))) prodBin$pdf(x1=1,x2=2,x3=3)
#> [1] 0.005096079
prodBin$cdf(x1=1,x2=2,x3=3)
#> [1] 0.5107404
prodBin$rand(10)
#> Binom1 Binom2 Binom3 #> 1: 0 3 1 #> 2: 0 4 0 #> 3: 1 2 2 #> 4: 0 3 2 #> 5: 0 2 2 #> 6: 0 2 3 #> 7: 0 3 2 #> 8: 0 4 1 #> 9: 0 2 1 #> 10: 1 2 1