Learn R Programming

distr6 (version 1.6.9)

as.Distribution: 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 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
vector

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

Value

A VectorDistribution or Matdist

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab