Title: Algebra over Probability Distributions
Version: 0.1.0
Description: Provides an algebra over probability distributions enabling composition, sampling, and automatic simplification to closed forms. Supports normal, exponential, multivariate normal, and empirical distributions with operations like addition and subtraction that automatically simplify when mathematical identities apply (e.g., the sum of independent normal distributions is normal). Uses S3 classes for distributions and R6 for support objects.
License: GPL (≥ 3)
Encoding: UTF-8
RoxygenNote: 7.3.3
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
Config/testthat/edition: 3
Imports: stats, mvtnorm, R6
Depends: R (≥ 3.5.0)
VignetteBuilder: knitr
URL: https://github.com/queelius/algebraic.dist, https://queelius.github.io/algebraic.dist/
BugReports: https://github.com/queelius/algebraic.dist/issues
NeedsCompilation: no
Packaged: 2025-12-11 17:29:33 UTC; spinoza
Author: Alexander Towell ORCID iD [aut, cre]
Maintainer: Alexander Towell <lex@metafunctor.com>
Repository: CRAN
Date/Publication: 2025-12-17 10:50:02 UTC

Method for adding dist objects.

Description

Creates an expression distribution and automatically simplifies to closed form when possible (e.g., normal + normal = normal).

Usage

## S3 method for class 'dist'
x + y

Arguments

x

The first dist object to add

y

The second dist object to add

Value

A simplified distribution or edist if no closed form exists


Method for negation or subtraction of dist objects.

Description

Unary: returns negated distribution (e.g., -N(mu, var) = N(-mu, var)) Binary: creates expression distribution and simplifies to closed form when possible (e.g., normal - normal = normal).

Usage

## S3 method for class 'dist'
x - y

Arguments

x

The first dist object

y

The second dist object (optional for unary negation)

Value

A simplified distribution or edist if no closed form exists


Generic method for obtaining the cdf of an object.

Description

Generic method for obtaining the cdf of an object.

Usage

cdf(x, ...)

Arguments

x

The object to obtain the cdf of.

...

Additional arguments to pass.


Method for obtaining the cdf of empirical_dist object x.

Description

If x is a multivariate empirical distribution, this function will throw an error. It's only defined for univariate empirical distributions.

Usage

## S3 method for class 'empirical_dist'
cdf(x, ...)

Arguments

x

The empirical distribution object.

...

Additional arguments to pass (not used))

Value

A function that takes a numeric vector t and returns the empirical cdf of x evaluated at t.


Method to obtain the cdf of an exponential object.

Description

Method to obtain the cdf of an exponential object.

Usage

## S3 method for class 'exponential'
cdf(x, ...)

Arguments

x

The object to obtain the pdf of

...

Additional arguments (not used)

Value

A function that computes the cdf of the exponential. Accepts as input a vector t at which to compute the cdf, an input rate denoting the failure rate of the exponential distribution, and a logical log indicating whether to compute the log of the cdf. By default, rate is the failure rate of object x.


Method for obtaining the CDF of a mvn object.

Description

Method for obtaining the CDF of a mvn object.

Usage

## S3 method for class 'mvn'
cdf(x, ...)

Arguments

x

The object to obtain the CDF of

...

Additional arguments to pass (not used)


Method for obtaining the cdf of an normal object.

Description

Method for obtaining the cdf of an normal object.

Usage

## S3 method for class 'normal'
cdf(x, ...)

Arguments

x

The object to obtain the cdf of

...

Additional arguments to pass (not used)

Value

A function that computes the cdf of the normal distribution. It accepts as input a parameter vector q, a mean vector mu, a variance var, and a log argument determining whether to compute the log of the cdf. By default, mu and var are the mean and variance of object x and log is FALSE. Finally, it accepts additional arguments ... to pass to the pnorm function.


Generic method for obtaining the conditional distribution of a distribution object x given condition P.

Description

Generic method for obtaining the conditional distribution of a distribution object x given condition P.

Usage

conditional(x, P, ...)

Arguments

x

The empirical distribution object.

P

The predicate function to condition x on

...

additional arguments to pass into P


Method for obtaining the condition distribution, x | P(x), of dist object x.

Description

We just sample from x and place the sample in empirical_dist and then condition on it.

Usage

## S3 method for class 'dist'
conditional(x, P, n = 10000L, ...)

Arguments

x

The distribution object.

P

The predicate function to condition the distribution on

n

The number of samples to generate for the MC estimate of the conditional distribution x | P. Defaults to 10000.

...

additional arguments to pass into P.


Method for obtaining the condition distribution, x | P(x), of empirical_dist object x.

Description

In other words, we condition the data on the predicate function. In order to do so, we simply remove all rows from the data that do not satisfy the predicate P. For instance, if we have a 2-dimensional distribution, and we want to condition on the first dimension being greater than the second dimension, we would do the following:

Usage

## S3 method for class 'empirical_dist'
conditional(x, P, ...)

Arguments

x

The empirical distribution object.

P

The predicate function to condition the data on.

...

additional arguments to pass into P.

Details

x_cond <- conditional(x, function(d) d[1] > d[2])

This would return a new empirical distribution object with the same dimensionality as x, but with all rows where the first dimension is less than or equal to the second dimension removed.


Method for obtaining the pdf of a empirical_dist object.

Description

Method for obtaining the pdf of a empirical_dist object.

Usage

## S3 method for class 'empirical_dist'
density(x, ...)

Arguments

x

The object to obtain the pdf of.

...

Additional arguments to pass into the pdf function.

Note

sort tibble lexicographically and do a binary search to find upper and lower bound in log(nobs(x)) time.


Method to obtain the pdf of an exponential object.

Description

Method to obtain the pdf of an exponential object.

Usage

## S3 method for class 'exponential'
density(x, ...)

Arguments

x

The object to obtain the pdf of

...

Additional arguments (not used)

Value

A function that computes the pdf of the exponential distribution at a given point t. Also accepts a rate argument that determines the failure rate of the exponential distribution (defaults to the failure rate of object x) and a log argument that determines whether to compute the log of the pdf.


Function generator for obtaining the pdf of an mvn object (multivariate normal).

Description

Function generator for obtaining the pdf of an mvn object (multivariate normal).

Usage

## S3 method for class 'mvn'
density(x, ...)

Arguments

x

The mvn (S3) object to obtain the pdf (density) of

...

Additional arguments to pass into the generated function.

Value

A function that computes the pdf of the mvn distribution. It accepts as input: - obs: vector or matrix of quantiles. when x is a matrix, each row is taken to be a quantile and columns correspond to the number of dimensions, p. - mu: a a vector denoting the population mean. Defaults to the mean of x (an mvn object) - sigma: a matrix denoting the variance-covariance of observations. Defaults to the variance-covariance of x. - log: logical, determines whether to compute the log of the pdf. Defaults to FALSE. - ...: any additional parameters to pass to dmvnorm.


Method for obtaining the pdf of an normal object.

Description

Method for obtaining the pdf of an normal object.

Usage

## S3 method for class 'normal'
density(x, ...)

Arguments

x

The object to obtain the pdf of

...

Additional arguments to pass (not used)

Value

A function that computes the pdf of the normal distribution. It accepts as input a parameter vector x, a mean vector mu, a variance-covariance matrix var, and a log argument determining whether to compute the log of the pdf. By default, mu and var are the mean and variance of object x.


Method for obtaining the dimension of a empirical_dist object.

Description

Method for obtaining the dimension of a empirical_dist object.

Usage

## S3 method for class 'empirical_dist'
dim(x)

Arguments

x

The object to obtain the dimension of.


Method to obtain the dimension of an exponential object.

Description

Method to obtain the dimension of an exponential object.

Usage

## S3 method for class 'exponential'
dim(x)

Arguments

x

The exponential object to obtain the dimension of

Value

The dimension of the exponential object


Return the dimension of the finite set.

Description

Return the dimension of the finite set.

Usage

## S3 method for class 'finite_set'
dim(x)

Arguments

x

A finite set.


Return the dimension of the interval.

Description

Return the dimension of the interval.

Usage

## S3 method for class 'interval'
dim(x)

Arguments

x

An interval object.


Method for obtaining the dimension of an mvn object.

Description

Method for obtaining the dimension of an mvn object.

Usage

## S3 method for class 'mvn'
dim(x)

Arguments

x

The object to obtain the dimension of

Value

The dimension of the mvn object


Method for obtaining the dimension of a normal object.

Description

Method for obtaining the dimension of a normal object.

Usage

## S3 method for class 'normal'
dim(x)

Arguments

x

The normal object to obtain the dimension of

Value

The dimension of the normal object


Takes an expression e and a list vars and returns a lazy edist (expression distribution object), that is a subclass of dist that can be used in place of a dist object.

Description

Takes an expression e and a list vars and returns a lazy edist (expression distribution object), that is a subclass of dist that can be used in place of a dist object.

Usage

edist(e, vars)

Arguments

e

the expression to evaluate against the arguments.

vars

the list of distributions (with variable names) to evaluate the expression e against.

Value

An edist object.


Construct empirical distribution object.

Description

Construct empirical distribution object.

Usage

empirical_dist(data)

Arguments

data

data to construct empirical distribution from. if matrix or data frame, each row is a joint observation, if a vector, each element is an observation. whatever data is, it must be convertible to a tibble.


Generic method for obtaining the expectation of f with respect to x.

Description

Generic method for obtaining the expectation of f with respect to x.

Usage

expectation(x, g, ...)

Arguments

x

The distribution object.

g

The function to take the expectation of.

...

Additional arguments to pass into g.


Expectation of a Function Applied to a dist Object

Description

Expectation operator applied to x of type dist with respect to a function g. Optionally, constructs a confidence interval for the expectation estimate using the Central Limit Theorem.

Usage

## S3 method for class 'dist'
expectation(x, g = function(t) t, ..., control = list())

Arguments

x

A dist object.

g

Characteristic function of interest, defaults to identity.

...

Additional arguments to pass to g.

control

A list of control parameters: compute_stats - Logical, whether to compute CIs for the expectations, defaults to FALSE n - Integer, the number of samples to use for the MC estimate, defaults to 10000L alpha - Real, the significance level for the confidence interval, defaults to 0.05

Value

If compute_stats is FALSE, then the estimate of the expectation, otherwise a list with the following components: value - The estimate of the expectation ci - The confidence intervals for each component of the expectation n - The number of samples


Method for obtaining the expectation of empirical_dist object x under function g.

Description

Method for obtaining the expectation of empirical_dist object x under function g.

Usage

## S3 method for class 'empirical_dist'
expectation(x, g = function(t) t, ..., control = list())

Arguments

x

The distribution object.

g

The function to take the expectation of.

...

Additional arguments to pass into function g.

control

a list of control parameters: compute_stats - Whether to compute CIs for the expectations, defaults to FALSE n - The number of samples to use for the MC estimate, defaults to 10000 alpha - The significance level for the confidence interval, defaults to 0.05

Value

If compute_stats is FALSE, then the estimate of the expectation, otherwise a list with the following components: value - The estimate of the expectation ci - The confidence intervals for each component of the expectation n - The number of samples


Method for obtaining the expectation of f with respect to a univariate_dist object x.

Description

Assumes the support is a contiguous interval that has operations for retrieving the lower and upper bounds.

Usage

## S3 method for class 'univariate_dist'
expectation(x, g, ..., control = list())

Arguments

x

The distribution object.

g

The function to take the expectation of.

...

Additional arguments to pass into g.

control

An (optional) list of control parameters for integrate or expectation_data (if x is not continuous)


Function used for computing expectations given data (e.g., from an MC simulation or bootstrap). it expects a matrix, or something that can be coerced to a matrix (e.g., a data frame). it also expects a function g to apply to each row of the data, and returns the expectation of g under the empirical distribution of the data. it also returns a confidence interval for the expectation, and the number of samples used to compute the expectation.

Description

example: expectation_data(D, function(x) (x-colMeans(D)) %*% t(x-colMeans(D))) computes the covariance of the data D, except the matrix structure is lost (it's just a vector, which can be coerced back to a matrix if needed).

Usage

expectation_data(
  data,
  g = function(x) x,
  ...,
  compute_stats = TRUE,
  alpha = 0.05
)

Arguments

data

a matrix of data

g

a function to apply to each row of the data

...

additional arguments to pass to g

compute_stats

whether to compute CIs for the expectations

alpha

the confidence level for the confidence interval for each component of the expectation (if compute_stats is TRUE)

Value

if compute_stats is TRUE, then a list with the following components: value - The estimate of the expectation ci - The confidence intervals for each component of the expectation n - The number of samples otherwise, just the value of the expectation.


Construct exponential distribution object.

Description

Construct exponential distribution object.

Usage

exponential(rate)

Arguments

rate

failure rate


Finite set

Description

A finite set. It also satisfies the concept of a support.

Public fields

values

A vector of values.

Methods

Public methods


Method new()

Initialize a finite set.

Usage
finite_set$new(values)
Arguments
values

A vector of values.


Method has()

Determine if a value is contained in the finite set.

Usage
finite_set$has(x)
Arguments
x

A vector of values.


Method infimum()

Get the infimum of the finite set.

Usage
finite_set$infimum()
Returns

A numeric vector of infimums.


Method supremum()

Get the supremum of the finite set.

Usage
finite_set$supremum()
Returns

A numeric vector of supremums.


Method dim()

Get the dimension of the finite set.

Usage
finite_set$dim()
Returns

The dimension of the finite set.


Method clone()

The objects of this class are cloneable with this method.

Usage
finite_set$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


Support

Description

support is a class that represents the support of a random element or distribution, i.e. the set of values that it realize.

It's a conceptual class. To satisfy the concept of a support, the following methods must be implemented:

  1. has: a function that returns a logical vector indicating whether each value in a vector is contained in the support

  2. infimum: a function that returns the infimum of the support

  3. supremum: a function that returns the supremum of the support

  4. dim: a function that returns the dimension of the support

We provide two implementations that satisfy the concept:

Usage

has(object, x)

Arguments

object

A support object.

x

A vector of values.


Determine if a value is contained in the finite set.

Description

Determine if a value is contained in the finite set.

Usage

## S3 method for class 'finite_set'
has(object, x)

Arguments

object

A finite set.

x

A vector of values.


Determine if a value is contained in the interval.

Description

Determine if a value is contained in the interval.

Usage

## S3 method for class 'interval'
has(object, x)

Arguments

object

An interval object.

x

A vector of values.


Generic method for obtaining the hazard function of an object.

Description

Generic method for obtaining the hazard function of an object.

Usage

hazard(x, ...)

Arguments

x

The object to obtain the hazard function of.

...

Additional arguments to pass.


Method to obtain the hazard function of an exponential object.

Description

Method to obtain the hazard function of an exponential object.

Usage

## S3 method for class 'exponential'
hazard(x, ...)

Arguments

x

The exponential object to obtain the hazard function of

...

Additional arguments (not used)

Value

A function that computes the hazard function of the exponential distribution at a given point t and rate rate. By default, rate is the failure rate of object x Also accepts a log argument that determines whether to compute the log of the hazard function.


Get the infimum of the support.

Description

Get the infimum of the support.

Usage

infimum(object)

Arguments

object

A support object.


Return the infimum of the finite set.

Description

Return the infimum of the finite set.

Usage

## S3 method for class 'finite_set'
infimum(object)

Arguments

object

A finite set.


Return the (vector of) infimum of the interval.

Description

Return the (vector of) infimum of the interval.

Usage

## S3 method for class 'interval'
infimum(object)

Arguments

object

An interval object.


Interval

Description

An interval is a support that is a finite union of intervals.

Public fields

lower

A numeric vector of lower bounds.

upper

A numeric vector of upper bounds.

lower_closed

A logical vector indicating whether the lower bound is closed.

upper_closed

A logical vector indicating whether the upper bound is closed.

Methods

Public methods


Method new()

Initialize an interval.

Usage
interval$new(
  lower = -Inf,
  upper = Inf,
  lower_closed = FALSE,
  upper_closed = FALSE
)
Arguments
lower

A numeric vector of lower bounds.

upper

A numeric vector of upper bounds.

lower_closed

A logical vector indicating whether the lower bound is closed.

upper_closed

A logical vector indicating whether the upper bound is closed.


Method is_empty()

Determine if the interval is empty

Usage
interval$is_empty()
Returns

A logical vector indicating whether the interval is empty.


Method has()

Determine if a value is contained in the interval.

Usage
interval$has(x)
Arguments
x

A numeric vector of values.

Returns

A logical vector indicating whether each value is contained


Method infimum()

Get the infimum of the interval.

Usage
interval$infimum()
Returns

A numeric vector of infimums.


Method supremum()

Get the supremum of the interval.

Usage
interval$supremum()
Returns

A numeric vector of supremums.


Method dim()

Get the dimension of the interval.

Usage
interval$dim()
Returns

The dimension of the interval.


Method clone()

The objects of this class are cloneable with this method.

Usage
interval$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


Generic method for obtaining the quantile (inverse cdf) of an object.

Description

Generic method for obtaining the quantile (inverse cdf) of an object.

Usage

inv_cdf(x, ...)

Arguments

x

The object to obtain the quantile of.

...

Additional arguments to pass.


Method to obtain the inverse cdf of an exponential object.

Description

Method to obtain the inverse cdf of an exponential object.

Usage

## S3 method for class 'exponential'
inv_cdf(x, ...)

Arguments

x

The object to obtain the inverse cdf of

...

Additional arguments (not used)

Value

A function that computes the inverse cdf of the exponential distribution. Accepts as input a vector p probabilities to compute the inverse cdf, a rate value denoting the failure rate of the exponential distribution, and a logical log.p indicating whether input p denotes probability or log-probability. By default, rate is the failure rate of object x.


Method for obtaining the inverse cdf of an normal object.

Description

Method for obtaining the inverse cdf of an normal object.

Usage

## S3 method for class 'normal'
inv_cdf(x, ...)

Arguments

x

The object to obtain the inverse cdf of

...

Additional arguments to pass (not used)

Value

A function that computes the inverse cdf of the normal distribution.


Function to determine whether an object x is a dist object.

Description

Function to determine whether an object x is a dist object.

Usage

is_dist(x)

Arguments

x

The object to test

Value

Logical indicating whether x is a dist object.


Function to determine whether an object x is an edist object.

Description

Function to determine whether an object x is an edist object.

Usage

is_edist(x)

Arguments

x

The object to test


Function to determine whether an object x is an empirical_dist object.

Description

Function to determine whether an object x is an empirical_dist object.

Usage

is_empirical_dist(x)

Arguments

x

The object to test


Function to determine whether an object x is an exponential object.

Description

Function to determine whether an object x is an exponential object.

Usage

is_exponential(x)

Arguments

x

The object to test


Function to determine whether an object x is an mvn object.

Description

Function to determine whether an object x is an mvn object.

Usage

is_mvn(x)

Arguments

x

The object to test


Function to determine whether an object x is an normal object.

Description

Function to determine whether an object x is an normal object.

Usage

is_normal(x)

Arguments

x

The object to test


We have an edist object, which is a subclass of dist, and now we're placing it inside of a limit expression, where the limit is understood to be with respect to sample size. We need to define a method for this.

Description

We have an edist object, which is a subclass of dist, and now we're placing it inside of a limit expression, where the limit is understood to be with respect to sample size. We need to define a method for this.

Usage

limit.edist(x)

Arguments

x

The edist object to take the limit of

Value

The limit of the edist object


Generic method for obtaining the marginal distribution of a distribution object x over components indices.

Description

Generic method for obtaining the marginal distribution of a distribution object x over components indices.

Usage

marginal(x, indices)

Arguments

x

The distribution object.

indices

The indices of the marginal distribution to obtain.


Method for obtaining the marginal distribution of empirical_dist object x.

Description

Method for obtaining the marginal distribution of empirical_dist object x.

Usage

## S3 method for class 'empirical_dist'
marginal(x, indices)

Arguments

x

The empirical distribution object.

indices

The indices of the marginal distribution to obtain.


Generic method for obtaining the marginal distribution of an mvn object x over components indices.

Description

Generic method for obtaining the marginal distribution of an mvn object x over components indices.

Usage

## S3 method for class 'mvn'
marginal(x, indices)

Arguments

x

The mvn object.

indices

The indices of the marginal distribution to obtain.


Method for obtaining the mean of an edist object.

Description

Method for obtaining the mean of an edist object.

Usage

## S3 method for class 'edist'
mean(x, n = 10000, ...)

Arguments

x

The edist object to retrieve the mean from

n

The number of samples to take (default: 1000)

...

Additional arguments to pass (not used)

Value

The mean of the edist object


Method for obtaining the mean of empirical_dist object x.

Description

Method for obtaining the mean of empirical_dist object x.

Usage

## S3 method for class 'empirical_dist'
mean(x, ...)

Arguments

x

The distribution object.

...

Additional arguments to pass (not used).


Method to obtain the mean of an exponential object.

Description

Method to obtain the mean of an exponential object.

Usage

## S3 method for class 'exponential'
mean(x, ...)

Arguments

x

The exponential object to obtain the mean of

...

Additional arguments (not used)


Retrieve the mean of a mvn object.

Description

Retrieve the mean of a mvn object.

Usage

## S3 method for class 'mvn'
mean(x, ...)

Arguments

x

The mvn object to retrieve the mean from

...

Additional arguments to pass (not used)

Value

The mean of the mvn object


Retrieve the mean of a normal object.

Description

Retrieve the mean of a normal object.

Usage

## S3 method for class 'normal'
mean(x, ...)

Arguments

x

The normal object to retrieve the mean from

...

Additional arguments to pass (not used)

Value

The mean of the normal object


Method for obtaining the mean of univariate_dist object x.

Description

Method for obtaining the mean of univariate_dist object x.

Usage

## S3 method for class 'univariate_dist'
mean(x, ...)

Arguments

x

The distribution object.

...

Additional arguments to pass into expectation.


Construct a multivariate or univariate normal distribution object.

Description

This function constructs an object representing a normal distribution. If the length of the mean vector mu is 1, it creates a univariate normal distribution. Otherwise, it creates a multivariate normal distribution.

Usage

mvn(mu, sigma = diag(length(mu)))

Arguments

mu

A numeric vector specifying the means of the distribution. If mu has length 1, a univariate normal distribution is created. If mu has length > 1, a multivariate normal distribution is created.

sigma

A numeric matrix specifying the variance-covariance matrix of the distribution. It must be a square matrix with the same number of rows and columns as the length of mu. Default is the identity matrix of size equal to the length of mu.

Value

If mu has length 1, it returns a normal object. If mu has length > 1, it returns an mvn object. Both types of objects contain mu and sigma as their properties.


Method for obtaining the number of observations used to construct a empirical_dist object.

Description

Method for obtaining the number of observations used to construct a empirical_dist object.

Usage

## S3 method for class 'empirical_dist'
nobs(object, ...)

Arguments

object

The empirical distribution object.

...

Additional arguments to pass (not used).


Construct univariate normal distribution object.

Description

Construct univariate normal distribution object.

Usage

normal(mu = 0, var = 1)

Arguments

mu

mean

var

variance


Generic method for obtaining the number of parameters of distribution-like object x.

Description

Generic method for obtaining the number of parameters of distribution-like object x.

Usage

nparams(x)

Arguments

x

the object to obtain the number of parameters for


Method for obtaining the name of a empirical_dist object. Since the empirical distribution is parameter-free, this function returns 0.

Description

Method for obtaining the name of a empirical_dist object. Since the empirical distribution is parameter-free, this function returns 0.

Usage

## S3 method for class 'empirical_dist'
nparams(x)

Arguments

x

The empirical distribution object.


Retrieve the observations used to construct a distribution-like object. This is useful for obtaining the data used to construct an empirical distribution, but it is also useful for, say, retrieving the sample that was used by a fitted object, like an maximum likelihood estimate.

Description

Retrieve the observations used to construct a distribution-like object. This is useful for obtaining the data used to construct an empirical distribution, but it is also useful for, say, retrieving the sample that was used by a fitted object, like an maximum likelihood estimate.

Usage

obs(x)

Arguments

x

the object to retrieve the observations from


Method for obtaining the observations used to construct a empirical_dist object.

Description

Method for obtaining the observations used to construct a empirical_dist object.

Usage

## S3 method for class 'empirical_dist'
obs(x)

Arguments

x

The empirical distribution object.


Generic method for obtaining the parameters of an object.

Description

Generic method for obtaining the parameters of an object.

Usage

params(x)

Arguments

x

The object to obtain the parameters of.


Method for obtaining the parameters of an edist object.

Description

Method for obtaining the parameters of an edist object.

Usage

## S3 method for class 'edist'
params(x)

Arguments

x

The object to obtain the parameters of

Value

A named vector of parameters


empirical_dist objects have no parameters, so this function returns NULL.

Description

empirical_dist objects have no parameters, so this function returns NULL.

Usage

## S3 method for class 'empirical_dist'
params(x)

Arguments

x

The empirical distribution object.


Method for obtaining the parameters of an exponential object.

Description

Method for obtaining the parameters of an exponential object.

Usage

## S3 method for class 'exponential'
params(x)

Arguments

x

The object to obtain the parameters of

Value

A named vector of parameters


Method for obtaining the parameters of a mvn object.

Description

Method for obtaining the parameters of a mvn object.

Usage

## S3 method for class 'mvn'
params(x)

Arguments

x

The object to obtain the parameters of

Value

A named vector of parameters


Method for obtaining the parameters of a normal object.

Description

Method for obtaining the parameters of a normal object.

Usage

## S3 method for class 'normal'
params(x)

Arguments

x

The object to obtain the parameters of

Value

A named vector of parameters


Method for printing an edist object.

Description

Method for printing an edist object.

Usage

## S3 method for class 'edist'
print(x, ...)

Arguments

x

The object to print

...

Additional arguments to pass (not used)


Method for printing a dist object

Description

Method for printing a dist object

Usage

## S3 method for class 'empirical_dist'
print(x, ...)

Arguments

x

The object to print

...

Additional arguments to pass


Print method for exponential objects.

Description

Print method for exponential objects.

Usage

## S3 method for class 'exponential'
print(x, ...)

Arguments

x

The exponential object to print.

...

Additional arguments (not used)


Print the interval.

Description

Print the interval.

Usage

## S3 method for class 'interval'
print(x, ...)

Arguments

x

An interval object.

...

Additional arguments.


Method for printing an mvn object.

Description

Method for printing an mvn object.

Usage

## S3 method for class 'mvn'
print(x, ...)

Arguments

x

The object to print

...

Additional arguments to pass to print


Method for printing a normal object.

Description

Method for printing a normal object.

Usage

## S3 method for class 'normal'
print(x, ...)

Arguments

x

The object to print

...

Additional arguments to pass (not used)


Print method for summary_dist objects.

Description

Print method for summary_dist objects.

Usage

## S3 method for class 'summary_dist'
print(x, ...)

Arguments

x

The object to print

...

Additional arguments


Generic method for applying a map f to distribution object x.

Description

Generic method for applying a map f to distribution object x.

Usage

rmap(x, g, ...)

Arguments

x

The distribution object.

g

The function to apply.

...

Additional arguments to pass into g.


Method for obtaining g(x)) where x is a dist object.

Description

We just sample from x and place the sample in empirical_dist and then apply rmap with g to it.

Usage

## S3 method for class 'dist'
rmap(x, g, n = 10000L, ...)

Arguments

x

The distribution object.

g

The function to apply to the distribution.

n

The number of samples to generate for the MC estimate of the conditional distribution x | P. Defaults to 10000.

...

additional arguments to pass into g.


Method for obtaining the empirical distribution of a function of the observations of empirical_dist object x.

Description

Method for obtaining the empirical distribution of a function of the observations of empirical_dist object x.

Usage

## S3 method for class 'empirical_dist'
rmap(x, g, ...)

Arguments

x

The empirical distribution object.

g

The function to apply to each observation.

...

Additional arguments to pass into function g.


Computes the distribution of g(x) where x is an mvn object.

Description

By the invariance property, if x is an mvn object, then under the right conditions, asymptotically, g(x) is an MVN distributed, g(x) ~ normal(g(mean(x)), sigma) where sigma is the variance-covariance of g(x)

Usage

## S3 method for class 'mvn'
rmap(x, g, n = 10000L, ...)

Arguments

x

The mvn object to apply g to

g

The function to apply to x

n

number of samples to take to estimate distribution of g(x) if method is mc or empirical. Defaults to 10000.

...

additional arguments to pass into the g function.


Function for obtaining sample points for an mvn object that is within the p-probability region. That is, it samples from the smallest region of the distribution that contains p probability mass. This is done by first sampling from the entire distribution, then rejecting samples that are not in the probability region (using the statistical distance mahalanobis from mu).

Description

Function for obtaining sample points for an mvn object that is within the p-probability region. That is, it samples from the smallest region of the distribution that contains p probability mass. This is done by first sampling from the entire distribution, then rejecting samples that are not in the probability region (using the statistical distance mahalanobis from mu).

Usage

sample_mvn_region(n, mu, sigma, p = 0.95, ...)

Arguments

n

the sample size

mu

mean vector

sigma

variance-covariance matrix

p

the probability region

...

additional arguments to pass into mahalanobis


Generic method for sampling from distribution-like objects.

Description

It creates a sampler for the x object. It returns a function that accepts a parameter n denoting the number of samples to draw from the x object and also any additional parameters ... are passed to the generated function.

Usage

sampler(x, ...)

Arguments

x

the x object to create a sampler for

...

additional arguments to pass


Sampler for non-dist objects (degenerate distributions).

Description

Sampler for non-dist objects (degenerate distributions).

Usage

## Default S3 method:
sampler(x, ...)

Arguments

x

The object to sample from

...

Additional arguments to pass

Value

A function that takes n and returns n copies of x


Method for obtaining the sampler of an edist object.

Description

Method for obtaining the sampler of an edist object.

Usage

## S3 method for class 'edist'
sampler(x, ...)

Arguments

x

The edist object to obtain the sampler of.

...

Additional arguments to pass into each of the sampler function generators.

Value

A function that takes a number of samples n, ... which is passed into the expression x$e and returns the result of applying the expression x$e to the sampled values.


Method for obtaining the sampler for a empirical_dist object.

Description

Method for obtaining the sampler for a empirical_dist object.

Usage

## S3 method for class 'empirical_dist'
sampler(x, ...)

Arguments

x

The object to obtain the sampler of.

...

Additional arguments to pass (not used).


Method to sample from an exponential object.

Description

Method to sample from an exponential object.

Usage

## S3 method for class 'exponential'
sampler(x, ...)

Arguments

x

The exponential object to sample from.

...

Additional arguments to pass (not used)

Value

A function that allows sampling from the exponential distribution. Accepts an argument n denoting sample size and rate denoting the failure rate. Defaults to the failure rate of object x.


Function generator for sampling from a mvn (multivariate normal) object.

Description

Function generator for sampling from a mvn (multivariate normal) object.

Usage

## S3 method for class 'mvn'
sampler(x, ...)

Arguments

x

The mvn object to sample from

...

Additional arguments to pass to the generated function that will be fixed during all calls.

Value

A function that samples from the mvn distribution. It accepts as input: - n: number of samples to generate. Defaults to 1. - mu: a vector denoting the population mean. Defaults to the mean of x (an mvn object) - sigma: a matrix denoting the covariance of observations. Defaults to the variance-covariance of x. - p: probability region to sample from. Defaults to 1, which corresponds to the entire distribution. sample_mvn_region method. It's used when p is less than 1. - ...: any additional parameters to pass to rmvnorm or sample_mvn_region which can be different during each call.


Method for sampling from a normal object.

Description

Method for sampling from a normal object.

Usage

## S3 method for class 'normal'
sampler(x, ...)

Arguments

x

The normal object to sample from

...

Additional arguments to pass (not used)

Value

A function that samples from the normal distribution. As input, it accepts a sample size n, a numeric mu, and a variance numeric var. By default, mu and var are the mean and variance of object x.


Generic method for simplifying distributions.

Description

Generic method for simplifying distributions.

Usage

simplify(x, ...)

Arguments

x

The distribution to simplify

...

Additional arguments to pass

Value

The simplified distribution


Default Method for simplifming a dist object. Just returns the object.

Description

Default Method for simplifming a dist object. Just returns the object.

Usage

## S3 method for class 'dist'
simplify(x, ...)

Arguments

x

The dist object to simplify

...

Additional arguments to pass (not used)

Value

The dist object


Method for simplifying an edist object.

Description

Attempts to reduce expression distributions to closed-form distributions when mathematical identities apply. For example:

Usage

## S3 method for class 'edist'
simplify(x, ...)

Arguments

x

The edist object to simplify

...

Additional arguments to pass (not used)

Value

The simplified distribution, or unchanged edist if no rule applies


Method for obtaining a summary of a dist object.

Description

Method for obtaining a summary of a dist object.

Usage

## S3 method for class 'dist'
summary(object, ..., name = NULL, nobs = NULL)

Arguments

object

The object to obtain the summary of

...

Additional arguments to pass

name

The name of the distribution, defaults to the class of the object.

nobs

The number of observations to report for the summary, if applicable.

Value

A summary_dist object


Method for constructing a summary_dist object.

Description

Method for constructing a summary_dist object.

Usage

summary_dist(name, mean, vcov, nobs = NULL)

Arguments

name

The name of the distribution

mean

The mean of the distribution

vcov

The variance of the distribution

nobs

The number of observations used to construct the distribution, if applicable.

Value

A summary_dist object


Generic method for retrieving the support of a (dist) object x.

Description

The returned value should have the following operations:

Usage

sup(x)

Arguments

x

The object to obtain the support of.

Value

A support object for x.


Method for obtaining the support of empirical_dist object x.

Description

Method for obtaining the support of empirical_dist object x.

Usage

## S3 method for class 'empirical_dist'
sup(x)

Arguments

x

The empirical distribution object.

Value

A finite_set object containing the support of x.


Support for exponential distribution, the positive real numbers, (0, Inf).

Description

Support for exponential distribution, the positive real numbers, (0, Inf).

Usage

## S3 method for class 'exponential'
sup(x)

Arguments

x

The object to obtain the support of

Value

An interval object representing the support of the exponential


Method for obtaining the support of a mvn object, where the support is defined as values that have non-zero probability density.

Description

Method for obtaining the support of a mvn object, where the support is defined as values that have non-zero probability density.

Usage

## S3 method for class 'mvn'
sup(x, ...)

Arguments

x

The mvn object to obtain the support of

...

Additional arguments to pass (not used)

Value

A support-type object (see support.R), in this case an interval object for each component.


Method for obtaining the support of a normal object, where the support is defined as values that have non-zero probability density.

Description

Method for obtaining the support of a normal object, where the support is defined as values that have non-zero probability density.

Usage

## S3 method for class 'normal'
sup(x)

Arguments

x

The normal object to obtain the support of

Value

A support-type object (see support.R), in this case an interval object for each component.


Get the supremum of the support.

Description

Get the supremum of the support.

Usage

supremum(object)

Arguments

object

A support object.


Return the supremum of the finite set.

Description

Return the supremum of the finite set.

Usage

## S3 method for class 'finite_set'
supremum(object)

Arguments

object

A finite set.


Return the (vector of) supremum of the interval.

Description

Return the (vector of) supremum of the interval.

Usage

## S3 method for class 'interval'
supremum(object)

Arguments

object

An interval object.


Generic method for obtaining the survival function of an object.

Description

Generic method for obtaining the survival function of an object.

Usage

surv(x, ...)

Arguments

x

The object to obtain the survival function of.

...

Additional arguments to pass.


Method to obtain the cdf of an exponential object.

Description

Method to obtain the cdf of an exponential object.

Usage

## S3 method for class 'exponential'
surv(x, ...)

Arguments

x

The object to obtain the pdf of

...

Additional arguments (not used)

Value

A function that computes the cdf of the exponential. Accepts as input a vector t at which to compute the cdf, an input rate denoting the failure rate of the exponential distribution, and a logical log indicating whether to compute the log of the cdf. By default, rate is the failure rate of object x.


Variance-covariance for non-dist objects (degenerate distributions).

Description

Variance-covariance for non-dist objects (degenerate distributions).

Usage

## Default S3 method:
vcov(object, ...)

Arguments

object

The object (returns 0 for constants)

...

Additional arguments to pass (not used)

Value

0 (degenerate distributions have no variance)


Method for obtaining the variance-covariance matrix (or scalar)

Description

Method for obtaining the variance-covariance matrix (or scalar)

Usage

## S3 method for class 'edist'
vcov(object, n = 10000, ...)

Arguments

object

The edist object to retrieve the variance-covariance matrix from

n

The number of samples to take (default: 1000)

...

Additional arguments to pass (not used)

Value

The variance-covariance matrix of the edist object


Method for obtaining the variance of empirical_dist object x.

Description

Method for obtaining the variance of empirical_dist object x.

Usage

## S3 method for class 'empirical_dist'
vcov(object, ...)

Arguments

object

The empirical distribution object.

...

Additional arguments to pass (not used).


Retrieve the variance of a exponential object.

Description

Retrieve the variance of a exponential object.

Usage

## S3 method for class 'exponential'
vcov(object, ...)

Arguments

object

The exponential object to retrieve the variance for

...

Additional arguments to pass (not used)

Value

The variance-covariance matrix of the normal object


Retrieve the variance-covariance matrix of an mvn object.

Description

Retrieve the variance-covariance matrix of an mvn object.

Usage

## S3 method for class 'mvn'
vcov(object, ...)

Arguments

object

The mvn object to retrieve the variance-covariance matrix of

...

Additional arguments to pass (not used)

Value

The variance-covariance matrix of the mvn object


Retrieve the variance-covariance matrix (or scalar) of a normal object.

Description

Retrieve the variance-covariance matrix (or scalar) of a normal object.

Usage

## S3 method for class 'normal'
vcov(object, ...)

Arguments

object

The normal object to retrieve the variance-covariance matrix from

...

Additional arguments to pass (not used)

Value

The variance-covariance matrix of the normal object


Method for obtaining the variance of univariate_dist object.

Description

Method for obtaining the variance of univariate_dist object.

Usage

## S3 method for class 'univariate_dist'
vcov(object, ...)

Arguments

object

The distribution object.

...

Additional arguments to pass into expectation.