Learn R Programming

posterior (version 1.7.0)

extract_variable_array: Extract array of a single (possibly indexed) variable

Description

Extract an array of draws of a single variable, including any dimensions of variables with indices.

Usage

extract_variable_array(x, variable, with_chains = TRUE, ...)

# S3 method for default extract_variable_array(x, variable, with_chains = TRUE, ...)

# S3 method for draws extract_variable_array(x, variable, with_chains = TRUE, ...)

Value

An array with dimension niterations(x) x nchains(x) x any remaining dimensions determined by the indices of the variable x (if with_chains = TRUE) or dimension niterations(x) * nchains(x) x any remaining dimensions (if with_chains = FALSE).

Arguments

x

(draws) A draws object or another R object for which the method is defined.

variable

(string) The name of the variable to extract. To extract all dimensions from variables with indices (e.g. "x[1]"), provide the base variable name (e.g. "x").

with_chains

(logical) Should the array of draws include a dimension for chains? If TRUE (the default), chains are included and the array has dimension c(niterations(x), nchains(x), ...). If FALSE, chains are not included and the array has dimension c(niterations(x) * nchains(x), ...).

...

Arguments passed to individual methods (if applicable).

See Also

Other variable extraction methods: extract_list_of_variable_arrays(), extract_variable(), extract_variable_matrix()

Examples

Run this code
x <- example_draws(example = "multi_normal")

mu <- extract_variable_array(x, variable = "mu")
str(mu)

# With chains collapsed
mu_no_chains <- extract_variable_array(x, variable = "mu", with_chains = FALSE)
str(mu_no_chains)

mu1 <- extract_variable_array(x, variable = "mu[1]")
str(mu1)

Sigma <- extract_variable_array(x, variable = "Sigma")
str(Sigma)

Run the code above in your browser using DataLab