Learn R Programming

posterior (version 1.6.0)

rvar-summaries-within-draws: Summaries of random variables over array elements, within draws

Description

Compute summaries of random variables over array elements and within draws, producing a new random variable of length 1 (except in the case of rvar_range(), see Details).

Usage

rvar_mean(..., na.rm = FALSE)

rvar_median(..., na.rm = FALSE)

rvar_sum(..., na.rm = FALSE)

rvar_prod(..., na.rm = FALSE)

rvar_min(..., na.rm = FALSE)

rvar_max(..., na.rm = FALSE)

rvar_sd(..., na.rm = FALSE)

rvar_var(..., na.rm = FALSE)

rvar_mad(..., constant = 1.4826, na.rm = FALSE)

rvar_range(..., na.rm = FALSE)

rvar_quantile(..., probs, names = FALSE, na.rm = FALSE)

rvar_all(..., na.rm = FALSE)

rvar_any(..., na.rm = FALSE)

Value

An rvar of length 1 (for range(), length 2; for quantile(), length equal to length(probs)) with the same number of draws as the input rvar(s) containing the summary statistic computed within each draw of the input rvar(s).

Arguments

...

(rvar) One or more rvars.

na.rm

(logical) Should NAs be removed from the input before summaries are computed? The default is FALSE.

constant

(scalar real) For rvar_mad(), a scale factor for computing the median absolute deviation. See the details of stats::mad() for the justification for the default value.

probs

(numeric vector) For rvar_quantile(), probabilities in [0, 1].

names

(logical) For rvar_quantile(), if TRUE, the result has a names attribute.

Details

These functions compute statistics within each draw of the random variable. For summaries over draws (such as expectations), see rvar-summaries-over-draws.

Each function defined here corresponds to the base function of the same name without the rvar_ prefix (e.g., rvar_mean() calls mean() under the hood, etc).

See Also

rvar-summaries-over-draws for summary functions across draws (e.g. expectations). rvar-dist for density, CDF, and quantile functions of random variables.

Other rvar-summaries: rvar-summaries-over-draws, rvar_is_finite()

Examples

Run this code

set.seed(5678)
x = rvar_rng(rnorm, 4, mean = 1:4, sd = 2)

# These will give similar results to mean(1:4),
# median(1:4), sum(1:4), prod(1:4), etc
rvar_mean(x)
rvar_median(x)
rvar_sum(x)
rvar_prod(x)
rvar_range(x)
rvar_quantile(x, probs = c(0.25, 0.5, 0.75), names = TRUE)

Run the code above in your browser using DataLab