draws_quantile {rvec}R Documentation

Quantiles Across Random Draws

Description

Summarise the distribution of random draws in an rvec, using quantiles.

Usage

draws_quantile(x, probs = c(0.025, 0.25, 0.5, 0.75, 0.975), na_rm = FALSE)

## S3 method for class 'rvec'
draws_quantile(x, probs = c(0.025, 0.25, 0.5, 0.75, 0.975), na_rm = FALSE)

## S3 method for class 'rvec_chr'
draws_quantile(x, probs = c(0.025, 0.25, 0.5, 0.75, 0.975), na_rm = FALSE)

Arguments

x

An object of class rvec.

probs

Vector of probabilities.

na_rm

Whether to remove NAs before calculating summaries. Default is FALSE.

Details

The probs argument defaults to c(0.025, 0.25, 0.5, 0.75, 0.975), the values needed for a median, a 50% credible intervals, and a 95% credible interval.

Value

A tibble.

Warning

It is tempting to assign the results of a call to draws_quantile() to a column in a data frame, as in

my_df$quantile <- draws_quantile(my_rvec)

However, creating data frame columns in this way can corrupt data frames. For safer options, see the examples below.

See Also

draws_ci() creates simple credible intervals.

Other functions for applying pre-specified functions across draws are:

Apply arbitrary function across draws:

For additional functions for summarising random draws, see tidybayes and ggdist. Function as_list_col() converts rvecs into a format that tidybayes and ggdist can work with.

Examples

set.seed(0)
m <- rbind(a = rnorm(100, mean = 5, sd = 2),
           b = rnorm(100, mean = -3, sd = 3),
           c = rnorm(100, mean = 0, sd = 20))
x <- rvec(m)
x
draws_quantile(x)

## results from 'draws_quantile'
## assigned to a data frame
library(dplyr)
df <- data.frame(x)

## base R approach
cbind(df, draws_quantile(x))

## a tidyverse alternative:
## mutate with no '='
df |>
  mutate(draws_quantile(x))

[Package rvec version 0.0.6 Index]