Coerces matrices to a VectorDistribution containing WeightedDiscrete distributions or a Matdist. Number of distributions are the number of rows in the matrix, number of x points are number of columns in the matrix.

as.Distribution(obj, fun, decorators = NULL, vector = FALSE)

# S3 method for class 'matrix'
as.Distribution(obj, fun, decorators = NULL, vector = FALSE)

# S3 method for class 'array'
as.Distribution(obj, fun, decorators = NULL, vector = FALSE)

Arguments

obj

matrix. Column names correspond to x in WeightedDiscrete, so this method only works if all distributions (rows in the matrix) have the same points to be evaluated on. Elements correspond to either the pdf or cdf of the distribution (see below).

fun

Either "pdf" or "cdf", passed to WeightedDiscrete or Matdist and tells the constructor if the elements in obj correspond to the pdf or cdf of the distribution.

decorators

Passed to VectorDistribution or Matdist.

vector

(logical(1))
If TRUE then constructs a VectorDistribution of WeightedDiscrete distributions, otherwise (default) constructs a Matdist.

Examples

pdf <- runif(200)
mat <- matrix(pdf, 20, 10, FALSE, list(NULL, 1:10))
mat <- t(apply(mat, 1, function(x) x / sum(x)))

# coercion to matrix distribution
as.Distribution(mat, fun = "pdf")
#> Matdist(20x10) 

# coercion to vector of weighted discrete distributions
as.Distribution(mat, fun = "pdf", vector = TRUE)
#> WeightDisc1 WeightDisc2 ... WeightDisc19 WeightDisc20