Learn R Programming

distributional (version 0.9.0)

family.distribution: Extract the name of the distribution family

Description

[Experimental]

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.

Usage

# S3 method for distribution
family(object, recursive = FALSE, ...)

Value

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).

Arguments

object

The distribution(s).

recursive

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.

Examples

Run this code
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)

# 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)

# With recursive = TRUE, the families of the mixture's components are
# also identified.
family(mix_dist, recursive = TRUE)

Run the code above in your browser using DataLab