as.Distribution: Coerce matrix to vector of WeightedDiscrete
Description
Coerces matrices to a VectorDistribution containing
WeightedDiscrete distributions. Number of distributions are the number
of rows in the matrix, number of x points are number of columns in the
matrix.
Usage
as.Distribution(obj, fun, decorators = NULL)
# S3 method for matrix
as.Distribution(obj, fun, decorators = NULL)
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 and tells
the constructor if the elements in obj correspond to the pdf or cdf of
the distribution.
# NOT RUN {pdf <- runif(200)
mat <- matrix(pdf, 20, 10)
mat <- t(apply(mat, 1, function(x) x / sum(x)))
colnames(mat) <- 1:10as.Distribution(mat, fun = "pdf")
# }