Skip to contents

Evaluate a distribution property. The distribution itself is first searched for the property, and if it can't be found, will attempt to calculate the property from other entries.

Usage

eval_property(distribution, entry, ...)

Arguments

distribution

Distribution object.

entry

Name of the property, such as "cdf" or "mean". Length 1 character vector.

...

If the property is a function, arguments to the function go here. Need not be named; inserted in the order they appear.

Value

The distribution's property, evaluated. If cannot be evaluated, returns NULL.

Examples

d <- distribution(
  cdf = \(x) (x > 0) * pmin(x^2, 1),
  g = 9.81,
  .vtype = "continuous"
)
eval_property(d, "g")
#> [1] 9.81
eval_property(d, "quantile", 1:9 / 10)
#> [1] 0.3162278 0.4472136 0.5477226 0.6324555 0.7071068 0.7745967 0.8366600
#> [8] 0.8944272 0.9486833
eval_property(d, "mean")
#> [1] NaN
eval_property(d, "realise", 10)
#>  [1] 0.4518610 0.8446285 0.2553745 0.5951528 0.9084049 0.5232765 0.7550132
#>  [8] 0.5794127 0.7721805 0.4376277
eval_property(d, "foofy")
#> NULL
eval_property(d, "foofy", 1:10)
#> NULL