Skip to contents

Helper function to construct an instance of a <VarDist> object, which defines a variable of interest in terms of its probability distribution, sampling distribution, percentile distribution or fixed point estimate.

Usage

VarDist(distr = NULL, units = NULL)

Arguments

distr

either an object of class <distribution> or a numeric value. Specifies the distribution of values of the variable, representing its expected value and uncertainty/variability. If a numeric value is provided, the variable is assumed to be constant and will remain fixed throughout the simulation.

units

a character string, defining the measurement units of the variable. Must be either a name (e.g. "grams") or a symbol (e.g. "m/s") that recognized by the "udunits" database (see units::valid_udunits()). If NULL (default) the variable is assumed to be unitless.

Value

an object of class <VarDist>

Details

<VarDist> objects extend the functionality of the commendable distributional package by integrating measurement units, ensuring that variable values are interpreted and processed correctly during simulation calculations.

See also

  • Package distributional for access to and details on a comprehensive selection of distributions.

  • Utility functions for <VarDist> objects in VarDist-utils.

Examples

#library(distributional)

# define a Normally distributed variable with units m/s
VarDist(dist_normal(mean = 23, sd = 2), "m/s")
#> <VarDist>
#> N(23, 4) [m s-1]


# define a parameter with fixed value
VarDist(10, "m")
#> <VarDist>
#> 10 [m]


# set variable's empirical distribution from a random sample (e.g a bootstrap)
boot <- rlnorm(100, 2, 1)
VarDist(dist_sample(list(boot)), "kg")
#> <VarDist>
#> sample[100] [kg]