Learn R Programming

distr6 (version 1.3.7)

ProductDistribution: Product Distribution

Description

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

Value

Returns an R6 object of class ProductDistribution.

Constructor

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

Constructor Arguments

Argument Type Details
distlist list List of distributions.
distribution distribution Distribution to wrap.
params a R object Either list of 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.

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

Variable Return
name Name of distribution.
short_name Id of distribution.
description Brief description of distribution.

Public Methods

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

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.

See Also

listWrappers and VectorDistribution

Examples

Run this code
# NOT RUN {
prodBin <- ProductDistribution$new(list(Binomial$new(prob = 0.5,
                           size = 10), Normal$new(mean = 15)))
prodBin$pdf(x1 = 2, x2 =3)
prodBin$cdf(1:5, 12:16)
prodBin$quantile(c(0.1,0.2),c(0.3,0.4))
prodBin$rand(10)

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)
prodBin$cdf(x1=1,x2=2,x3=3)
prodBin$rand(10)

#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)
prodBin$cdf(x1=1,x2=2,x3=3)
prodBin$rand(10)

# }

Run the code above in your browser using DataLab