as.Distribution: Coerce matrix to vector of WeightedDiscrete

Description Usage Arguments Value Examples

View source: R/as.Distribution.R

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

1
2
3
4
as.Distribution(obj, fun, decorators = NULL)

## S3 method for class '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.

decorators

Passed to VectorDistribution.

Value

A VectorDistribution

Examples

1
2
3
4
5
pdf <- runif(200)
mat <- matrix(pdf, 20, 10)
mat <- t(apply(mat, 1, function(x) x / sum(x)))
colnames(mat) <- 1:10
as.Distribution(mat, fun = "pdf")

distr6 documentation built on Sept. 6, 2021, 9:10 a.m.