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

# S3 method for Distribution
*(x, y)

## Arguments

x, y Distribution

## Details

A product distribution is defined by

$$F_P(X1 = x1,...,XN = xN) = F_{X1}(x1) * ... * F_{XN}(xn)$$ #nolint where $$F_P$$ is the cdf of the product distribution and $$X1,...,XN$$ are independent distributions.

Other wrappers: Convolution, DistributionWrapper, HuberizedDistribution, MixtureDistribution, TruncatedDistribution, VectorDistribution

## Super classes

distr6::Distribution -> distr6::DistributionWrapper -> distr6::VectorDistribution -> ProductDistribution

## Methods

### Public methods

Inherited methods

### Method new()

Creates a new instance of this R6 class.

ProductDistribution$new( distlist = NULL, distribution = NULL, params = NULL, shared_params = NULL, name = NULL, short_name = NULL, decorators = NULL, vecdist = NULL ) #### Arguments distlist (list()) List of Distributions. distribution (character(1)) Should be supplied with params and optionally shared_params as an alternative to distlist. Much faster implementation when only one class of distribution is being wrapped. distribution is the full name of one of the distributions in listDistributions(), or "Distribution" if constructing custom distributions. See examples in VectorDistribution. params (list()|data.frame()) Parameters in the individual distributions for use with distribution. Can be supplied as a list, where each element is the list of parameters to set in the distribution, or as an object coercable to data.frame, where each column is a parameter and each row is a distribution. See examples in VectorDistribution. shared_params (list()) If any parameters are shared when using the distribution constructor, this provides a much faster implementation to list and query them together. See examples in VectorDistribution. name (character(1)) Optional name of wrapped distribution. short_name (character(1)) Optional short name/ID of wrapped distribution. decorators (character()) Decorators to add to the distribution during construction. vecdist VectorDistribution Alternative constructor to directly create this object from an object inheriting from VectorDistribution. #### Examples \dontrun{ ProductDistribution$new(list(Binomial$new( prob = 0.5, size = 10 ), Normal$new(mean = 15)))

ProductDistribution$new( distribution = "Binomial", params = list( list(prob = 0.1, size = 2), list(prob = 0.6, size = 4), list(prob = 0.2, size = 6) ) ) # Equivalently ProductDistribution$new(
distribution = "Binomial",
params = data.table::data.table(prob = c(0.1, 0.6, 0.2), size = c(2, 4, 6))
)
}


### Method strprint()

Printable string representation of the ProductDistribution. Primarily used internally.

#### Arguments

...

(numeric())
Points to evaluate the function at Arguments do not need to be named. The length of each argument corresponds to the number of points to evaluate, the number of arguments corresponds to the number of variables in the distribution. See examples.

log

(logical(1))
If TRUE returns the logarithm of the probabilities. Default is FALSE.

simplify

logical(1)
If TRUE (default) simplifies the return if possible to a numeric, otherwise returns a data.table::data.table.

data

array
Alternative method to specify points to evaluate. If univariate then rows correspond with number of points to evaluate and columns correspond with number of variables to evaluate. In the special case of VectorDistributions of multivariate distributions, then the third dimension corresponds to the distribution in the vector to evaluate.

#### Examples

p <- ProductDistribution$new(list( Binomial$new(prob = 0.5, size = 10),
Binomial$new())) p$pdf(1:5)
p$pdf(1, 2) p$pdf(1:2)


### Method cdf()

Cumulative distribution function of the product distribution. Computed by $$F_P(X1 = x1,...,XN = xN) = \prod_{i} F_{Xi}(xi)$$ where $$F_{Xi}$$ are the cdfs of the wrapped distributions.

ProductDistribution$cdf( ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE, data = NULL ) #### Arguments ... (numeric()) Points to evaluate the function at Arguments do not need to be named. The length of each argument corresponds to the number of points to evaluate, the number of arguments corresponds to the number of variables in the distribution. See examples. lower.tail (logical(1)) If TRUE (default), probabilities are X <= x, otherwise, P(X > x). log.p (logical(1)) If TRUE returns the logarithm of the probabilities. Default is FALSE. simplify logical(1) If TRUE (default) simplifies the return if possible to a numeric, otherwise returns a data.table::data.table. data array Alternative method to specify points to evaluate. If univariate then rows correspond with number of points to evaluate and columns correspond with number of variables to evaluate. In the special case of VectorDistributions of multivariate distributions, then the third dimension corresponds to the distribution in the vector to evaluate. #### Examples p <- ProductDistribution$new(list(
Binomial$new(prob = 0.5, size = 10), Binomial$new()))
p$cdf(1:5) p$cdf(1, 2)
p$cdf(1:2)  ### Method quantile() The quantile function is not implemented for product distributions. #### Usage ProductDistribution$quantile(
...,
lower.tail = TRUE,
log.p = FALSE,
simplify = TRUE,
data = NULL
)

#### Arguments

...

(numeric())
Points to evaluate the function at Arguments do not need to be named. The length of each argument corresponds to the number of points to evaluate, the number of arguments corresponds to the number of variables in the distribution. See examples.

lower.tail

(logical(1))
If TRUE (default), probabilities are X <= x, otherwise, P(X > x).

log.p

(logical(1))
If TRUE returns the logarithm of the probabilities. Default is FALSE.

simplify

logical(1)
If TRUE (default) simplifies the return if possible to a numeric, otherwise returns a data.table::data.table.

data

array
Alternative method to specify points to evaluate. If univariate then rows correspond with number of points to evaluate and columns correspond with number of variables to evaluate. In the special case of VectorDistributions of multivariate distributions, then the third dimension corresponds to the distribution in the vector to evaluate.

### Method clone()

The objects of this class are cloneable with this method.

ProductDistribution$clone(deep = FALSE) #### Arguments deep Whether to make a deep clone. ## Examples  ## ------------------------------------------------ ## Method ProductDistribution$new
## ------------------------------------------------

if (FALSE) {
ProductDistribution$new(list(Binomial$new(
prob = 0.5,
size = 10
), Normal$new(mean = 15))) ProductDistribution$new(
distribution = "Binomial",
params = list(
list(prob = 0.1, size = 2),
list(prob = 0.6, size = 4),
list(prob = 0.2, size = 6)
)
)

# Equivalently
ProductDistribution$new( distribution = "Binomial", params = data.table::data.table(prob = c(0.1, 0.6, 0.2), size = c(2, 4, 6)) ) } ## ------------------------------------------------ ## Method ProductDistribution$pdf
## ------------------------------------------------

p <- ProductDistribution$new(list( Binomial$new(prob = 0.5, size = 10),
Binomial$new())) p$pdf(1:5)
#> [1] 9.536743e-05 1.931190e-03 1.373291e-02 4.205704e-02 6.056213e-02p$pdf(1, 2) #> [1] 0.0004291534p$pdf(1:2)
#> [1] 9.536743e-05 1.931190e-03
## ------------------------------------------------
## Method ProductDistribution$cdf ## ------------------------------------------------ p <- ProductDistribution$new(list(
Binomial$new(prob = 0.5, size = 10), Binomial$new()))
p$cdf(1:5) #> [1] 0.0001153946 0.0029907227 0.0295410156 0.1420936584 0.3881874084p$cdf(1, 2)
#> [1] 0.0005874634p$cdf(1:2) #> [1] 0.0001153946 0.0029907227Normal$new() * Binomial\$new()
#> Norm X Binom