draws_ci {rvec}R Documentation

Credible Intervals from Random Draws

Description

Summarise the distribution of random draws in an rvec, using a simple credible interval.

Usage

draws_ci(x, width = 0.95, prefix = NULL, na_rm = FALSE)

## S3 method for class 'rvec'
draws_ci(x, width = 0.95, prefix = NULL, na_rm = FALSE)

## S3 method for class 'rvec_chr'
draws_ci(x, width = 0.95, prefix = NULL, na_rm = FALSE)

Arguments

x

An object of class rvec.

width

A number, where ⁠0 < width <= 1⁠. Default is 0.975.

prefix

String to be added to the names of columns in the result. Defaults to name of x.

na_rm

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

Value

A tibble with three columns.

Warning

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

my_df$ci <- draws_ci(my_rvec)

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

See Also

draws_quantile() gives more options for forming quantiles.

Other ways of 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_ci(x)

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

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

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

[Package rvec version 0.0.6 Index]