extract_distribution: Extract a distribution represented by samples

extract_distributionR Documentation

Extract a distribution represented by samples

Description

The distribution can be extracted as:

  • a probability density function (type = "continuous"), cf. extract_pdf().

  • a probability mass function (type = "discrete"), cf. extract_pmf().

  • a series of equal-tailed confidence/credible intervals (type = "eti"), cf. extract_ci().

  • a series of highest density confidence/credible intervals (type = "hdi"), cf. extract_ci().

Usage

extract_distribution(
  object,
  parName = "",
  type = c("continuous", "discrete", "eti", "hdi"),
  transform = identity,
  ...
)

Arguments

object

Object specifying the distribution as samples: can be a Stanfit object, a matrix (columns represents parameters, rows samples) or a vector.

parName

Name of the parameter to extract.

type

Indicates how the distribution is summarised.

transform

Function to apply to the samples.

...

Arguments to pass to extract_pmf(), extract_pdf() or extract_ci() depending on type.

Value

Dataframe. The columns depends on the method that is used (see specific function for details).

Alternative

This function can notably be used to prepare the data for plotting fan charts when type = "eti" or "hdi". In that case, the ggdist package offers an alternative with ggdist::stat_lineribbon().

See Also

extract_draws() for extracting draws of an object.

Examples

extract_distribution(runif(1e2), type = "continuous", support = c(0, 1))

ghurault/HuraultMisc documentation built on Dec. 9, 2024, 10:39 a.m.