An R6 class representing a (possibly multivariate) distribution.
Andrew J. Sims andrew.sims@newcastle.ac.uk
new()
Create an object of class Distribution
.
Distribution$new(name, K = as.integer(1))
name
Name of the distribution ("Beta" etc.)
K
Order of the distribution (1=univariate, 2=bivariate etc.).
Must be an integer; use as.integer()
to avoid an error.
An object of class Distribution
.
Order (K
).
distribution()
Description of the uncertainty distribution.
Distribution$distribution()
Includes the distribution name and its parameters.
Distribution name and parameters as character string.
Mean value as a numeric scalar (K=1
) or vector of
length K
.
By default returns NA
, which will be the case for most
because an arbitrary distribution is not guaranteed to be unimodal.
Mode as a numeric scalar (K=1
) or vector of
length K
.
SD()
Return the standard deviation of a univariate distribution.
Distribution$SD()
Only defined for univariate (K=1
) distributions; for
multivariate distributions, function varcov
returns the
variance-covariance matrix.
Standard deviation as a numeric value.
varcov()
Variance-covariance matrix.
Distribution$varcov()
A positive definite symmetric matrix of size K
by
K
, or a scalar for K=1
, equal to the variance.
probs
Numeric vector of probabilities, each in range [0,1].
If they are defined, this function returns the marginal
quantiles of the multivariate distribution; i.e. the quantiles of each
univariate marginal distribution of the multivariate distribution. For
example, the univariate marginal distributions of a multivariate
normal are univariate normals, and the univariate marginal distributions
of a Dirichlet distribution are Beta distributions. Note that these are
not the true quantiles of a multivariate distribution, which are contours
for K=2
, surfaces for K=3
, etc. Thus, for example, the
2.5% and 97.5% marginal quantiles of a bivariate normal distribution
define a rectangle in \(x_1, x_2\) space that will include more than
95% of the distribution, whereas the contour containing 95% of the
distribution is an ellipse.
For K=1
a numeric vector of length equal to the length of
probs
, with each entry labelled with the quantile. For K>1
a matrix of numeric values with the number of rows equal to the length
of probs
, the number of columns equal to the order; rows are
labelled with quantiles and columns with the dimension (1, 2, etc).
sample()
Draw and hold a random sample from the distribution.
Distribution$sample(expected = FALSE)
expected
If TRUE, sets the next value retrieved by a call to
r()
to be the mean of the distribution.
Void
r()
Return a random sample drawn from the distribution.
Distribution$r()
Returns the sample generated at the last call to sample
.
A vector of length K
representing one sample.
clone()
The objects of this class are cloneable with this method.
Distribution$clone(deep = FALSE)
deep
Whether to make a deep clone.
The base class for particular univariate or multivariate distributions.