Skip to contents

When a distribution has p, d, q, r functions available (such as pnorm(), dnorm(), etc.), dst_parametric() creates a distribution that draws on these four functions.

Usage

dst_parametric(
  .name,
  ...,
  .variable = c("unknown", "continuous", "discrete", "mixed"),
  .env = parent.frame()
)

Arguments

.name

Name of the distribution. Specifically, a string with the suffix of the p, d, q, r functions (such as "norm").

...

Name-value pairs of parameters. Names must be found in the parameter names of the p, d, q, r functions.

.variable

Type of random variable represented by the distribution. Warning: defaults to "unknown", where density, pmf, and hazard cannot be evaluated.

.env

Environment beginning the search path when looking for the representation, or the name of an environment (or any object that can be coerced to an environment with as.environment().) Defaults to the calling environment.

Examples

d <- dst_parametric("norm", mean = 0, sd = 1, .variable = "continuous")
eval_density(d, at = -3:3)
#> [1] 0.004431848 0.053990967 0.241970725 0.398942280 0.241970725 0.053990967
#> [7] 0.004431848
eval_pmf(d, at = -3:3, strict = FALSE)
#> [1] 0 0 0 0 0 0 0
eval_hazard(d, at = -3:3)
#> [1] 0.004437839 0.055247863 0.287599971 0.797884561 1.525135276 2.373215533
#> [7] 3.283098655