| Title: | Algebra over Probability Distributions |
|---|---|
| Description: | Provides an algebra over probability distributions enabling composition, sampling, and automatic simplification to closed forms. Supports normal, exponential, gamma, Weibull, chi-squared, uniform, beta, log-normal, Poisson, multivariate normal, empirical, and mixture distributions with algebraic operators (addition, subtraction, multiplication, division, power, exp, log, min, max) that automatically simplify when mathematical identities apply. Includes closed-form MVN conditioning (Schur complement), affine transformations, mixture marginals/conditionals (Bayes rule), and limiting distribution builders (CLT, LLN, delta method). Uses S3 classes for distributions and R6 for support objects. |
| Authors: | Alexander Towell [aut, cre] (ORCID: <https://orcid.org/0000-0001-6443-9897>) |
| Maintainer: | Alexander Towell <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-05-16 08:29:46 UTC |
| Source: | https://github.com/queelius/algebraic.dist |
dist objects.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, normal - scalar = normal).
## S3 method for class 'dist' x - y## S3 method for class 'dist' x - y
x |
A |
y |
A |
A simplified distribution or edist if no closed form exists
# Difference of normals simplifies to a normal z <- normal(5, 2) - normal(1, 3) z # Normal(mu = 4, var = 5) # Unary negation -normal(3, 1) # Normal(mu = -3, var = 1)# Difference of normals simplifies to a normal z <- normal(5, 2) - normal(1, 3) z # Normal(mu = 4, var = 5) # Unary negation -normal(3, 1) # Normal(mu = -3, var = 1)
Handles scalar * dist, dist * scalar, and dist * dist.
## S3 method for class 'dist' x * y## S3 method for class 'dist' x * y
x |
first operand |
y |
second operand |
A simplified distribution or edist
# Scalar multiplication simplifies for normal z <- 2 * normal(0, 1) z # Normal(mu = 0, var = 4) # Product of two distributions yields an edist w <- normal(0, 1) * exponential(1) is_edist(w) # TRUE# Scalar multiplication simplifies for normal z <- 2 * normal(0, 1) z # Normal(mu = 0, var = 4) # Product of two distributions yields an edist w <- normal(0, 1) * exponential(1) is_edist(w) # TRUE
Handles dist / scalar (delegates to dist * (1/scalar)), scalar / dist, and dist / dist.
## S3 method for class 'dist' x / y## S3 method for class 'dist' x / y
x |
first operand |
y |
second operand |
A simplified distribution or edist
# Division by scalar reuses multiplication rule z <- normal(0, 4) / 2 z # Normal(mu = 0, var = 1)# Division by scalar reuses multiplication rule z <- normal(0, 4) / 2 z # Normal(mu = 0, var = 1)
Power operator for distribution objects.
## S3 method for class 'dist' x ^ y## S3 method for class 'dist' x ^ y
x |
a dist object (base) |
y |
a numeric scalar (exponent) |
A simplified distribution or edist
# Standard normal squared yields chi-squared(1) z <- normal(0, 1)^2 z# Standard normal squared yields chi-squared(1) z <- normal(0, 1)^2 z
dist objects, or shifting a distribution by a scalar.Creates an expression distribution and automatically simplifies to closed form when possible (e.g., normal + normal = normal, normal + scalar = normal with shifted mean).
## S3 method for class 'dist' x + y## S3 method for class 'dist' x + y
x |
A |
y |
A |
A simplified distribution or edist if no closed form exists
# Sum of two normals simplifies to a normal z <- normal(0, 1) + normal(2, 3) z # Normal(mu = 2, var = 4) # Shift a distribution by a constant normal(0, 1) + 5 # Normal(mu = 5, var = 1)# Sum of two normals simplifies to a normal z <- normal(0, 1) + normal(2, 3) z # Normal(mu = 2, var = 4) # Shift a distribution by a constant normal(0, 1) + 5 # Normal(mu = 5, var = 1)
Computes the distribution of where .
The result is .
affine_transform(x, A, b = NULL)affine_transform(x, A, b = NULL)
x |
A |
A |
A numeric matrix (or scalar for univariate). |
b |
An optional numeric vector (or scalar) for the offset. Default is a zero vector. |
For a univariate normal, scalars A and b are promoted
to 1x1 matrices and scalar internally. Returns a normal if the
result is 1-dimensional.
A normal or mvn distribution.
X <- mvn(c(0, 0), diag(2)) # Project to first component via 1x2 matrix Y <- affine_transform(X, A = matrix(c(1, 0), 1, 2), b = 5) mean(Y) # Scale a univariate normal Z <- affine_transform(normal(0, 1), A = 3, b = 2) mean(Z) vcov(Z)X <- mvn(c(0, 0), diag(2)) # Project to first component via 1x2 matrix Y <- affine_transform(X, A = matrix(c(1, 0), 1, 2), b = 5) mean(Y) # Scale a univariate normal Z <- affine_transform(normal(0, 1), A = 3, b = 2) mean(Z) vcov(Z)
Generic method for converting objects (such as fitted models) into
distribution objects from the algebraic.dist package.
as_dist(x, ...) ## S3 method for class 'dist' as_dist(x, ...)as_dist(x, ...) ## S3 method for class 'dist' as_dist(x, ...)
x |
The object to convert to a distribution. |
... |
Additional arguments to pass to methods. |
A dist object.
# Identity for existing distributions d <- normal(0, 1) identical(as_dist(d), d)# Identity for existing distributions d <- normal(0, 1) identical(as_dist(d), d)
Creates an S3 object representing a beta distribution with shape
parameters shape1 and shape2. The PDF on is
where = shape1, = shape2, and
is the beta function.
beta_dist(shape1, shape2)beta_dist(shape1, shape2)
shape1 |
First shape parameter, must be a positive scalar. |
shape2 |
Second shape parameter, must be a positive scalar. |
A beta_dist object with classes
c("beta_dist", "univariate_dist", "continuous_dist", "dist").
x <- beta_dist(shape1 = 2, shape2 = 5) mean(x) vcov(x) format(x)x <- beta_dist(shape1 = 2, shape2 = 5) mean(x) vcov(x) format(x)
Generic method for obtaining the cdf of an object.
cdf(x, ...)cdf(x, ...)
x |
The object to obtain the cdf of. |
... |
Additional arguments to pass. |
A function computing the cumulative distribution function.
x <- normal(0, 1) F <- cdf(x) F(0) # 0.5 (median of standard normal) F(1.96) # approximately 0.975x <- normal(0, 1) F <- cdf(x) F(0) # 0.5 (median of standard normal) F(1.96) # approximately 0.975
Returns a function that evaluates the beta CDF at given points.
## S3 method for class 'beta_dist' cdf(x, ...)## S3 method for class 'beta_dist' cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(q, log.p = FALSE, ...) returning the
CDF (or log-CDF) at q.
x <- beta_dist(2, 5) F <- cdf(x) F(0.3) F(0.5)x <- beta_dist(2, 5) F <- cdf(x) F(0.3) F(0.5)
chi_squared object.Method for obtaining the cdf of a chi_squared object.
## S3 method for class 'chi_squared' cdf(x, ...)## S3 method for class 'chi_squared' cdf(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes the cdf at point(s) t
x <- chi_squared(5) F <- cdf(x) F(5) F(10)x <- chi_squared(5) F <- cdf(x) F(5) F(10)
Falls back to realize to materialize the distribution
as an empirical_dist, then delegates to
cdf.empirical_dist.
## S3 method for class 'edist' cdf(x, ...)## S3 method for class 'edist' cdf(x, ...)
x |
An |
... |
Additional arguments forwarded to |
A function computing the empirical CDF.
set.seed(1) z <- normal(0, 1) * exponential(1) Fz <- cdf(z) Fz(0)set.seed(1) z <- normal(0, 1) * exponential(1) Fz <- cdf(z) Fz(0)
empirical_dist object x.If x is a multivariate empirical distribution, this function will
throw an error. It's only defined for univariate empirical distributions.
## S3 method for class 'empirical_dist' cdf(x, ...)## S3 method for class 'empirical_dist' cdf(x, ...)
x |
The empirical distribution object. |
... |
Additional arguments to pass (not used)) |
A function that takes a numeric vector t and returns the
empirical cdf of x evaluated at t.
ed <- empirical_dist(c(1, 2, 3, 4, 5)) Fx <- cdf(ed) Fx(3) # 0.6 Fx(c(1, 5)) # 0.2, 1.0ed <- empirical_dist(c(1, 2, 3, 4, 5)) Fx <- cdf(ed) Fx(3) # 0.6 Fx(c(1, 5)) # 0.2, 1.0
exponential object.Method to obtain the cdf of an exponential object.
## S3 method for class 'exponential' cdf(x, ...)## S3 method for class 'exponential' cdf(x, ...)
x |
The object to obtain the cdf of |
... |
Additional arguments (not used) |
A function function(q, lower.tail = TRUE, log.p = FALSE, ...)
that computes the cdf (or log-cdf) of the exponential distribution.
x <- exponential(rate = 1) F <- cdf(x) F(1) F(2)x <- exponential(rate = 1) F <- cdf(x) F(1) F(2)
gamma_dist object.Method for obtaining the cdf of a gamma_dist object.
## S3 method for class 'gamma_dist' cdf(x, ...)## S3 method for class 'gamma_dist' cdf(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes the cdf at point(s) t
x <- gamma_dist(shape = 2, rate = 1) F <- cdf(x) F(1) F(2)x <- gamma_dist(shape = 2, rate = 1) F <- cdf(x) F(1) F(2)
Returns a function that evaluates the log-normal CDF at given points.
## S3 method for class 'lognormal' cdf(x, ...)## S3 method for class 'lognormal' cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(q, log.p = FALSE, ...) returning the
CDF (or log-CDF) at q.
x <- lognormal(0, 1) F <- cdf(x) F(1) F(2)x <- lognormal(0, 1) F <- cdf(x) F(1) F(2)
Returns a function that evaluates the mixture CDF at given points.
The mixture CDF is .
## S3 method for class 'mixture' cdf(x, ...)## S3 method for class 'mixture' cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(q, ...) returning the CDF at q.
m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) F <- cdf(m) F(0) F(5)m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) F <- cdf(m) F(0) F(5)
mvn object.Method for obtaining the CDF of a mvn object.
## S3 method for class 'mvn' cdf(x, ...)## S3 method for class 'mvn' cdf(x, ...)
x |
The object to obtain the CDF of |
... |
Additional arguments to pass (not used) |
A function computing the multivariate normal CDF.
X <- mvn(c(0, 0), diag(2)) F <- cdf(X) F(c(0, 0))X <- mvn(c(0, 0), diag(2)) F <- cdf(X) F(c(0, 0))
normal object.Method for obtaining the cdf of an normal object.
## S3 method for class 'normal' cdf(x, ...)## S3 method for class 'normal' cdf(x, ...)
x |
The object to obtain the cdf of |
... |
Additional arguments to pass (not used) |
A function function(q, lower.tail = TRUE, log.p = FALSE, ...)
that computes the cdf (or log-cdf) of the normal distribution at q.
x <- normal(0, 1) F <- cdf(x) F(0) F(1.96)x <- normal(0, 1) F <- cdf(x) F(0) F(1.96)
Returns a function that evaluates the Poisson CDF at given points.
## S3 method for class 'poisson_dist' cdf(x, ...)## S3 method for class 'poisson_dist' cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(q, log.p = FALSE, ...) returning the
CDF (or log-CDF) at q.
x <- poisson_dist(5) F <- cdf(x) F(5) F(10)x <- poisson_dist(5) F <- cdf(x) F(5) F(10)
Returns a function that evaluates the uniform CDF at given points.
## S3 method for class 'uniform_dist' cdf(x, ...)## S3 method for class 'uniform_dist' cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(q, log.p = FALSE, ...) returning the
CDF (or log-CDF) at q.
x <- uniform_dist(0, 10) F <- cdf(x) F(5) F(10)x <- uniform_dist(0, 10) F <- cdf(x) F(5) F(10)
Returns a function that evaluates the Weibull CDF at given points.
## S3 method for class 'weibull_dist' cdf(x, ...)## S3 method for class 'weibull_dist' cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(q, log.p = FALSE, ...) returning the
CDF (or log-CDF) at q.
x <- weibull_dist(shape = 2, scale = 3) F <- cdf(x) F(1) F(3)x <- weibull_dist(shape = 2, scale = 3) F <- cdf(x) F(1) F(3)
Construct a chi-squared distribution object.
chi_squared(df)chi_squared(df)
df |
Degrees of freedom (positive scalar) |
A chi_squared object
x <- chi_squared(df = 5) mean(x) vcov(x) format(x)x <- chi_squared(df = 5) mean(x) vcov(x) format(x)
Returns the limiting distribution of the standardized sample mean
under the Central Limit Theorem.
For a univariate distribution with variance , this is
. For a multivariate distribution with covariance
matrix , this is .
clt(base_dist)clt(base_dist)
base_dist |
A |
A normal or mvn distribution representing the
CLT limiting distribution.
# CLT for Exp(2): sqrt(n)(Xbar - 1/2) -> N(0, 1/4) x <- exponential(rate = 2) z <- clt(x) mean(z) vcov(z)# CLT for Exp(2): sqrt(n)(Xbar - 1/2) -> N(0, 1/4) x <- exponential(rate = 2) z <- clt(x) mean(z) vcov(z)
x given condition P.Generic method for obtaining the conditional distribution of a distribution
object x given condition P.
conditional(x, P, ...)conditional(x, P, ...)
x |
The empirical distribution object. |
P |
The predicate function to condition |
... |
additional arguments to pass into |
A distribution object for the conditional distribution.
d <- empirical_dist(1:100) # condition on values greater than 50 d_gt50 <- conditional(d, function(x) x > 50) mean(d_gt50)d <- empirical_dist(1:100) # condition on values greater than 50 d_gt50 <- conditional(d, function(x) x > 50) mean(d_gt50)
x | P(x), of
dist object x.Falls back to MC: materializes x via ensure_realized() and
then conditions on the resulting empirical distribution.
## S3 method for class 'dist' conditional(x, P, n = 10000L, ...)## S3 method for class 'dist' conditional(x, P, n = 10000L, ...)
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 |
An empirical_dist approximating the conditional distribution.
set.seed(1) x <- exponential(1) # Condition on X > 2 x_gt2 <- conditional(x, function(t) t > 2) mean(x_gt2)set.seed(1) x <- exponential(1) # Condition on X > 2 x_gt2 <- conditional(x, function(t) t > 2) mean(x_gt2)
Falls back to realize and delegates to
conditional.empirical_dist.
## S3 method for class 'edist' conditional(x, P, ...)## S3 method for class 'edist' conditional(x, P, ...)
x |
An |
P |
Predicate function to condition on. |
... |
Additional arguments forwarded to the predicate |
A conditional empirical_dist.
set.seed(1) z <- normal(0, 1) + exponential(1) z_pos <- conditional(z, function(t) t > 2) mean(z_pos)set.seed(1) z <- normal(0, 1) + exponential(1) z_pos <- conditional(z, function(t) t > 2) mean(z_pos)
x | P(x), of
empirical_dist object x.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:
## S3 method for class 'empirical_dist' conditional(x, P, ...)## S3 method for class 'empirical_dist' conditional(x, P, ...)
x |
The empirical distribution object. |
P |
The predicate function to condition the data on. |
... |
additional arguments to pass into |
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.
An empirical_dist containing only rows satisfying P.
mat <- matrix(c(1, 5, 2, 3, 4, 1, 6, 2), ncol = 2) ed <- empirical_dist(mat) # Condition on first column being greater than second ed_cond <- conditional(ed, function(d) d[1] > d[2]) nobs(ed_cond)mat <- matrix(c(1, 5, 2, 3, 4, 1, 6, 2), ncol = 2) ed <- empirical_dist(mat) # Condition on first column being greater than second ed_cond <- conditional(ed, function(d) d[1] > d[2]) nobs(ed_cond)
For a mixture of distributions that support closed-form conditioning (e.g. MVN), uses Bayes' rule to update the mixing weights:
where is the marginal density of component at the
observed values. The component conditionals are computed via
conditional(component_k, given_indices = ..., given_values = ...).
## S3 method for class 'mixture' conditional(x, P = NULL, ..., given_indices = NULL, given_values = NULL)## S3 method for class 'mixture' conditional(x, P = NULL, ..., given_indices = NULL, given_values = NULL)
x |
A |
P |
Optional predicate function for MC fallback. |
... |
Additional arguments. |
given_indices |
Integer vector of observed variable indices. |
given_values |
Numeric vector of observed values. |
Falls back to MC realization if P is provided or if any
component does not support given_indices/given_values.
A mixture or empirical_dist object.
# Closed-form conditioning on MVN mixture m <- mixture( list(mvn(c(0, 0), diag(2)), mvn(c(3, 3), diag(2))), c(0.5, 0.5) ) # Condition on X2 = 1 mc <- conditional(m, given_indices = 2, given_values = 1) mean(mc)# Closed-form conditioning on MVN mixture m <- mixture( list(mvn(c(0, 0), diag(2)), mvn(c(3, 3), diag(2))), c(0.5, 0.5) ) # Condition on X2 = 1 mc <- conditional(m, given_indices = 2, given_values = 1) mean(mc)
Supports two calling patterns:
Closed-form (via given_indices and
given_values): Uses the exact Schur complement formula.
Returns a normal (1D result) or mvn.
Predicate-based (via P): Falls back to MC
realization via ensure_realized.
## S3 method for class 'mvn' conditional(x, P = NULL, ..., given_indices = NULL, given_values = NULL)## S3 method for class 'mvn' conditional(x, P = NULL, ..., given_indices = NULL, given_values = NULL)
x |
An |
P |
Optional predicate function for MC fallback. |
... |
Additional arguments forwarded to the predicate |
given_indices |
Integer vector of observed variable indices. |
given_values |
Numeric vector of observed values (same length as
|
A normal, mvn, or empirical_dist object.
# Closed-form conditioning: X2 | X1 = 1 sigma <- matrix(c(1, 0.5, 0.5, 1), 2, 2) X <- mvn(c(0, 0), sigma) X2_given <- conditional(X, given_indices = 1, given_values = 1) mean(X2_given) vcov(X2_given) # Predicate-based MC fallback (slower) set.seed(42) X2_mc <- conditional(X, P = function(x) x[1] > 0)# Closed-form conditioning: X2 | X1 = 1 sigma <- matrix(c(1, 0.5, 0.5, 1), 2, 2) X <- mvn(c(0, 0), sigma) X2_given <- conditional(X, given_indices = 1, given_values = 1) mean(X2_given) vcov(X2_given) # Predicate-based MC fallback (slower) set.seed(42) X2_mc <- conditional(X, P = function(x) x[1] > 0)
A countably infinite support set, such as the non-negative
integers. It satisfies the concept of a support (see has,
infimum, supremum, dim).
lower_boundInteger lower bound of the set.
new()
Initialize a countable set.
countable_set$new(lower = 0L)
lowerInteger lower bound (default 0).
clone()
The objects of this class are cloneable with this method.
countable_set$clone(deep = FALSE)
deepWhether to make a deep clone.
Returns the limiting distribution of
under the Delta Method. For a univariate distribution, this is
. For a multivariate distribution with
Jacobian , this is .
delta_clt(base_dist, g, dg)delta_clt(base_dist, g, dg)
base_dist |
A |
g |
The function to apply to the sample mean. |
dg |
The derivative (univariate) or Jacobian function (multivariate)
of |
A normal or mvn distribution representing the
Delta Method limiting distribution.
# Delta method: g = exp, dg = exp x <- exponential(rate = 1) z <- delta_clt(x, g = exp, dg = exp) mean(z) vcov(z)# Delta method: g = exp, dg = exp x <- exponential(rate = 1) z <- delta_clt(x, g = exp, dg = exp) mean(z) vcov(z)
Returns a function that evaluates the beta PDF at given points.
## S3 method for class 'beta_dist' density(x, ...)## S3 method for class 'beta_dist' density(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log = FALSE, ...) returning the
density (or log-density) at t.
x <- beta_dist(2, 5) f <- density(x) f(0.3) f(0.5)x <- beta_dist(2, 5) f <- density(x) f(0.3) f(0.5)
chi_squared object.Method for obtaining the density (pdf) of a chi_squared object.
## S3 method for class 'chi_squared' density(x, ...)## S3 method for class 'chi_squared' density(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes the pdf at point(s) t
x <- chi_squared(5) f <- density(x) f(5) f(10)x <- chi_squared(5) f <- density(x) f(5) f(10)
Falls back to realize and delegates to
density.empirical_dist.
## S3 method for class 'edist' density(x, ...)## S3 method for class 'edist' density(x, ...)
x |
An |
... |
Additional arguments forwarded to |
A function computing the empirical density (PMF).
set.seed(1) z <- normal(0, 1) * exponential(1) fz <- density(z)set.seed(1) z <- normal(0, 1) * exponential(1) fz <- density(z)
empirical_dist object.Method for obtaining the pdf of a empirical_dist object.
## S3 method for class 'empirical_dist' density(x, ...)## S3 method for class 'empirical_dist' density(x, ...)
x |
The object to obtain the pdf of. |
... |
Additional arguments to pass into the pdf function. |
A function computing the empirical PMF at given points.
sort tibble lexicographically and do a binary search to find upper
and lower bound in log(nobs(x)) time.
ed <- empirical_dist(c(1, 2, 2, 3, 3, 3)) f <- density(ed) f(2) # 2/6 f(3, log = TRUE) # log(3/6)ed <- empirical_dist(c(1, 2, 2, 3, 3, 3)) f <- density(ed) f(2) # 2/6 f(3, log = TRUE) # log(3/6)
exponential object.Method to obtain the pdf of an exponential object.
## S3 method for class 'exponential' density(x, ...)## S3 method for class 'exponential' density(x, ...)
x |
The object to obtain the pdf of |
... |
Additional arguments (not used) |
A function function(t, log = FALSE, ...) that computes
the pdf (or log-pdf) of the exponential distribution at t.
x <- exponential(rate = 2) f <- density(x) f(0) f(1)x <- exponential(rate = 2) f <- density(x) f(0) f(1)
gamma_dist object.Method for obtaining the density (pdf) of a gamma_dist object.
## S3 method for class 'gamma_dist' density(x, ...)## S3 method for class 'gamma_dist' density(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes the pdf at point(s) t
x <- gamma_dist(shape = 2, rate = 1) f <- density(x) f(1) f(2)x <- gamma_dist(shape = 2, rate = 1) f <- density(x) f(1) f(2)
Returns a function that evaluates the log-normal PDF at given points.
## S3 method for class 'lognormal' density(x, ...)## S3 method for class 'lognormal' density(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log = FALSE, ...) returning the
density (or log-density) at t.
x <- lognormal(0, 1) f <- density(x) f(1) f(2)x <- lognormal(0, 1) f <- density(x) f(1) f(2)
Returns a function that evaluates the mixture density at given points.
The mixture density is .
## S3 method for class 'mixture' density(x, ...)## S3 method for class 'mixture' density(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log = FALSE, ...) returning the
density (or log-density) at t.
m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) f <- density(m) f(0) f(2.5)m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) f <- density(m) f(0) f(2.5)
mvn object (multivariate
normal).Function generator for obtaining the pdf of an mvn object (multivariate
normal).
## S3 method for class 'mvn' density(x, ...)## S3 method for class 'mvn' density(x, ...)
x |
The |
... |
Additional arguments passed to |
A function function(obs, log = FALSE, ...) that computes the
pdf (or log-pdf) of the multivariate normal distribution.
X <- mvn(c(0, 0), diag(2)) f <- density(X) f(c(0, 0)) f(c(1, 1))X <- mvn(c(0, 0), diag(2)) f <- density(X) f(c(0, 0)) f(c(1, 1))
normal object.Method for obtaining the pdf of an normal object.
## S3 method for class 'normal' density(x, ...)## S3 method for class 'normal' density(x, ...)
x |
The object to obtain the pdf of |
... |
Additional arguments to pass (not used) |
A function function(t, log = FALSE, ...) that computes the
pdf (or log-pdf) of the normal distribution at t.
x <- normal(0, 1) f <- density(x) f(0) f(1)x <- normal(0, 1) f <- density(x) f(0) f(1)
Returns a function that evaluates the Poisson PMF at given points.
## S3 method for class 'poisson_dist' density(x, ...)## S3 method for class 'poisson_dist' density(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(k, log = FALSE, ...) returning the
probability mass (or log-probability) at k.
x <- poisson_dist(5) f <- density(x) f(5) f(0)x <- poisson_dist(5) f <- density(x) f(5) f(0)
Returns a function that evaluates the uniform PDF at given points.
## S3 method for class 'uniform_dist' density(x, ...)## S3 method for class 'uniform_dist' density(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log = FALSE, ...) returning the
density (or log-density) at t.
x <- uniform_dist(0, 10) f <- density(x) f(5) f(15)x <- uniform_dist(0, 10) f <- density(x) f(5) f(15)
Returns a function that evaluates the Weibull PDF at given points.
## S3 method for class 'weibull_dist' density(x, ...)## S3 method for class 'weibull_dist' density(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log = FALSE, ...) returning the
density (or log-density) at t.
x <- weibull_dist(shape = 2, scale = 3) f <- density(x) f(1) f(3)x <- weibull_dist(shape = 2, scale = 3) f <- density(x) f(1) f(3)
Dimension of a beta distribution (always 1).
## S3 method for class 'beta_dist' dim(x)## S3 method for class 'beta_dist' dim(x)
x |
A |
1.
dim(beta_dist(2, 5))dim(beta_dist(2, 5))
chi_squared object.Retrieve the dimension of a chi_squared object.
## S3 method for class 'chi_squared' dim(x)## S3 method for class 'chi_squared' dim(x)
x |
The |
1 (univariate)
dim(chi_squared(5))dim(chi_squared(5))
Get the dimension of a countable set.
## S3 method for class 'countable_set' dim(x)## S3 method for class 'countable_set' dim(x)
x |
A |
1 (always univariate).
cs <- countable_set$new(0L) dim(cs) # 1cs <- countable_set$new(0L) dim(cs) # 1
edist object.Determines the dimension by drawing a single sample and checking whether it is a matrix (multivariate) or scalar (univariate).
## S3 method for class 'edist' dim(x)## S3 method for class 'edist' dim(x)
x |
The |
Integer; the number of dimensions.
z <- normal(0, 1) * exponential(1) dim(z)z <- normal(0, 1) * exponential(1) dim(z)
empirical_dist object.Method for obtaining the dimension of a empirical_dist object.
## S3 method for class 'empirical_dist' dim(x)## S3 method for class 'empirical_dist' dim(x)
x |
The object to obtain the dimension of. |
Integer; the number of dimensions.
ed1 <- empirical_dist(c(1, 2, 3)) dim(ed1) # 1 ed2 <- empirical_dist(matrix(1:6, ncol = 2)) dim(ed2) # 2ed1 <- empirical_dist(c(1, 2, 3)) dim(ed1) # 1 ed2 <- empirical_dist(matrix(1:6, ncol = 2)) dim(ed2) # 2
exponential object.Method to obtain the dimension of an exponential object.
## S3 method for class 'exponential' dim(x)## S3 method for class 'exponential' dim(x)
x |
The |
The dimension of the exponential object
dim(exponential(rate = 1))dim(exponential(rate = 1))
Return the dimension of the finite set.
## S3 method for class 'finite_set' dim(x)## S3 method for class 'finite_set' dim(x)
x |
A finite set. |
Integer; the dimension of the set.
fs <- finite_set$new(c(1, 3, 5, 7)) dim(fs) # 1fs <- finite_set$new(c(1, 3, 5, 7)) dim(fs) # 1
gamma_dist object.Retrieve the dimension of a gamma_dist object.
## S3 method for class 'gamma_dist' dim(x)## S3 method for class 'gamma_dist' dim(x)
x |
The |
1 (univariate)
dim(gamma_dist(2, 1))dim(gamma_dist(2, 1))
Return the dimension of the interval.
## S3 method for class 'interval' dim(x)## S3 method for class 'interval' dim(x)
x |
An interval object. |
Integer; the number of interval components.
iv <- interval$new(lower = 0, upper = 1) dim(iv) # 1iv <- interval$new(lower = 0, upper = 1) dim(iv) # 1
Dimension of a log-normal distribution (always 1).
## S3 method for class 'lognormal' dim(x)## S3 method for class 'lognormal' dim(x)
x |
A |
1.
dim(lognormal(0, 1))dim(lognormal(0, 1))
Returns the dimension of the first component (all components are assumed to have the same dimension).
## S3 method for class 'mixture' dim(x)## S3 method for class 'mixture' dim(x)
x |
A |
The dimension of the distribution.
m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) dim(m)m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) dim(m)
mvn object.Method for obtaining the dimension of an mvn object.
## S3 method for class 'mvn' dim(x)## S3 method for class 'mvn' dim(x)
x |
The object to obtain the dimension of |
The dimension of the mvn object
dim(mvn(c(0, 0, 0)))dim(mvn(c(0, 0, 0)))
normal object.Method for obtaining the dimension of a normal object.
## S3 method for class 'normal' dim(x)## S3 method for class 'normal' dim(x)
x |
The |
The dimension of the normal object
dim(normal(0, 1))dim(normal(0, 1))
Dimension of a Poisson distribution (always 1).
## S3 method for class 'poisson_dist' dim(x)## S3 method for class 'poisson_dist' dim(x)
x |
A |
1.
dim(poisson_dist(5))dim(poisson_dist(5))
Dimension of a uniform distribution (always 1).
## S3 method for class 'uniform_dist' dim(x)## S3 method for class 'uniform_dist' dim(x)
x |
A |
1.
dim(uniform_dist(0, 1))dim(uniform_dist(0, 1))
Dimension of a Weibull distribution (always 1).
## S3 method for class 'weibull_dist' dim(x)## S3 method for class 'weibull_dist' dim(x)
x |
A |
1.
dim(weibull_dist(2, 3))dim(weibull_dist(2, 3))
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.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.
edist(e, vars)edist(e, vars)
e |
the expression to evaluate against the arguments. |
vars |
the list of distributions (with variable names)
to evaluate the expression |
An edist object.
x <- normal(0, 1) y <- normal(2, 3) e <- edist(quote(x + y), list(x = x, y = y)) ex <- normal(0, 1) y <- normal(2, 3) e <- edist(quote(x + y), list(x = x, y = y)) e
Construct empirical distribution object.
empirical_dist(data)empirical_dist(data)
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. |
An empirical_dist object.
# Univariate empirical distribution from a vector ed <- empirical_dist(c(1, 2, 3, 4, 5)) mean(ed) # Multivariate empirical distribution from a matrix mat <- matrix(c(1, 2, 3, 4, 5, 6), ncol = 2) ed_mv <- empirical_dist(mat) dim(ed_mv)# Univariate empirical distribution from a vector ed <- empirical_dist(c(1, 2, 3, 4, 5)) mean(ed) # Multivariate empirical distribution from a matrix mat <- matrix(c(1, 2, 3, 4, 5, 6), ncol = 2) ed_mv <- empirical_dist(mat) dim(ed_mv)
f with respect to
x.Generic method for obtaining the expectation of f with respect to
x.
expectation(x, g, ...)expectation(x, g, ...)
x |
The distribution object. |
g |
The function to take the expectation of. |
... |
Additional arguments to pass into |
The expected value of g(x).
x <- exponential(1) # E[X] for Exp(1) is 1 expectation(x, function(t) t)x <- exponential(1) # E[X] for Exp(1) is 1 expectation(x, function(t) t)
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.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).
expectation_data( data, g = function(x) x, ..., compute_stats = TRUE, alpha = 0.05 )expectation_data( data, g = function(x) x, ..., compute_stats = TRUE, alpha = 0.05 )
data |
a matrix of data |
g |
a function to apply to each row of the data |
... |
additional arguments to pass to |
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) |
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.
set.seed(42) data <- matrix(rnorm(200), ncol = 2) # sample mean with confidence interval expectation_data(data) # just the point estimate, no CI expectation_data(data, compute_stats = FALSE) # expectation of a function of the data (row-wise) expectation_data(data, g = function(x) sum(x^2))set.seed(42) data <- matrix(rnorm(200), ncol = 2) # sample mean with confidence interval expectation_data(data) # just the point estimate, no CI expectation_data(data, compute_stats = FALSE) # expectation of a function of the data (row-wise) expectation_data(data, g = function(x) sum(x^2))
dist ObjectExpectation 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.
## S3 method for class 'dist' expectation(x, g = function(t) t, ..., control = list())## S3 method for class 'dist' expectation(x, g = function(t) t, ..., control = list())
x |
A |
g |
Characteristic function of interest, defaults to identity. |
... |
Additional arguments to pass to |
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 |
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
# MC expectation of X^2 where X ~ Exp(1) set.seed(1) ex <- exponential(1) expectation(ex, g = function(t) t^2)# MC expectation of X^2 where X ~ Exp(1) set.seed(1) ex <- exponential(1) expectation(ex, g = function(t) t^2)
empirical_dist object x
under function g.Method for obtaining the expectation of empirical_dist object x
under function g.
## S3 method for class 'empirical_dist' expectation(x, g = function(t) t, ..., control = list())## S3 method for class 'empirical_dist' expectation(x, g = function(t) t, ..., control = list())
x |
The distribution object. |
g |
The function to take the expectation of. |
... |
Additional arguments to pass into function |
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 |
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
ed <- empirical_dist(c(1, 2, 3, 4, 5)) expectation(ed) # E[X] = 3 expectation(ed, function(x) x^2) # E[X^2] = 11ed <- empirical_dist(c(1, 2, 3, 4, 5)) expectation(ed) # E[X] = 3 expectation(ed, function(x) x^2) # E[X^2] = 11
Computes using truncated summation over the support.
The summation is truncated at the quantile to
ensure negligible truncation error.
## S3 method for class 'poisson_dist' expectation(x, g, ...)## S3 method for class 'poisson_dist' expectation(x, g, ...)
x |
A |
g |
A function to take the expectation of. |
... |
Additional arguments passed to |
The expected value .
x <- poisson_dist(5) expectation(x, identity) expectation(x, function(k) k^2)x <- poisson_dist(5) expectation(x, identity) expectation(x, function(k) k^2)
f with respect to a
univariate_dist object x.Assumes the support is a contiguous interval that has operations for retrieving the lower and upper bounds.
## S3 method for class 'univariate_dist' expectation(x, g, ..., control = list())## S3 method for class 'univariate_dist' expectation(x, g, ..., control = list())
x |
The distribution object. |
g |
The function to take the expectation of. |
... |
Additional arguments to pass into |
control |
An (optional) list of control parameters for |
The expected value (numeric scalar), or the full
integrate() result if compute_stats = TRUE.
x <- normal(3, 4) # E[X] for Normal(3, 4) is 3 expectation(x, function(t) t) # E[X^2] for Exp(1) is 2 expectation(exponential(1), function(t) t^2)x <- normal(3, 4) # E[X] for Normal(3, 4) is 3 expectation(x, function(t) t) # E[X^2] for Exp(1) is 2 expectation(exponential(1), function(t) t^2)
Construct exponential distribution object.
exponential(rate)exponential(rate)
rate |
failure rate |
An exponential distribution object.
x <- exponential(rate = 2) mean(x) vcov(x) format(x)x <- exponential(rate = 2) mean(x) vcov(x) format(x)
A finite set. It also satisfies the concept of a support.
valuesA vector of values.
new()
Initialize a finite set.
finite_set$new(values)
valuesA vector of values.
has()
Determine if a value is contained in the finite set.
finite_set$has(x)
xA vector of values.
infimum()
Get the infimum of the finite set.
finite_set$infimum()
A numeric vector of infimums.
supremum()
Get the supremum of the finite set.
finite_set$supremum()
A numeric vector of supremums.
dim()
Get the dimension of the finite set.
finite_set$dim()
The dimension of the finite set.
clone()
The objects of this class are cloneable with this method.
finite_set$clone(deep = FALSE)
deepWhether to make a deep clone.
beta_dist object as a character string.Format a beta_dist object as a character string.
## S3 method for class 'beta_dist' format(x, ...)## S3 method for class 'beta_dist' format(x, ...)
x |
A |
... |
Additional arguments (not used). |
A character string describing the distribution.
format(beta_dist(2, 5))format(beta_dist(2, 5))
chi_squared object as a character string.Format a chi_squared object as a character string.
## S3 method for class 'chi_squared' format(x, ...)## S3 method for class 'chi_squared' format(x, ...)
x |
The |
... |
Additional arguments (not used) |
A character string describing the distribution
format(chi_squared(5))format(chi_squared(5))
edist objects.Format method for edist objects.
## S3 method for class 'edist' format(x, ...)## S3 method for class 'edist' format(x, ...)
x |
The object to format |
... |
Additional arguments (not used) |
A character string
z <- normal(0, 1) * exponential(2) format(z)z <- normal(0, 1) * exponential(2) format(z)
empirical_dist objects.Format method for empirical_dist objects.
## S3 method for class 'empirical_dist' format(x, ...)## S3 method for class 'empirical_dist' format(x, ...)
x |
The object to format |
... |
Additional arguments (not used) |
A character string
ed <- empirical_dist(c(1, 2, 3, 4, 5)) format(ed)ed <- empirical_dist(c(1, 2, 3, 4, 5)) format(ed)
exponential objects.Format method for exponential objects.
## S3 method for class 'exponential' format(x, ...)## S3 method for class 'exponential' format(x, ...)
x |
The |
... |
Additional arguments (not used) |
A character string
format(exponential(rate = 2))format(exponential(rate = 2))
gamma_dist object as a character string.Format a gamma_dist object as a character string.
## S3 method for class 'gamma_dist' format(x, ...)## S3 method for class 'gamma_dist' format(x, ...)
x |
The |
... |
Additional arguments (not used) |
A character string describing the distribution
format(gamma_dist(2, 1))format(gamma_dist(2, 1))
lognormal object as a character string.Format a lognormal object as a character string.
## S3 method for class 'lognormal' format(x, ...)## S3 method for class 'lognormal' format(x, ...)
x |
A |
... |
Additional arguments (not used). |
A character string describing the distribution.
format(lognormal(0, 1))format(lognormal(0, 1))
mixture object as a character string.Format a mixture object as a character string.
## S3 method for class 'mixture' format(x, ...)## S3 method for class 'mixture' format(x, ...)
x |
A |
... |
Additional arguments (not used). |
A character string describing the mixture.
m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) format(m)m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) format(m)
mvn objects.Format method for mvn objects.
## S3 method for class 'mvn' format(x, ...)## S3 method for class 'mvn' format(x, ...)
x |
The object to format |
... |
Additional arguments (not used) |
A character string
format(mvn(c(0, 0)))format(mvn(c(0, 0)))
normal objects.Format method for normal objects.
## S3 method for class 'normal' format(x, ...)## S3 method for class 'normal' format(x, ...)
x |
The object to format |
... |
Additional arguments (not used) |
A character string
x <- normal(2, 3) format(x)x <- normal(2, 3) format(x)
poisson_dist object as a character string.Format a poisson_dist object as a character string.
## S3 method for class 'poisson_dist' format(x, ...)## S3 method for class 'poisson_dist' format(x, ...)
x |
A |
... |
Additional arguments (not used). |
A character string describing the distribution.
format(poisson_dist(5))format(poisson_dist(5))
realized_dist object as a character string.Shows the number of samples and a summary of the source distribution.
## S3 method for class 'realized_dist' format(x, ...)## S3 method for class 'realized_dist' format(x, ...)
x |
A |
... |
Additional arguments (not used). |
A character string.
rd <- realize(normal(0, 1), n = 100) format(rd)rd <- realize(normal(0, 1), n = 100) format(rd)
uniform_dist object as a character string.Format a uniform_dist object as a character string.
## S3 method for class 'uniform_dist' format(x, ...)## S3 method for class 'uniform_dist' format(x, ...)
x |
A |
... |
Additional arguments (not used). |
A character string describing the distribution.
format(uniform_dist(0, 10))format(uniform_dist(0, 10))
weibull_dist object as a character string.Format a weibull_dist object as a character string.
## S3 method for class 'weibull_dist' format(x, ...)## S3 method for class 'weibull_dist' format(x, ...)
x |
A |
... |
Additional arguments (not used). |
A character string describing the distribution.
format(weibull_dist(2, 3))format(weibull_dist(2, 3))
Construct a gamma distribution object.
gamma_dist(shape, rate)gamma_dist(shape, rate)
shape |
Shape parameter (positive scalar) |
rate |
Rate parameter (positive scalar) |
A gamma_dist object
x <- gamma_dist(shape = 2, rate = 1) mean(x) vcov(x) format(x)x <- gamma_dist(shape = 2, rate = 1) mean(x) vcov(x) format(x)
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:
has: a function that returns a logical vector indicating whether each value in a vector is contained in the support
infimum: a function that returns the infimum of the support
supremum: a function that returns the supremum of the support
dim: a function that returns the dimension of the support
We provide two implementations that satisfy the concept:
interval: a support that is an infiite set of contiguous numeric values
finite_set: a support that is a finite set of values
Determine if a value is contained in the support.
has(object, x)has(object, x)
object |
A support object. |
x |
A vector of values. |
Logical vector indicating membership.
I <- interval$new(0, 1, lower_closed = TRUE, upper_closed = TRUE) has(I, 0.5) # TRUE has(I, 2) # FALSE S <- finite_set$new(c(1, 2, 3)) has(S, 2) # TRUE has(S, 4) # FALSEI <- interval$new(0, 1, lower_closed = TRUE, upper_closed = TRUE) has(I, 0.5) # TRUE has(I, 2) # FALSE S <- finite_set$new(c(1, 2, 3)) has(S, 2) # TRUE has(S, 4) # FALSE
Returns TRUE if all values are integers (within floating-point
tolerance) that are at least as large as the lower bound.
## S3 method for class 'countable_set' has(object, x)## S3 method for class 'countable_set' has(object, x)
object |
A |
x |
Value(s) to check. |
Logical; TRUE if all values are valid members of the set.
cs <- countable_set$new(0L) has(cs, c(0, 3, 5)) # TRUE has(cs, c(-1, 2)) # FALSE (negative integer) has(cs, 1.5) # FALSE (not integer)cs <- countable_set$new(0L) has(cs, c(0, 3, 5)) # TRUE has(cs, c(-1, 2)) # FALSE (negative integer) has(cs, 1.5) # FALSE (not integer)
Determine if a value is contained in the finite set.
## S3 method for class 'finite_set' has(object, x)## S3 method for class 'finite_set' has(object, x)
object |
A finite set. |
x |
A vector of values. |
Logical indicating membership.
fs <- finite_set$new(c(1, 3, 5, 7)) has(fs, 3) # TRUE has(fs, 4) # FALSEfs <- finite_set$new(c(1, 3, 5, 7)) has(fs, 3) # TRUE has(fs, 4) # FALSE
Determine if a value is contained in the interval.
## S3 method for class 'interval' has(object, x)## S3 method for class 'interval' has(object, x)
object |
An interval object. |
x |
A vector of values. |
Logical vector indicating containment.
iv <- interval$new(lower = 0, upper = 1) has(iv, 0.5) # TRUE has(iv, 2.0) # FALSEiv <- interval$new(lower = 0, upper = 1) has(iv, 0.5) # TRUE has(iv, 2.0) # FALSE
chi_squared object.Method for obtaining the hazard function of a chi_squared object.
## S3 method for class 'chi_squared' hazard(x, ...)## S3 method for class 'chi_squared' hazard(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes h(t) = f(t) / S(t)
x <- chi_squared(5) h <- hazard(x) h(5)x <- chi_squared(5) h <- hazard(x) h(5)
Computes from the density and survival
function.
## S3 method for class 'continuous_dist' hazard(x, ...) hazard(x, ...)## S3 method for class 'continuous_dist' hazard(x, ...) hazard(x, ...)
x |
The object to obtain the hazard function of. |
... |
Additional arguments to pass. |
A function function(t, ...) returning the hazard rate.
A function computing the hazard rate at given points.
x <- normal(0, 1) h <- hazard(x) h(0) x <- exponential(2) h <- hazard(x) h(1) # hazard rate at t = 1 (constant for exponential)x <- normal(0, 1) h <- hazard(x) h(0) x <- exponential(2) h <- hazard(x) h(1) # hazard rate at t = 1 (constant for exponential)
exponential object.Method to obtain the hazard function of an exponential object.
## S3 method for class 'exponential' hazard(x, ...)## S3 method for class 'exponential' hazard(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function function(t, log = FALSE, ...) that computes
the hazard rate (or log-hazard) of the exponential distribution.
x <- exponential(rate = 2) h <- hazard(x) h(1) h(5)x <- exponential(rate = 2) h <- hazard(x) h(1) h(5)
gamma_dist object.Method for obtaining the hazard function of a gamma_dist object.
## S3 method for class 'gamma_dist' hazard(x, ...)## S3 method for class 'gamma_dist' hazard(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes h(t) = f(t) / S(t)
x <- gamma_dist(shape = 2, rate = 1) h <- hazard(x) h(1)x <- gamma_dist(shape = 2, rate = 1) h <- hazard(x) h(1)
Returns a function that evaluates the log-normal hazard rate
for .
## S3 method for class 'lognormal' hazard(x, ...)## S3 method for class 'lognormal' hazard(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log = FALSE) returning the hazard
(or log-hazard) at t.
x <- lognormal(0, 1) h <- hazard(x) h(1) h(2)x <- lognormal(0, 1) h <- hazard(x) h(1) h(2)
Returns a function that evaluates the Weibull hazard rate
for .
## S3 method for class 'weibull_dist' hazard(x, ...)## S3 method for class 'weibull_dist' hazard(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log = FALSE) returning the hazard
(or log-hazard) at t.
x <- weibull_dist(shape = 2, scale = 3) h <- hazard(x) h(1) h(3)x <- weibull_dist(shape = 2, scale = 3) h <- hazard(x) h(1) h(3)
Get the infimum of the support.
infimum(object)infimum(object)
object |
A support object. |
The infimum (greatest lower bound) of the support.
I <- interval$new(0, 10) infimum(I) # 0 S <- finite_set$new(c(3, 7, 11)) infimum(S) # 3I <- interval$new(0, 10) infimum(I) # 0 S <- finite_set$new(c(3, 7, 11)) infimum(S) # 3
Get the infimum of a countable set.
## S3 method for class 'countable_set' infimum(object)## S3 method for class 'countable_set' infimum(object)
object |
A |
The lower bound (integer).
cs <- countable_set$new(0L) infimum(cs) # 0cs <- countable_set$new(0L) infimum(cs) # 0
Return the infimum of the finite set.
## S3 method for class 'finite_set' infimum(object)## S3 method for class 'finite_set' infimum(object)
object |
A finite set. |
Numeric; the minimum value(s).
fs <- finite_set$new(c(1, 3, 5, 7)) infimum(fs) # 1fs <- finite_set$new(c(1, 3, 5, 7)) infimum(fs) # 1
Return the (vector of) infimum of the interval.
## S3 method for class 'interval' infimum(object)## S3 method for class 'interval' infimum(object)
object |
An interval object. |
Numeric vector of lower bounds.
iv <- interval$new(lower = 0, upper = 1) infimum(iv) # 0iv <- interval$new(lower = 0, upper = 1) infimum(iv) # 0
An interval is a support that is a finite union of intervals.
lowerA numeric vector of lower bounds.
upperA numeric vector of upper bounds.
lower_closedA logical vector indicating whether the lower bound is closed.
upper_closedA logical vector indicating whether the upper bound is closed.
new()
Initialize an interval.
interval$new( lower = -Inf, upper = Inf, lower_closed = FALSE, upper_closed = FALSE )
lowerA numeric vector of lower bounds.
upperA numeric vector of upper bounds.
lower_closedA logical vector indicating whether the lower bound is closed.
upper_closedA logical vector indicating whether the upper bound is closed.
is_empty()
Determine if the interval is empty
interval$is_empty()
A logical vector indicating whether the interval is empty.
has()
Determine if a value is contained in the interval.
interval$has(x)
xA numeric vector of values.
A logical vector indicating whether each value is contained
infimum()
Get the infimum of the interval.
interval$infimum()
A numeric vector of infimums.
supremum()
Get the supremum of the interval.
interval$supremum()
A numeric vector of supremums.
dim()
Get the dimension of the interval.
interval$dim()
The dimension of the interval.
clone()
The objects of this class are cloneable with this method.
interval$clone(deep = FALSE)
deepWhether to make a deep clone.
Generic method for obtaining the quantile (inverse cdf) of an object.
inv_cdf(x, ...)inv_cdf(x, ...)
x |
The object to obtain the quantile of. |
... |
Additional arguments to pass. |
A function computing the quantile (inverse CDF).
x <- normal(0, 1) Q <- inv_cdf(x) Q(0.5) # 0 (median of standard normal) Q(0.975) # approximately 1.96x <- normal(0, 1) Q <- inv_cdf(x) Q(0.5) # 0 (median of standard normal) Q(0.975) # approximately 1.96
Returns a function that computes quantiles of the beta distribution.
## S3 method for class 'beta_dist' inv_cdf(x, ...)## S3 method for class 'beta_dist' inv_cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(p, lower.tail = TRUE, log.p = FALSE, ...)
returning the quantile at probability p.
x <- beta_dist(2, 5) q <- inv_cdf(x) q(0.5) q(0.95)x <- beta_dist(2, 5) q <- inv_cdf(x) q(0.5) q(0.95)
chi_squared
object.Method for obtaining the inverse cdf (quantile function) of a chi_squared
object.
## S3 method for class 'chi_squared' inv_cdf(x, ...)## S3 method for class 'chi_squared' inv_cdf(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes the quantile at probability p
x <- chi_squared(5) q <- inv_cdf(x) q(0.5) q(0.95)x <- chi_squared(5) q <- inv_cdf(x) q(0.5) q(0.95)
Falls back to realize and delegates to
inv_cdf.empirical_dist.
## S3 method for class 'edist' inv_cdf(x, ...)## S3 method for class 'edist' inv_cdf(x, ...)
x |
An |
... |
Additional arguments forwarded to
|
A function computing the empirical quantile function.
set.seed(1) z <- normal(0, 1) * exponential(1) qz <- inv_cdf(z) qz(0.5)set.seed(1) z <- normal(0, 1) * exponential(1) qz <- inv_cdf(z) qz(0.5)
empirical_dist object.Uses the empirical quantile function from the observed data.
## S3 method for class 'empirical_dist' inv_cdf(x, ...)## S3 method for class 'empirical_dist' inv_cdf(x, ...)
x |
The empirical distribution object. |
... |
Additional arguments (not used). |
A function that accepts a vector of probabilities p and returns
the corresponding quantiles.
ed <- empirical_dist(c(1, 2, 3, 4, 5)) qf <- inv_cdf(ed) qf(0.5) # median qf(c(0.25, 0.75)) # quartilesed <- empirical_dist(c(1, 2, 3, 4, 5)) qf <- inv_cdf(ed) qf(0.5) # median qf(c(0.25, 0.75)) # quartiles
exponential object.Method to obtain the inverse cdf of an exponential object.
## S3 method for class 'exponential' inv_cdf(x, ...)## S3 method for class 'exponential' inv_cdf(x, ...)
x |
The object to obtain the inverse cdf of |
... |
Additional arguments (not used) |
A function function(p, lower.tail = TRUE, log.p = FALSE, ...)
that computes the inverse cdf of the exponential distribution.
x <- exponential(rate = 1) q <- inv_cdf(x) q(0.5) q(0.95)x <- exponential(rate = 1) q <- inv_cdf(x) q(0.5) q(0.95)
gamma_dist
object.Method for obtaining the inverse cdf (quantile function) of a gamma_dist
object.
## S3 method for class 'gamma_dist' inv_cdf(x, ...)## S3 method for class 'gamma_dist' inv_cdf(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes the quantile at probability p
x <- gamma_dist(shape = 2, rate = 1) q <- inv_cdf(x) q(0.5) q(0.95)x <- gamma_dist(shape = 2, rate = 1) q <- inv_cdf(x) q(0.5) q(0.95)
Returns a function that computes quantiles of the log-normal distribution.
## S3 method for class 'lognormal' inv_cdf(x, ...)## S3 method for class 'lognormal' inv_cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(p, lower.tail = TRUE, log.p = FALSE, ...)
returning the quantile at probability p.
x <- lognormal(0, 1) q <- inv_cdf(x) q(0.5) q(0.95)x <- lognormal(0, 1) q <- inv_cdf(x) q(0.5) q(0.95)
normal object.Method for obtaining the inverse cdf of an normal object.
## S3 method for class 'normal' inv_cdf(x, ...)## S3 method for class 'normal' inv_cdf(x, ...)
x |
The object to obtain the inverse cdf of |
... |
Additional arguments to pass (not used) |
A function function(p, lower.tail = TRUE, log.p = FALSE, ...)
that computes the inverse cdf of the normal distribution.
x <- normal(0, 1) q <- inv_cdf(x) q(0.5) q(0.975)x <- normal(0, 1) q <- inv_cdf(x) q(0.5) q(0.975)
Returns a function that computes quantiles of the Poisson distribution.
## S3 method for class 'poisson_dist' inv_cdf(x, ...)## S3 method for class 'poisson_dist' inv_cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(p, lower.tail = TRUE, log.p = FALSE, ...)
returning the quantile at probability p.
x <- poisson_dist(5) q <- inv_cdf(x) q(0.5) q(0.95)x <- poisson_dist(5) q <- inv_cdf(x) q(0.5) q(0.95)
Returns a function that computes quantiles of the uniform distribution.
## S3 method for class 'uniform_dist' inv_cdf(x, ...)## S3 method for class 'uniform_dist' inv_cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(p, lower.tail = TRUE, log.p = FALSE, ...)
returning the quantile at probability p.
x <- uniform_dist(0, 10) q <- inv_cdf(x) q(0.5) q(0.9)x <- uniform_dist(0, 10) q <- inv_cdf(x) q(0.5) q(0.9)
Returns a function that computes quantiles of the Weibull distribution.
## S3 method for class 'weibull_dist' inv_cdf(x, ...)## S3 method for class 'weibull_dist' inv_cdf(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(p, lower.tail = TRUE, log.p = FALSE, ...)
returning the quantile at probability p.
x <- weibull_dist(shape = 2, scale = 3) q <- inv_cdf(x) q(0.5) q(0.95)x <- weibull_dist(shape = 2, scale = 3) q <- inv_cdf(x) q(0.5) q(0.95)
beta_dist.Test whether an object is a beta_dist.
is_beta_dist(x)is_beta_dist(x)
x |
The object to test. |
TRUE if x inherits from "beta_dist",
FALSE otherwise.
is_beta_dist(beta_dist(2, 5)) is_beta_dist(normal(0, 1))is_beta_dist(beta_dist(2, 5)) is_beta_dist(normal(0, 1))
chi_squared.Test whether an object is a chi_squared.
is_chi_squared(x)is_chi_squared(x)
x |
The object to test |
Logical; TRUE if x inherits from chi_squared
is_chi_squared(chi_squared(3)) is_chi_squared(normal(0, 1))is_chi_squared(chi_squared(3)) is_chi_squared(normal(0, 1))
x is a dist object.Function to determine whether an object x is a dist object.
is_dist(x)is_dist(x)
x |
The object to test |
Logical indicating whether x is a dist object.
is_dist(normal(0, 1)) # TRUE is_dist(42) # FALSEis_dist(normal(0, 1)) # TRUE is_dist(42) # FALSE
x is an edist object.Function to determine whether an object x is an edist object.
is_edist(x)is_edist(x)
x |
The object to test |
Logical; TRUE if x is an edist.
is_edist(normal(0, 1) * exponential(1)) # TRUE is_edist(normal(0, 1)) # FALSEis_edist(normal(0, 1) * exponential(1)) # TRUE is_edist(normal(0, 1)) # FALSE
x is an empirical_dist object.Function to determine whether an object x is an empirical_dist object.
is_empirical_dist(x)is_empirical_dist(x)
x |
The object to test |
Logical; TRUE if x is an empirical_dist.
ed <- empirical_dist(c(1, 2, 3)) is_empirical_dist(ed) # TRUE is_empirical_dist("abc") # FALSEed <- empirical_dist(c(1, 2, 3)) is_empirical_dist(ed) # TRUE is_empirical_dist("abc") # FALSE
x is an exponential object.Function to determine whether an object x is an exponential object.
is_exponential(x)is_exponential(x)
x |
The object to test |
Logical; TRUE if x is an exponential.
is_exponential(exponential(1)) is_exponential(normal(0, 1))is_exponential(exponential(1)) is_exponential(normal(0, 1))
gamma_dist.Test whether an object is a gamma_dist.
is_gamma_dist(x)is_gamma_dist(x)
x |
The object to test |
Logical; TRUE if x inherits from gamma_dist
is_gamma_dist(gamma_dist(2, 1)) is_gamma_dist(normal(0, 1))is_gamma_dist(gamma_dist(2, 1)) is_gamma_dist(normal(0, 1))
lognormal.Test whether an object is a lognormal.
is_lognormal(x)is_lognormal(x)
x |
The object to test. |
TRUE if x inherits from "lognormal",
FALSE otherwise.
is_lognormal(lognormal(0, 1)) is_lognormal(normal(0, 1))is_lognormal(lognormal(0, 1)) is_lognormal(normal(0, 1))
mixture distribution.Test whether an object is a mixture distribution.
is_mixture(x)is_mixture(x)
x |
The object to test. |
TRUE if x inherits from "mixture",
FALSE otherwise.
m <- mixture(list(normal(0, 1), normal(5, 2)), c(0.5, 0.5)) is_mixture(m) is_mixture(normal(0, 1))m <- mixture(list(normal(0, 1), normal(5, 2)), c(0.5, 0.5)) is_mixture(m) is_mixture(normal(0, 1))
x is an mvn object.Function to determine whether an object x is an mvn object.
is_mvn(x)is_mvn(x)
x |
The object to test |
Logical; TRUE if x is an mvn.
is_mvn(mvn(c(0, 0))) is_mvn(normal(0, 1))is_mvn(mvn(c(0, 0))) is_mvn(normal(0, 1))
x is an normal object.Function to determine whether an object x is an normal object.
is_normal(x)is_normal(x)
x |
The object to test |
Logical; TRUE if x is a normal.
is_normal(normal(0, 1)) is_normal(exponential(1))is_normal(normal(0, 1)) is_normal(exponential(1))
poisson_dist.Test whether an object is a poisson_dist.
is_poisson_dist(x)is_poisson_dist(x)
x |
The object to test. |
TRUE if x inherits from "poisson_dist",
FALSE otherwise.
is_poisson_dist(poisson_dist(5)) is_poisson_dist(normal(0, 1))is_poisson_dist(poisson_dist(5)) is_poisson_dist(normal(0, 1))
realized_dist.Test whether an object is a realized_dist.
is_realized_dist(x)is_realized_dist(x)
x |
The object to test. |
TRUE if x inherits from "realized_dist",
FALSE otherwise.
rd <- realize(normal(0, 1), n = 100) is_realized_dist(rd) # TRUE is_realized_dist(normal(0, 1)) # FALSErd <- realize(normal(0, 1), n = 100) is_realized_dist(rd) # TRUE is_realized_dist(normal(0, 1)) # FALSE
uniform_dist.Test whether an object is a uniform_dist.
is_uniform_dist(x)is_uniform_dist(x)
x |
The object to test. |
TRUE if x inherits from "uniform_dist",
FALSE otherwise.
is_uniform_dist(uniform_dist(0, 1)) is_uniform_dist(normal(0, 1))is_uniform_dist(uniform_dist(0, 1)) is_uniform_dist(normal(0, 1))
weibull_dist.Test whether an object is a weibull_dist.
is_weibull_dist(x)is_weibull_dist(x)
x |
The object to test. |
TRUE if x inherits from "weibull_dist",
FALSE otherwise.
is_weibull_dist(weibull_dist(2, 3)) is_weibull_dist(normal(0, 1))is_weibull_dist(weibull_dist(2, 3)) is_weibull_dist(normal(0, 1))
Returns the degenerate limiting distribution of the sample mean
under the Law of Large Numbers. The limit is a
point mass at the population mean (represented as a normal or mvn
with zero variance).
lln(base_dist)lln(base_dist)
base_dist |
A |
A normal or mvn distribution with zero variance,
representing the degenerate distribution at the mean.
# LLN for Exp(2): Xbar -> 1/2 (degenerate) x <- exponential(rate = 2) d <- lln(x) mean(d) vcov(d)# LLN for Exp(2): Xbar -> 1/2 (degenerate) x <- exponential(rate = 2) d <- lln(x) mean(d) vcov(d)
Creates an S3 object representing a log-normal distribution with the given
meanlog and sdlog parameters. The log-normal PDF is
for .
lognormal(meanlog = 0, sdlog = 1)lognormal(meanlog = 0, sdlog = 1)
meanlog |
Mean of the distribution on the log scale (default 0). |
sdlog |
Standard deviation on the log scale (default 1), must be positive. |
A lognormal object with classes
c("lognormal", "univariate_dist", "continuous_dist", "dist").
x <- lognormal(meanlog = 0, sdlog = 1) mean(x) vcov(x) format(x)x <- lognormal(meanlog = 0, sdlog = 1) mean(x) vcov(x) format(x)
x over components indices.Generic method for obtaining the marginal distribution of a distribution
object x over components indices.
marginal(x, indices)marginal(x, indices)
x |
The distribution object. |
indices |
The indices of the marginal distribution to obtain. |
A distribution object for the marginal over indices.
x <- mvn(c(0, 0), diag(2)) m <- marginal(x, 1) # marginal over first component mean(m) # 0x <- mvn(c(0, 0), diag(2)) m <- marginal(x, 1) # marginal over first component mean(m) # 0
empirical_dist object
x.Method for obtaining the marginal distribution of empirical_dist object
x.
## S3 method for class 'empirical_dist' marginal(x, indices)## S3 method for class 'empirical_dist' marginal(x, indices)
x |
The empirical distribution object. |
indices |
The indices of the marginal distribution to obtain. |
An empirical_dist over the selected columns.
mat <- matrix(1:12, ncol = 3) ed <- empirical_dist(mat) ed_marginal <- marginal(ed, c(1, 3)) dim(ed_marginal) # 2mat <- matrix(1:12, ncol = 3) ed <- empirical_dist(mat) ed_marginal <- marginal(ed, c(1, 3)) dim(ed_marginal) # 2
The marginal of a mixture is itself a mixture of the component marginals
with the same mixing weights:
.
## S3 method for class 'mixture' marginal(x, indices)## S3 method for class 'mixture' marginal(x, indices)
x |
A |
indices |
Integer vector of variable indices to keep. |
Requires all components to support marginal.
A mixture object with marginalized components.
# Mixture of bivariate normals, extract marginal over first variable m <- mixture( list(mvn(c(0, 0), diag(2)), mvn(c(3, 3), diag(2))), c(0.5, 0.5) ) m1 <- marginal(m, 1) mean(m1)# Mixture of bivariate normals, extract marginal over first variable m <- mixture( list(mvn(c(0, 0), diag(2)), mvn(c(3, 3), diag(2))), c(0.5, 0.5) ) m1 <- marginal(m, 1) mean(m1)
mvn object
x over components indices.Generic method for obtaining the marginal distribution of an mvn object
x over components indices.
## S3 method for class 'mvn' marginal(x, indices)## S3 method for class 'mvn' marginal(x, indices)
x |
The |
indices |
The indices of the marginal distribution to obtain. |
A normal (for a single index) or mvn marginal distribution.
X <- mvn(c(1, 2, 3)) # Univariate marginal marginal(X, 1) # Bivariate marginal marginal(X, c(1, 3))X <- mvn(c(1, 2, 3)) # Univariate marginal marginal(X, 1) # Bivariate marginal marginal(X, c(1, 3))
Handles exp(), log(), sqrt(), abs(), cos(), sin(), etc.
## S3 method for class 'dist' Math(x, ...)## S3 method for class 'dist' Math(x, ...)
x |
a dist object |
... |
additional arguments |
A simplified distribution or edist
# exp(Normal) simplifies to LogNormal z <- exp(normal(0, 1)) z # sqrt of a distribution (no closed-form rule, remains edist) w <- sqrt(exponential(1)) is_edist(w) # TRUE# exp(Normal) simplifies to LogNormal z <- exp(normal(0, 1)) z # sqrt of a distribution (no closed-form rule, remains edist) w <- sqrt(exponential(1)) is_edist(w) # TRUE
Computes where = shape1
and = shape2.
## S3 method for class 'beta_dist' mean(x, ...)## S3 method for class 'beta_dist' mean(x, ...)
x |
A |
... |
Additional arguments (not used). |
The mean of the distribution.
mean(beta_dist(2, 5))mean(beta_dist(2, 5))
chi_squared object.Retrieve the mean of a chi_squared object.
## S3 method for class 'chi_squared' mean(x, ...)## S3 method for class 'chi_squared' mean(x, ...)
x |
The |
... |
Additional arguments (not used) |
The mean, equal to df
mean(chi_squared(10))mean(chi_squared(10))
edist object.Method for obtaining the mean of an edist object.
## S3 method for class 'edist' mean(x, n = 10000, ...)## S3 method for class 'edist' mean(x, n = 10000, ...)
x |
The |
n |
The number of samples to take (default: 10000) |
... |
Additional arguments to pass (not used) |
The mean of the edist object
set.seed(1) z <- normal(0, 1) * exponential(2) mean(z)set.seed(1) z <- normal(0, 1) * exponential(2) mean(z)
empirical_dist object x.Method for obtaining the mean of empirical_dist object x.
## S3 method for class 'empirical_dist' mean(x, ...)## S3 method for class 'empirical_dist' mean(x, ...)
x |
The distribution object. |
... |
Additional arguments to pass (not used). |
Numeric vector of column means.
ed <- empirical_dist(c(1, 2, 3, 4, 5)) mean(ed) # 3ed <- empirical_dist(c(1, 2, 3, 4, 5)) mean(ed) # 3
exponential object.Method to obtain the mean of an exponential object.
## S3 method for class 'exponential' mean(x, ...)## S3 method for class 'exponential' mean(x, ...)
x |
The |
... |
Additional arguments (not used) |
The mean of the exponential distribution (1 / rate).
x <- exponential(rate = 0.5) mean(x)x <- exponential(rate = 0.5) mean(x)
gamma_dist object.Retrieve the mean of a gamma_dist object.
## S3 method for class 'gamma_dist' mean(x, ...)## S3 method for class 'gamma_dist' mean(x, ...)
x |
The |
... |
Additional arguments (not used) |
The mean, shape / rate
mean(gamma_dist(shape = 3, rate = 2))mean(gamma_dist(shape = 3, rate = 2))
Computes .
## S3 method for class 'lognormal' mean(x, ...)## S3 method for class 'lognormal' mean(x, ...)
x |
A |
... |
Additional arguments (not used). |
The mean of the distribution.
mean(lognormal(0, 1))mean(lognormal(0, 1))
The mean of a mixture is the weighted sum of the component means:
.
## S3 method for class 'mixture' mean(x, ...)## S3 method for class 'mixture' mean(x, ...)
x |
A |
... |
Additional arguments (not used). |
The mean of the mixture distribution.
m <- mixture(list(normal(0, 1), normal(10, 1)), c(0.5, 0.5)) mean(m)m <- mixture(list(normal(0, 1), normal(10, 1)), c(0.5, 0.5)) mean(m)
mvn object.Retrieve the mean of a mvn object.
## S3 method for class 'mvn' mean(x, ...)## S3 method for class 'mvn' mean(x, ...)
x |
The |
... |
Additional arguments to pass (not used) |
The mean of the mvn object
X <- mvn(c(1, 2, 3)) mean(X)X <- mvn(c(1, 2, 3)) mean(X)
normal object.Retrieve the mean of a normal object.
## S3 method for class 'normal' mean(x, ...)## S3 method for class 'normal' mean(x, ...)
x |
The |
... |
Additional arguments to pass (not used) |
The mean of the normal object
x <- normal(5, 2) mean(x)x <- normal(5, 2) mean(x)
Mean of a Poisson distribution.
## S3 method for class 'poisson_dist' mean(x, ...)## S3 method for class 'poisson_dist' mean(x, ...)
x |
A |
... |
Additional arguments (not used). |
The mean, equal to lambda.
mean(poisson_dist(5))mean(poisson_dist(5))
Computes .
## S3 method for class 'uniform_dist' mean(x, ...)## S3 method for class 'uniform_dist' mean(x, ...)
x |
A |
... |
Additional arguments (not used). |
The mean of the distribution.
mean(uniform_dist(0, 10))mean(uniform_dist(0, 10))
univariate_dist object x.Method for obtaining the mean of univariate_dist object x.
## S3 method for class 'univariate_dist' mean(x, ...)## S3 method for class 'univariate_dist' mean(x, ...)
x |
The distribution object. |
... |
Additional arguments to pass into |
Numeric scalar; the mean of the distribution.
mean(normal(5, 2)) # 5 mean(exponential(2)) # 0.5mean(normal(5, 2)) # 5 mean(exponential(2)) # 0.5
Computes .
## S3 method for class 'weibull_dist' mean(x, ...)## S3 method for class 'weibull_dist' mean(x, ...)
x |
A |
... |
Additional arguments (not used). |
The mean of the distribution.
mean(weibull_dist(shape = 2, scale = 3))mean(weibull_dist(shape = 2, scale = 3))
Creates an S3 object representing a finite mixture distribution.
The density is where
are the component densities and are the mixing
weights.
mixture(components, weights)mixture(components, weights)
components |
A non-empty list of |
weights |
A numeric vector of non-negative mixing weights that
sum to 1 (within tolerance |
The class hierarchy is determined by the components: if all components are univariate (or multivariate, continuous, discrete), the mixture inherits those classes as well.
A mixture object with appropriate class hierarchy.
m <- mixture( components = list(normal(0, 1), normal(5, 2)), weights = c(0.3, 0.7) ) mean(m) vcov(m) format(m)m <- mixture( components = list(normal(0, 1), normal(5, 2)), weights = c(0.3, 0.7) ) mean(m) vcov(m) format(m)
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.
mvn(mu, sigma = diag(length(mu)))mvn(mu, sigma = diag(length(mu)))
mu |
A numeric vector specifying the means of the distribution.
If |
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 |
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.
# Bivariate normal with identity covariance X <- mvn(mu = c(0, 0)) mean(X) vcov(X) # 1D case returns a normal object is_normal(mvn(mu = 1, sigma = matrix(4)))# Bivariate normal with identity covariance X <- mvn(mu = c(0, 0)) mean(X) vcov(X) # 1D case returns a normal object is_normal(mvn(mu = 1, sigma = matrix(4)))
empirical_dist object.Method for obtaining the number of observations used to construct a
empirical_dist object.
## S3 method for class 'empirical_dist' nobs(object, ...)## S3 method for class 'empirical_dist' nobs(object, ...)
object |
The empirical distribution object. |
... |
Additional arguments to pass (not used). |
Integer; number of observations.
ed <- empirical_dist(c(10, 20, 30, 40)) nobs(ed) # 4ed <- empirical_dist(c(10, 20, 30, 40)) nobs(ed) # 4
Construct univariate normal distribution object.
normal(mu = 0, var = 1)normal(mu = 0, var = 1)
mu |
mean |
var |
variance |
A normal distribution object.
x <- normal(mu = 0, var = 1) mean(x) vcov(x) format(x)x <- normal(mu = 0, var = 1) mean(x) vcov(x) format(x)
Constructs a normal (or multivariate normal) distribution that matches the mean and variance-covariance of the input distribution. This is useful as a quick Gaussian approximation for any distribution whose first two moments are available.
normal_approx(x)normal_approx(x)
x |
A |
A normal distribution (for univariate inputs) or an
mvn distribution (for multivariate inputs) with the same
mean and variance-covariance as x.
# Approximate a Gamma(5, 2) with a normal g <- gamma_dist(shape = 5, rate = 2) n <- normal_approx(g) mean(n) vcov(n)# Approximate a Gamma(5, 2) with a normal g <- gamma_dist(shape = 5, rate = 2) n <- normal_approx(g) mean(n) vcov(n)
x.Generic method for obtaining the number of parameters of
distribution-like object x.
nparams(x) ## S3 method for class 'dist' nparams(x)nparams(x) ## S3 method for class 'dist' nparams(x)
x |
the object to obtain the number of parameters for |
Integer; the number of parameters.
d <- empirical_dist(matrix(rnorm(30), ncol = 3)) nparams(d) # 0 (non-parametric) nparams(normal(0, 1)) # 2d <- empirical_dist(matrix(rnorm(30), ncol = 3)) nparams(d) # 0 (non-parametric) nparams(normal(0, 1)) # 2
empirical_dist object. Since the
empirical distribution is parameter-free, this function returns 0.Method for obtaining the name of a empirical_dist object. Since the
empirical distribution is parameter-free, this function returns 0.
## S3 method for class 'empirical_dist' nparams(x)## S3 method for class 'empirical_dist' nparams(x)
x |
The empirical distribution object. |
0 (empirical distributions are non-parametric).
ed <- empirical_dist(c(1, 2, 3)) nparams(ed) # 0ed <- empirical_dist(c(1, 2, 3)) nparams(ed) # 0
mixture distribution.The total number of parameters is the sum of component parameters plus the number of mixing weights.
## S3 method for class 'mixture' nparams(x)## S3 method for class 'mixture' nparams(x)
x |
A |
An integer count of parameters.
m <- mixture(list(normal(0, 1), normal(5, 2)), c(0.3, 0.7)) nparams(m)m <- mixture(list(normal(0, 1), normal(5, 2)), c(0.3, 0.7)) nparams(m)
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.
obs(x)obs(x)
x |
the object to retrieve the observations from |
The data (matrix or vector) used to construct x.
d <- empirical_dist(1:10) obs(d) # returns the vector 1:10d <- empirical_dist(1:10) obs(d) # returns the vector 1:10
empirical_dist object.Method for obtaining the observations used to construct a
empirical_dist object.
## S3 method for class 'empirical_dist' obs(x)## S3 method for class 'empirical_dist' obs(x)
x |
The empirical distribution object. |
A matrix of observations (rows = observations, columns = dimensions).
ed <- empirical_dist(c(5, 10, 15)) obs(ed)ed <- empirical_dist(c(5, 10, 15)) obs(ed)
Generic method for obtaining the parameters of an object.
params(x)params(x)
x |
The object to obtain the parameters of. |
A named vector (or list) of distribution parameters.
x <- normal(5, 2) params(x) # mu = 5, var = 2 y <- exponential(3) params(y) # rate = 3x <- normal(5, 2) params(x) # mu = 5, var = 2 y <- exponential(3) params(y) # rate = 3
beta_dist object.Retrieve the parameters of a beta_dist object.
## S3 method for class 'beta_dist' params(x)## S3 method for class 'beta_dist' params(x)
x |
A |
A named numeric vector with elements shape1 and shape2.
params(beta_dist(2, 5))params(beta_dist(2, 5))
chi_squared object.Method for obtaining the parameters of a chi_squared object.
## S3 method for class 'chi_squared' params(x)## S3 method for class 'chi_squared' params(x)
x |
The |
A named numeric vector of parameters
params(chi_squared(5))params(chi_squared(5))
edist object.Method for obtaining the parameters of an edist object.
## S3 method for class 'edist' params(x)## S3 method for class 'edist' params(x)
x |
The object to obtain the parameters of |
A named vector of parameters
z <- normal(0, 1) * exponential(2) params(z)z <- normal(0, 1) * exponential(2) params(z)
empirical_dist objects have no parameters, so this function returns NULL.empirical_dist objects have no parameters, so this function returns NULL.
## S3 method for class 'empirical_dist' params(x)## S3 method for class 'empirical_dist' params(x)
x |
The empirical distribution object. |
NULL (empirical distributions have no parameters).
ed <- empirical_dist(c(1, 2, 3)) params(ed) # NULLed <- empirical_dist(c(1, 2, 3)) params(ed) # NULL
exponential object.Method for obtaining the parameters of an exponential object.
## S3 method for class 'exponential' params(x)## S3 method for class 'exponential' params(x)
x |
The object to obtain the parameters of |
A named vector of parameters
x <- exponential(rate = 0.5) params(x)x <- exponential(rate = 0.5) params(x)
gamma_dist object.Method for obtaining the parameters of a gamma_dist object.
## S3 method for class 'gamma_dist' params(x)## S3 method for class 'gamma_dist' params(x)
x |
The |
A named numeric vector of parameters
params(gamma_dist(2, 1))params(gamma_dist(2, 1))
lognormal object.Retrieve the parameters of a lognormal object.
## S3 method for class 'lognormal' params(x)## S3 method for class 'lognormal' params(x)
x |
A |
A named numeric vector with elements meanlog and sdlog.
params(lognormal(0, 1))params(lognormal(0, 1))
mixture object.Returns a named numeric vector containing all component parameters (flattened) followed by the mixing weights.
## S3 method for class 'mixture' params(x)## S3 method for class 'mixture' params(x)
x |
A |
A named numeric vector.
m <- mixture(list(normal(0, 1), normal(5, 2)), c(0.3, 0.7)) params(m)m <- mixture(list(normal(0, 1), normal(5, 2)), c(0.3, 0.7)) params(m)
mvn object.Method for obtaining the parameters of a mvn object.
## S3 method for class 'mvn' params(x)## S3 method for class 'mvn' params(x)
x |
The object to obtain the parameters of |
A named vector of parameters
X <- mvn(c(0, 0), diag(2)) params(X)X <- mvn(c(0, 0), diag(2)) params(X)
normal object.Method for obtaining the parameters of a normal object.
## S3 method for class 'normal' params(x)## S3 method for class 'normal' params(x)
x |
The object to obtain the parameters of |
A named vector of parameters
x <- normal(3, 2) params(x)x <- normal(3, 2) params(x)
poisson_dist object.Retrieve the parameters of a poisson_dist object.
## S3 method for class 'poisson_dist' params(x)## S3 method for class 'poisson_dist' params(x)
x |
A |
A named numeric vector with element lambda.
params(poisson_dist(5))params(poisson_dist(5))
uniform_dist object.Retrieve the parameters of a uniform_dist object.
## S3 method for class 'uniform_dist' params(x)## S3 method for class 'uniform_dist' params(x)
x |
A |
A named numeric vector with elements min and max.
params(uniform_dist(0, 10))params(uniform_dist(0, 10))
weibull_dist object.Retrieve the parameters of a weibull_dist object.
## S3 method for class 'weibull_dist' params(x)## S3 method for class 'weibull_dist' params(x)
x |
A |
A named numeric vector with elements shape and scale.
params(weibull_dist(2, 3))params(weibull_dist(2, 3))
Creates an S3 object representing a Poisson distribution with rate
parameter . The PMF is
for .
poisson_dist(lambda)poisson_dist(lambda)
lambda |
Rate parameter (mean), must be a positive scalar. |
A poisson_dist object with classes
c("poisson_dist", "univariate_dist", "discrete_dist", "dist").
x <- poisson_dist(lambda = 5) mean(x) vcov(x) format(x)x <- poisson_dist(lambda = 5) mean(x) vcov(x) format(x)
beta_dist object.Print a beta_dist object.
## S3 method for class 'beta_dist' print(x, ...)## S3 method for class 'beta_dist' print(x, ...)
x |
A |
... |
Additional arguments (not used). |
x, invisibly.
print(beta_dist(2, 5))print(beta_dist(2, 5))
chi_squared objects.Print method for chi_squared objects.
## S3 method for class 'chi_squared' print(x, ...)## S3 method for class 'chi_squared' print(x, ...)
x |
The |
... |
Additional arguments (not used) |
x, invisibly.
print(chi_squared(5))print(chi_squared(5))
edist objects.Print method for edist objects.
## S3 method for class 'edist' print(x, ...)## S3 method for class 'edist' print(x, ...)
x |
The object to print |
... |
Additional arguments to pass (not used) |
z <- normal(0, 1) * exponential(2) print(z)z <- normal(0, 1) * exponential(2) print(z)
empirical_dist objects.Print method for empirical_dist objects.
## S3 method for class 'empirical_dist' print(x, ...)## S3 method for class 'empirical_dist' print(x, ...)
x |
The object to print |
... |
Additional arguments to pass |
x, invisibly.
ed <- empirical_dist(c(1, 2, 3, 4, 5)) print(ed)ed <- empirical_dist(c(1, 2, 3, 4, 5)) print(ed)
exponential objects.Print method for exponential objects.
## S3 method for class 'exponential' print(x, ...)## S3 method for class 'exponential' print(x, ...)
x |
The |
... |
Additional arguments (not used) |
x, invisibly.
print(exponential(rate = 2))print(exponential(rate = 2))
gamma_dist objects.Print method for gamma_dist objects.
## S3 method for class 'gamma_dist' print(x, ...)## S3 method for class 'gamma_dist' print(x, ...)
x |
The |
... |
Additional arguments (not used) |
x, invisibly.
print(gamma_dist(2, 1))print(gamma_dist(2, 1))
Print the interval.
## S3 method for class 'interval' print(x, ...)## S3 method for class 'interval' print(x, ...)
x |
An interval object. |
... |
Additional arguments. |
x, invisibly.
iv <- interval$new(lower = 0, upper = 1, lower_closed = TRUE) print(iv) # [0, 1)iv <- interval$new(lower = 0, upper = 1, lower_closed = TRUE) print(iv) # [0, 1)
lognormal object.Print a lognormal object.
## S3 method for class 'lognormal' print(x, ...)## S3 method for class 'lognormal' print(x, ...)
x |
A |
... |
Additional arguments (not used). |
x, invisibly.
print(lognormal(0, 1))print(lognormal(0, 1))
mixture object.Print a mixture object.
## S3 method for class 'mixture' print(x, ...)## S3 method for class 'mixture' print(x, ...)
x |
A |
... |
Additional arguments (not used). |
x, invisibly.
m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) print(m)m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) print(m)
mvn object.Method for printing an mvn object.
## S3 method for class 'mvn' print(x, ...)## S3 method for class 'mvn' print(x, ...)
x |
The object to print |
... |
Additional arguments to pass to |
x, invisibly.
print(mvn(c(0, 0)))print(mvn(c(0, 0)))
normal objects.Print method for normal objects.
## S3 method for class 'normal' print(x, ...)## S3 method for class 'normal' print(x, ...)
x |
The object to print |
... |
Additional arguments to pass (not used) |
x, invisibly.
x <- normal(2, 3) print(x)x <- normal(2, 3) print(x)
poisson_dist object.Print a poisson_dist object.
## S3 method for class 'poisson_dist' print(x, ...)## S3 method for class 'poisson_dist' print(x, ...)
x |
A |
... |
Additional arguments (not used). |
x, invisibly.
print(poisson_dist(5))print(poisson_dist(5))
realized_dist object.Print a realized_dist object.
## S3 method for class 'realized_dist' print(x, ...)## S3 method for class 'realized_dist' print(x, ...)
x |
A |
... |
Additional arguments (not used). |
x, invisibly.
rd <- realize(normal(0, 1), n = 100) print(rd)rd <- realize(normal(0, 1), n = 100) print(rd)
summary_dist objects.Print method for summary_dist objects.
## S3 method for class 'summary_dist' print(x, ...)## S3 method for class 'summary_dist' print(x, ...)
x |
The object to print |
... |
Additional arguments |
x, invisibly.
s <- summary(normal(5, 2)) print(s)s <- summary(normal(5, 2)) print(s)
uniform_dist object.Print a uniform_dist object.
## S3 method for class 'uniform_dist' print(x, ...)## S3 method for class 'uniform_dist' print(x, ...)
x |
A |
... |
Additional arguments (not used). |
x, invisibly.
print(uniform_dist(0, 10))print(uniform_dist(0, 10))
weibull_dist object.Print a weibull_dist object.
## S3 method for class 'weibull_dist' print(x, ...)## S3 method for class 'weibull_dist' print(x, ...)
x |
A |
... |
Additional arguments (not used). |
x, invisibly.
print(weibull_dist(2, 3))print(weibull_dist(2, 3))
realize draws n samples from a distribution and wraps
them in an empirical_dist.
This is the universal fallback that lets any dist object be
converted to a discrete approximation on which methods like
cdf, density, and conditional
are always available.
realize(x, n = 10000, ...) ## S3 method for class 'dist' realize(x, n = 10000, ...) ## S3 method for class 'empirical_dist' realize(x, ...) ## S3 method for class 'realized_dist' realize(x, n = 10000, ...)realize(x, n = 10000, ...) ## S3 method for class 'dist' realize(x, n = 10000, ...) ## S3 method for class 'empirical_dist' realize(x, ...) ## S3 method for class 'realized_dist' realize(x, n = 10000, ...)
x |
A distribution object (inheriting from |
n |
Number of samples (default: 10000). |
... |
Additional arguments passed to methods. |
For non-empirical distributions, the result is a
realized_dist that preserves the source distribution
as provenance metadata. This enables re-sampling via
realize(x$source, n = ...) and informative printing.
The empirical_dist method is a no-op: the distribution is
already materialized.
The realized_dist method re-samples from the original source
distribution, allowing cheap regeneration with a different sample size.
An empirical_dist (or realized_dist)
object.
set.seed(1) x <- normal(0, 1) rd <- realize(x, n = 1000) mean(rd)set.seed(1) x <- normal(0, 1) rd <- realize(x, n = 1000) mean(rd)
f to distribution object x.Generic method for applying a map f to distribution object x.
rmap(x, g, ...)rmap(x, g, ...)
x |
The distribution object. |
g |
The function to apply. |
... |
Additional arguments to pass into |
A distribution representing the push-forward of x through g.
d <- empirical_dist(1:20) d_sq <- rmap(d, function(x) x^2) mean(d_sq) # E[X^2] for uniform 1..20d <- empirical_dist(1:20) d_sq <- rmap(d, function(x) x^2) mean(d_sq) # E[X^2] for uniform 1..20
dist object.Falls back to MC: materializes x via ensure_realized() and
then applies rmap with g to the resulting empirical distribution.
## S3 method for class 'dist' rmap(x, g, n = 10000L, ...)## S3 method for class 'dist' rmap(x, g, n = 10000L, ...)
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 |
An empirical_dist of the transformed samples.
set.seed(1) x <- exponential(1) # Distribution of log(X) where X ~ Exp(1) log_x <- rmap(x, log) mean(log_x)set.seed(1) x <- exponential(1) # Distribution of log(X) where X ~ Exp(1) log_x <- rmap(x, log) mean(log_x)
Falls back to realize and delegates to
rmap.empirical_dist.
## S3 method for class 'edist' rmap(x, g, ...)## S3 method for class 'edist' rmap(x, g, ...)
x |
An |
g |
Function to apply to each observation. |
... |
Additional arguments forwarded to |
A transformed empirical_dist.
set.seed(1) z <- normal(0, 1) * exponential(1) abs_z <- rmap(z, abs) mean(abs_z)set.seed(1) z <- normal(0, 1) * exponential(1) abs_z <- rmap(z, abs) mean(abs_z)
empirical_dist object x.Method for obtaining the empirical distribution of a function of the
observations of empirical_dist object x.
## S3 method for class 'empirical_dist' rmap(x, g, ...)## S3 method for class 'empirical_dist' rmap(x, g, ...)
x |
The empirical distribution object. |
g |
The function to apply to each observation. |
... |
Additional arguments to pass into function |
An empirical_dist of the transformed observations.
ed <- empirical_dist(c(1, 2, 3, 4)) ed2 <- rmap(ed, function(x) x^2) mean(ed2) # mean of 1, 4, 9, 16ed <- empirical_dist(c(1, 2, 3, 4)) ed2 <- rmap(ed, function(x) x^2) mean(ed2) # mean of 1, 4, 9, 16
g(x) where x is an mvn object.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)
## S3 method for class 'mvn' rmap(x, g, n = 10000L, ...)## S3 method for class 'mvn' rmap(x, g, n = 10000L, ...)
x |
The |
g |
The function to apply to |
n |
number of samples to take to estimate distribution of |
... |
additional arguments to pass into the |
An mvn distribution fitted to the transformed samples.
X <- mvn(c(1, 2), diag(2)) set.seed(42) Y <- rmap(X, function(x) x^2) mean(Y)X <- mvn(c(1, 2), diag(2)) set.seed(42) Y <- rmap(X, function(x) x^2) mean(Y)
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).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).
sample_mvn_region(n, mu, sigma, p = 0.95, ...)sample_mvn_region(n, mu, sigma, p = 0.95, ...)
n |
the sample size |
mu |
mean vector |
sigma |
variance-covariance matrix |
p |
the probability region |
... |
additional arguments to pass into |
An n by length(mu) matrix of samples within the
probability region.
set.seed(42) pts <- sample_mvn_region(10, mu = c(0, 0), sigma = diag(2), p = 0.95) dim(pts)set.seed(42) pts <- sample_mvn_region(10, mu = c(0, 0), sigma = diag(2), p = 0.95) dim(pts)
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.
sampler(x, ...)sampler(x, ...)
x |
the |
... |
additional arguments to pass |
A function that takes n and returns n samples.
x <- normal(0, 1) samp <- sampler(x) set.seed(42) samp(5) # draw 5 samples from standard normalx <- normal(0, 1) samp <- sampler(x) set.seed(42) samp(5) # draw 5 samples from standard normal
Returns a function that draws n independent samples from the
beta distribution.
## S3 method for class 'beta_dist' sampler(x, ...)## S3 method for class 'beta_dist' sampler(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(n = 1, ...) returning a numeric vector
of length n.
x <- beta_dist(2, 5) s <- sampler(x) set.seed(42) s(5)x <- beta_dist(2, 5) s <- sampler(x) set.seed(42) s(5)
chi_squared object.Method for sampling from a chi_squared object.
## S3 method for class 'chi_squared' sampler(x, ...)## S3 method for class 'chi_squared' sampler(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that generates n samples from the chi-squared
distribution
x <- chi_squared(5) s <- sampler(x) set.seed(42) s(5)x <- chi_squared(5) s <- sampler(x) set.seed(42) s(5)
Sampler for non-dist objects (degenerate distributions).
## Default S3 method: sampler(x, ...)## Default S3 method: sampler(x, ...)
x |
The object to sample from |
... |
Additional arguments to pass |
A function that takes n and returns n copies of x
s <- sampler(5) s(3) # returns c(5, 5, 5)s <- sampler(5) s(3) # returns c(5, 5, 5)
edist object.Method for obtaining the sampler of an edist object.
## S3 method for class 'edist' sampler(x, ...)## S3 method for class 'edist' sampler(x, ...)
x |
The |
... |
Additional arguments to pass into each of the |
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.
set.seed(1) z <- normal(0, 1) * exponential(2) s <- sampler(z) samples <- s(100) head(samples)set.seed(1) z <- normal(0, 1) * exponential(2) s <- sampler(z) samples <- s(100) head(samples)
empirical_dist object.Method for obtaining the sampler for a empirical_dist object.
## S3 method for class 'empirical_dist' sampler(x, ...)## S3 method for class 'empirical_dist' sampler(x, ...)
x |
The object to obtain the sampler of. |
... |
Additional arguments to pass (not used). |
A function that takes n and returns n resampled
observations.
ed <- empirical_dist(c(10, 20, 30)) s <- sampler(ed) set.seed(42) s(5)ed <- empirical_dist(c(10, 20, 30)) s <- sampler(ed) set.seed(42) s(5)
exponential object.Method to sample from an exponential object.
## S3 method for class 'exponential' sampler(x, ...)## S3 method for class 'exponential' sampler(x, ...)
x |
The |
... |
Additional arguments to pass (not used) |
A function function(n = 1, ...) that draws n
samples from the exponential distribution.
x <- exponential(rate = 2) s <- sampler(x) set.seed(42) s(5)x <- exponential(rate = 2) s <- sampler(x) set.seed(42) s(5)
gamma_dist object.Method for sampling from a gamma_dist object.
## S3 method for class 'gamma_dist' sampler(x, ...)## S3 method for class 'gamma_dist' sampler(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that generates n samples from the gamma distribution
x <- gamma_dist(shape = 2, rate = 1) s <- sampler(x) set.seed(42) s(5)x <- gamma_dist(shape = 2, rate = 1) s <- sampler(x) set.seed(42) s(5)
Returns a function that draws n independent samples from the
log-normal distribution.
## S3 method for class 'lognormal' sampler(x, ...)## S3 method for class 'lognormal' sampler(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(n = 1, ...) returning a numeric vector
of length n.
x <- lognormal(0, 1) s <- sampler(x) set.seed(42) s(5)x <- lognormal(0, 1) s <- sampler(x) set.seed(42) s(5)
Returns a function that draws samples from the mixture by first selecting a component according to the mixing weights, then sampling from the selected component.
## S3 method for class 'mixture' sampler(x, ...)## S3 method for class 'mixture' sampler(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(n = 1, ...) returning a numeric
vector of length n.
m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) s <- sampler(m) set.seed(42) s(6)m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5)) s <- sampler(m) set.seed(42) s(6)
mvn (multivariate normal) object.Function generator for sampling from a mvn (multivariate normal) object.
## S3 method for class 'mvn' sampler(x, ...)## S3 method for class 'mvn' sampler(x, ...)
x |
The |
... |
Additional arguments passed to |
X <- mvn(c(0, 0), diag(2)) s <- sampler(X) set.seed(42) s(3)X <- mvn(c(0, 0), diag(2)) s <- sampler(X) set.seed(42) s(3)
normal object.Method for sampling from a normal object.
## S3 method for class 'normal' sampler(x, ...)## S3 method for class 'normal' sampler(x, ...)
x |
The |
... |
Additional arguments to pass (not used) |
A function function(n = 1, ...) that draws n
samples from the normal distribution.
x <- normal(0, 1) s <- sampler(x) set.seed(42) s(5)x <- normal(0, 1) s <- sampler(x) set.seed(42) s(5)
Returns a function that draws n independent samples from the
Poisson distribution.
## S3 method for class 'poisson_dist' sampler(x, ...)## S3 method for class 'poisson_dist' sampler(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(n = 1, ...) returning an integer vector
of length n.
x <- poisson_dist(5) s <- sampler(x) set.seed(42) s(5)x <- poisson_dist(5) s <- sampler(x) set.seed(42) s(5)
Returns a function that draws n independent samples from the
uniform distribution.
## S3 method for class 'uniform_dist' sampler(x, ...)## S3 method for class 'uniform_dist' sampler(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(n = 1, ...) returning a numeric vector
of length n.
x <- uniform_dist(0, 10) s <- sampler(x) set.seed(42) s(5)x <- uniform_dist(0, 10) s <- sampler(x) set.seed(42) s(5)
Returns a function that draws n independent samples from the
Weibull distribution.
## S3 method for class 'weibull_dist' sampler(x, ...)## S3 method for class 'weibull_dist' sampler(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(n = 1, ...) returning a numeric vector
of length n.
x <- weibull_dist(shape = 2, scale = 3) s <- sampler(x) set.seed(42) s(5)x <- weibull_dist(shape = 2, scale = 3) s <- sampler(x) set.seed(42) s(5)
Generic method for simplifying distributions.
simplify(x, ...)simplify(x, ...)
x |
The distribution to simplify |
... |
Additional arguments to pass |
The simplified distribution
# Simplify dispatches to the appropriate method simplify(normal(0, 1)) # unchanged (already simplified)# Simplify dispatches to the appropriate method simplify(normal(0, 1)) # unchanged (already simplified)
dist object. Just returns the object.Default Method for simplifying a dist object. Just returns the object.
## S3 method for class 'dist' simplify(x, ...)## S3 method for class 'dist' simplify(x, ...)
x |
The |
... |
Additional arguments to pass (not used) |
The dist object
x <- normal(0, 1) identical(simplify(x), x) # TRUE, returns unchangedx <- normal(0, 1) identical(simplify(x), x) # TRUE, returns unchanged
edist object.Attempts to reduce expression distributions to closed-form distributions when mathematical identities apply. Supported rules include:
## S3 method for class 'edist' simplify(x, ...)## S3 method for class 'edist' simplify(x, ...)
x |
The |
... |
Additional arguments to pass (not used) |
Single-variable:
c * Normal(mu, v) -> Normal(cmu, c^2v)
c * Gamma(a, r) -> Gamma(a, r/c) for c > 0
c * Exponential(r) -> Gamma(1, r/c) for c > 0
c * Uniform(a, b) -> Uniform(min(ca,cb), max(ca,cb)) for c != 0
c * Weibull(k, lam) -> Weibull(k, c*lam) for c > 0
c * ChiSq(df) -> Gamma(df/2, 1/(2c)) for c > 0
c * LogNormal(ml, sl) -> LogNormal(ml + log(c), sl) for c > 0
Normal(mu, v) + c -> Normal(mu + c, v)
Normal(mu, v) - c -> Normal(mu - c, v)
Uniform(a, b) + c -> Uniform(a + c, b + c)
Uniform(a, b) - c -> Uniform(a - c, b - c)
Normal(0, 1) ^ 2 -> ChiSquared(1)
exp(Normal(mu, v)) -> LogNormal(mu, sqrt(v))
log(LogNormal(ml, sl)) -> Normal(ml, sl^2)
Two-variable:
Normal + Normal -> Normal
Normal - Normal -> Normal
Gamma + Gamma (same rate) -> Gamma
Exponential + Exponential (same rate) -> Gamma(2, rate)
Gamma + Exponential (same rate) -> Gamma(a+1, rate)
ChiSquared + ChiSquared -> ChiSquared
Poisson + Poisson -> Poisson
LogNormal * LogNormal -> LogNormal
The simplified distribution, or unchanged edist if no rule applies
# Normal + Normal simplifies to a Normal z <- normal(0, 1) + normal(2, 3) is_normal(z) # TRUE z # Normal(mu = 2, var = 4) # exp(Normal) simplifies to LogNormal w <- exp(normal(0, 1)) is_lognormal(w) # TRUE# Normal + Normal simplifies to a Normal z <- normal(0, 1) + normal(2, 3) is_normal(z) # TRUE z # Normal(mu = 2, var = 4) # exp(Normal) simplifies to LogNormal w <- exp(normal(0, 1)) is_lognormal(w) # TRUE
summary_dist object.Method for constructing a summary_dist object.
summary_dist(name, mean, vcov, nobs = NULL)summary_dist(name, mean, vcov, nobs = NULL)
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. |
A summary_dist object
s <- summary_dist(name = "my_dist", mean = 0, vcov = 1) print(s)s <- summary_dist(name = "my_dist", mean = 0, vcov = 1) print(s)
dist object.Method for obtaining a summary of a dist object.
## S3 method for class 'dist' summary(object, ..., name = NULL, nobs = NULL)## S3 method for class 'dist' summary(object, ..., name = NULL, nobs = NULL)
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. |
A summary_dist object
summary(normal(0, 1))summary(normal(0, 1))
Handles sum(), prod(), min(), max() of distributions.
## S3 method for class 'dist' Summary(..., na.rm = FALSE)## S3 method for class 'dist' Summary(..., na.rm = FALSE)
... |
dist objects |
na.rm |
ignored |
A simplified distribution or edist
# sum() reduces via + operator z <- sum(normal(0, 1), normal(2, 3)) z # Normal(mu = 2, var = 4) # min() of exponentials simplifies w <- min(exponential(1), exponential(2)) w # Exponential(rate = 3)# sum() reduces via + operator z <- sum(normal(0, 1), normal(2, 3)) z # Normal(mu = 2, var = 4) # min() of exponentials simplifies w <- min(exponential(1), exponential(2)) w # Exponential(rate = 3)
x.The returned value should have the following operations:
min: a vector, the minimum value of the support for each component.
max: a vector, the maximum value of the support for each component.
call: a predicate function, which returns TRUE if the value is in
the support, and FALSE otherwise.
sample: a function, which returns a sample from the support. Note that
the returned value is not guaranteed to be in the support of x. You may need
to call call to check.
sup(x)sup(x)
x |
The object to obtain the support of. |
A support object for x.
x <- normal(0, 1) S <- sup(x) infimum(S) # -Inf supremum(S) # Inf y <- exponential(1) S2 <- sup(y) infimum(S2) # 0x <- normal(0, 1) S <- sup(x) infimum(S) # -Inf supremum(S) # Inf y <- exponential(1) S2 <- sup(y) infimum(S2) # 0
The beta distribution is supported on the open interval .
## S3 method for class 'beta_dist' sup(x)## S3 method for class 'beta_dist' sup(x)
x |
A |
An interval object representing .
sup(beta_dist(2, 5))sup(beta_dist(2, 5))
Support for chi-squared distribution, the positive real numbers (0, Inf).
## S3 method for class 'chi_squared' sup(x)## S3 method for class 'chi_squared' sup(x)
x |
The |
An interval object representing (0, Inf)
sup(chi_squared(5))sup(chi_squared(5))
Falls back to realize and delegates to
sup.empirical_dist.
## S3 method for class 'edist' sup(x)## S3 method for class 'edist' sup(x)
x |
An |
A finite_set support object.
set.seed(1) z <- normal(0, 1) * exponential(1) sup(z)set.seed(1) z <- normal(0, 1) * exponential(1) sup(z)
empirical_dist object x.Method for obtaining the support of empirical_dist object x.
## S3 method for class 'empirical_dist' sup(x)## S3 method for class 'empirical_dist' sup(x)
x |
The empirical distribution object. |
A finite_set object containing the support of x.
ed <- empirical_dist(c(1, 2, 2, 3)) s <- sup(ed) s$has(2) # TRUE s$has(4) # FALSEed <- empirical_dist(c(1, 2, 2, 3)) s <- sup(ed) s$has(2) # TRUE s$has(4) # FALSE
Support for exponential distribution, the positive real numbers, (0, Inf).
## S3 method for class 'exponential' sup(x)## S3 method for class 'exponential' sup(x)
x |
The object to obtain the support of |
An interval object representing the support of the exponential
x <- exponential(rate = 1) sup(x)x <- exponential(rate = 1) sup(x)
Support for gamma distribution, the positive real numbers (0, Inf).
## S3 method for class 'gamma_dist' sup(x)## S3 method for class 'gamma_dist' sup(x)
x |
The |
An interval object representing (0, Inf)
sup(gamma_dist(2, 1))sup(gamma_dist(2, 1))
The log-normal distribution is supported on .
## S3 method for class 'lognormal' sup(x)## S3 method for class 'lognormal' sup(x)
x |
A |
An interval object representing .
sup(lognormal(0, 1))sup(lognormal(0, 1))
Returns an interval spanning the widest range of all
component supports (from the smallest infimum to the largest supremum).
## S3 method for class 'mixture' sup(x)## S3 method for class 'mixture' sup(x)
x |
A |
An interval object.
m <- mixture(list(normal(0, 1), exponential(1)), c(0.5, 0.5)) sup(m)m <- mixture(list(normal(0, 1), exponential(1)), c(0.5, 0.5)) sup(m)
mvn object, where the support
is defined as values that have non-zero probability density.Method for obtaining the support of a mvn object, where the support
is defined as values that have non-zero probability density.
## S3 method for class 'mvn' sup(x, ...)## S3 method for class 'mvn' sup(x, ...)
x |
The |
... |
Additional arguments to pass (not used) |
A support-type object (see support.R), in this case an
interval object for each component.
X <- mvn(c(0, 0)) sup(X)X <- mvn(c(0, 0)) sup(X)
normal object, where the support
is defined as values that have non-zero probability density.Method for obtaining the support of a normal object, where the support
is defined as values that have non-zero probability density.
## S3 method for class 'normal' sup(x)## S3 method for class 'normal' sup(x)
x |
The |
A support-type object (see support.R), in this case an
interval object for each component.
x <- normal(0, 1) sup(x)x <- normal(0, 1) sup(x)
The Poisson distribution is supported on the non-negative integers
.
## S3 method for class 'poisson_dist' sup(x)## S3 method for class 'poisson_dist' sup(x)
x |
A |
A countable_set object with lower bound 0.
sup(poisson_dist(5))sup(poisson_dist(5))
The uniform distribution is supported on .
## S3 method for class 'uniform_dist' sup(x)## S3 method for class 'uniform_dist' sup(x)
x |
A |
An interval object representing .
sup(uniform_dist(0, 10))sup(uniform_dist(0, 10))
The Weibull distribution is supported on .
## S3 method for class 'weibull_dist' sup(x)## S3 method for class 'weibull_dist' sup(x)
x |
A |
An interval object representing .
sup(weibull_dist(2, 3))sup(weibull_dist(2, 3))
Get the supremum of the support.
supremum(object)supremum(object)
object |
A support object. |
The supremum (least upper bound) of the support.
I <- interval$new(0, 10) supremum(I) # 10 S <- finite_set$new(c(3, 7, 11)) supremum(S) # 11I <- interval$new(0, 10) supremum(I) # 10 S <- finite_set$new(c(3, 7, 11)) supremum(S) # 11
Get the supremum of a countable set.
## S3 method for class 'countable_set' supremum(object)## S3 method for class 'countable_set' supremum(object)
object |
A |
Inf (the set is unbounded above).
cs <- countable_set$new(0L) supremum(cs) # Infcs <- countable_set$new(0L) supremum(cs) # Inf
Return the supremum of the finite set.
## S3 method for class 'finite_set' supremum(object)## S3 method for class 'finite_set' supremum(object)
object |
A finite set. |
Numeric; the maximum value(s).
fs <- finite_set$new(c(1, 3, 5, 7)) supremum(fs) # 7fs <- finite_set$new(c(1, 3, 5, 7)) supremum(fs) # 7
Return the (vector of) supremum of the interval.
## S3 method for class 'interval' supremum(object)## S3 method for class 'interval' supremum(object)
object |
An interval object. |
Numeric vector of upper bounds.
iv <- interval$new(lower = 0, upper = 1) supremum(iv) # 1iv <- interval$new(lower = 0, upper = 1) supremum(iv) # 1
chi_squared object.Method for obtaining the survival function of a chi_squared object.
## S3 method for class 'chi_squared' surv(x, ...)## S3 method for class 'chi_squared' surv(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes S(t) = P(X > t)
x <- chi_squared(5) S <- surv(x) S(5)x <- chi_squared(5) S <- surv(x) S(5)
Computes from the CDF.
## S3 method for class 'continuous_dist' surv(x, ...) surv(x, ...)## S3 method for class 'continuous_dist' surv(x, ...) surv(x, ...)
x |
The object to obtain the survival function of. |
... |
Additional arguments to pass. |
A function function(t, ...) returning the survival
probability.
A function computing the survival function .
x <- beta_dist(2, 5) S <- surv(x) S(0.5) x <- exponential(1) S <- surv(x) S(0) # 1 (survival at time 0) S(1) # exp(-1), approximately 0.368x <- beta_dist(2, 5) S <- surv(x) S(0.5) x <- exponential(1) S <- surv(x) S(0) # 1 (survival at time 0) S(1) # exp(-1), approximately 0.368
exponential object.Method to obtain the survival function of an exponential object.
## S3 method for class 'exponential' surv(x, ...)## S3 method for class 'exponential' surv(x, ...)
x |
The object to obtain the survival function of |
... |
Additional arguments (not used) |
A function function(t, log.p = FALSE, ...) that computes
the survival function .
x <- exponential(rate = 1) S <- surv(x) S(1) S(2)x <- exponential(rate = 1) S <- surv(x) S(1) S(2)
gamma_dist object.Method for obtaining the survival function of a gamma_dist object.
## S3 method for class 'gamma_dist' surv(x, ...)## S3 method for class 'gamma_dist' surv(x, ...)
x |
The |
... |
Additional arguments (not used) |
A function that computes S(t) = P(X > t)
x <- gamma_dist(shape = 2, rate = 1) S <- surv(x) S(1)x <- gamma_dist(shape = 2, rate = 1) S <- surv(x) S(1)
Returns a function that computes for the log-normal
distribution.
## S3 method for class 'lognormal' surv(x, ...)## S3 method for class 'lognormal' surv(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log.p = FALSE, ...) returning the
survival probability (or log-survival probability) at t.
x <- lognormal(0, 1) S <- surv(x) S(1) S(2)x <- lognormal(0, 1) S <- surv(x) S(1) S(2)
Returns a function that computes for the Weibull
distribution.
## S3 method for class 'weibull_dist' surv(x, ...)## S3 method for class 'weibull_dist' surv(x, ...)
x |
A |
... |
Additional arguments (not used). |
A function function(t, log.p = FALSE, ...) returning the
survival probability (or log-survival probability) at t.
x <- weibull_dist(shape = 2, scale = 3) S <- surv(x) S(1) S(3)x <- weibull_dist(shape = 2, scale = 3) S <- surv(x) S(1) S(3)
Creates an S3 object representing a continuous uniform distribution on the
interval . The PDF is for
.
uniform_dist(min = 0, max = 1)uniform_dist(min = 0, max = 1)
min |
Lower bound of the distribution (default 0). |
max |
Upper bound of the distribution (default 1). |
A uniform_dist object with classes
c("uniform_dist", "univariate_dist", "continuous_dist", "dist").
x <- uniform_dist(min = 0, max = 10) mean(x) vcov(x) format(x)x <- uniform_dist(min = 0, max = 10) mean(x) vcov(x) format(x)
Computes .
## S3 method for class 'beta_dist' vcov(object, ...)## S3 method for class 'beta_dist' vcov(object, ...)
object |
A |
... |
Additional arguments (not used). |
The variance (scalar).
vcov(beta_dist(2, 5))vcov(beta_dist(2, 5))
chi_squared object.Retrieve the variance of a chi_squared object.
## S3 method for class 'chi_squared' vcov(object, ...)## S3 method for class 'chi_squared' vcov(object, ...)
object |
The |
... |
Additional arguments (not used) |
The variance, 2 * df
vcov(chi_squared(10))vcov(chi_squared(10))
Variance-covariance for non-dist objects (degenerate distributions).
## Default S3 method: vcov(object, ...)## Default S3 method: vcov(object, ...)
object |
The object (returns 0 for constants) |
... |
Additional arguments to pass (not used) |
0 (degenerate distributions have no variance)
vcov(42) # returns 0vcov(42) # returns 0
Method for obtaining the variance-covariance matrix (or scalar)
## S3 method for class 'edist' vcov(object, n = 10000, ...)## S3 method for class 'edist' vcov(object, n = 10000, ...)
object |
The |
n |
The number of samples to take (default: 10000) |
... |
Additional arguments to pass (not used) |
The variance-covariance matrix of the edist object
set.seed(1) z <- normal(0, 1) * exponential(2) vcov(z)set.seed(1) z <- normal(0, 1) * exponential(2) vcov(z)
empirical_dist object x.Method for obtaining the variance of empirical_dist object x.
## S3 method for class 'empirical_dist' vcov(object, ...)## S3 method for class 'empirical_dist' vcov(object, ...)
object |
The empirical distribution object. |
... |
Additional arguments to pass (not used). |
The sample variance-covariance matrix.
ed <- empirical_dist(c(1, 2, 3, 4, 5)) vcov(ed) # sample variance ed_mv <- empirical_dist(matrix(rnorm(20), ncol = 2)) vcov(ed_mv) # 2x2 covariance matrixed <- empirical_dist(c(1, 2, 3, 4, 5)) vcov(ed) # sample variance ed_mv <- empirical_dist(matrix(rnorm(20), ncol = 2)) vcov(ed_mv) # 2x2 covariance matrix
exponential object.Retrieve the variance of a exponential object.
## S3 method for class 'exponential' vcov(object, ...)## S3 method for class 'exponential' vcov(object, ...)
object |
The |
... |
Additional arguments to pass (not used) |
The variance-covariance matrix of the normal object
x <- exponential(rate = 2) vcov(x)x <- exponential(rate = 2) vcov(x)
gamma_dist object.Retrieve the variance of a gamma_dist object.
## S3 method for class 'gamma_dist' vcov(object, ...)## S3 method for class 'gamma_dist' vcov(object, ...)
object |
The |
... |
Additional arguments (not used) |
The variance, shape / rate^2
vcov(gamma_dist(shape = 3, rate = 2))vcov(gamma_dist(shape = 3, rate = 2))
Computes .
## S3 method for class 'lognormal' vcov(object, ...)## S3 method for class 'lognormal' vcov(object, ...)
object |
A |
... |
Additional arguments (not used). |
The variance (scalar).
vcov(lognormal(0, 1))vcov(lognormal(0, 1))
Uses the law of total variance:
.
## S3 method for class 'mixture' vcov(object, ...)## S3 method for class 'mixture' vcov(object, ...)
object |
A |
... |
Additional arguments (not used). |
The variance (scalar for univariate mixtures).
m <- mixture(list(normal(0, 1), normal(10, 1)), c(0.5, 0.5)) vcov(m)m <- mixture(list(normal(0, 1), normal(10, 1)), c(0.5, 0.5)) vcov(m)
mvn object.Retrieve the variance-covariance matrix of an mvn object.
## S3 method for class 'mvn' vcov(object, ...)## S3 method for class 'mvn' vcov(object, ...)
object |
The |
... |
Additional arguments to pass (not used) |
The variance-covariance matrix of the mvn object
X <- mvn(c(0, 0), diag(2)) vcov(X)X <- mvn(c(0, 0), diag(2)) vcov(X)
normal object.Retrieve the variance-covariance matrix (or scalar)
of a normal object.
## S3 method for class 'normal' vcov(object, ...)## S3 method for class 'normal' vcov(object, ...)
object |
The |
... |
Additional arguments to pass (not used) |
The variance-covariance matrix of the normal object
x <- normal(0, 4) vcov(x)x <- normal(0, 4) vcov(x)
For the Poisson distribution, the variance equals lambda.
## S3 method for class 'poisson_dist' vcov(object, ...)## S3 method for class 'poisson_dist' vcov(object, ...)
object |
A |
... |
Additional arguments (not used). |
The variance (scalar), equal to lambda.
vcov(poisson_dist(5))vcov(poisson_dist(5))
Computes .
## S3 method for class 'uniform_dist' vcov(object, ...)## S3 method for class 'uniform_dist' vcov(object, ...)
object |
A |
... |
Additional arguments (not used). |
The variance (scalar).
vcov(uniform_dist(0, 10))vcov(uniform_dist(0, 10))
univariate_dist object.Method for obtaining the variance of univariate_dist object.
## S3 method for class 'univariate_dist' vcov(object, ...)## S3 method for class 'univariate_dist' vcov(object, ...)
object |
The distribution object. |
... |
Additional arguments to pass into |
Numeric scalar; the variance of the distribution.
vcov(normal(0, 4)) # 4 vcov(exponential(2)) # 0.25vcov(normal(0, 4)) # 4 vcov(exponential(2)) # 0.25
Computes .
## S3 method for class 'weibull_dist' vcov(object, ...)## S3 method for class 'weibull_dist' vcov(object, ...)
object |
A |
... |
Additional arguments (not used). |
The variance (scalar).
vcov(weibull_dist(shape = 2, scale = 3))vcov(weibull_dist(shape = 2, scale = 3))
Creates an S3 object representing a Weibull distribution with the given shape and scale parameters. The Weibull PDF is
for .
weibull_dist(shape, scale)weibull_dist(shape, scale)
shape |
Positive scalar shape parameter. |
scale |
Positive scalar scale parameter. |
A weibull_dist object with classes
c("weibull_dist", "univariate_dist", "continuous_dist", "dist").
x <- weibull_dist(shape = 2, scale = 3) mean(x) vcov(x) format(x)x <- weibull_dist(shape = 2, scale = 3) mean(x) vcov(x) format(x)