Some distributions (such as dist_mixture(), dist_convolved(),
dist_inflated() and dist_transformed()) are defined in terms of one or
more other distributions. By default, family() only identifies the
outermost distribution. Setting recursive = TRUE will also identify the
families of these embedded distributions, returning a nested list
describing the full family tree of each distribution.
# S3 method for class 'distribution'
family(object, recursive = FALSE, ...)The distribution(s).
If TRUE, the families of any distributions embedded
within object (such as the components of a dist_mixture(), or the
base distribution of a dist_inflated() or dist_transformed()) are
also identified, and returned as a nested list instead of a flat
character vector.
Additional arguments used by methods.
If recursive = FALSE (the default), a character vector giving
the family name of each distribution. If recursive = TRUE, a list with
one element per distribution: a distribution with no embedded
distributions is represented by a character scalar (as before), while a
distribution built from others is represented by a named list with a
family element and one element per embedded distribution (containing
its recursive family() result, or a list of such results if that
element holds more than one embedded distribution).
dist <- c(
dist_normal(1:2),
dist_poisson(3),
dist_multinomial(size = c(4, 3),
prob = list(c(0.3, 0.5, 0.2), c(0.1, 0.5, 0.4)))
)
family(dist)
#> [1] "normal" "normal" "poisson" "multinomial" "multinomial"
# Distributions composed of other distributions (such as the mixture
# below) only identify the outer family by default.
mix_dist <- dist_mixture(dist_normal(0, 1), dist_normal(5, 2),
weights = c(0.3, 0.7))
family(mix_dist)
#> [1] "mixture"
# With recursive = TRUE, the families of the mixture's components are
# also identified.
family(mix_dist, recursive = TRUE)
#> [[1]]
#> [[1]]$family
#> [1] "mixture"
#>
#> [[1]]$dist
#> [[1]]$dist[[1]]
#> [1] "normal"
#>
#> [[1]]$dist[[2]]
#> [1] "normal"
#>
#>
#>