as.Distribution: Coerce matrix to vector of WeightedDiscrete or Matrix...

View source: R/as.Distribution.R

as.DistributionR Documentation

Coerce matrix to vector of WeightedDiscrete or Matrix Distribution

Description

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.

Usage

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

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

Value

A VectorDistribution or 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")

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

distr6 documentation built on March 28, 2022, 1:05 a.m.