Description Usage Arguments Details Value Author(s) Examples
View source: R/point_interval.R
Translates draws from distributions in a (possibly grouped) data frame into point and interval summaries (or set of point and interval summaries, if there are multiple groups in a grouped data frame).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63  point_interval(
.data,
...,
.width = 0.95,
.point = median,
.interval = qi,
.simple_names = TRUE,
na.rm = FALSE,
.exclude = c(".chain", ".iteration", ".draw", ".row"),
.prob
)
## Default S3 method:
point_interval(
.data,
...,
.width = 0.95,
.point = median,
.interval = qi,
.simple_names = TRUE,
na.rm = FALSE,
.exclude = c(".chain", ".iteration", ".draw", ".row"),
.prob
)
## S3 method for class 'numeric'
point_interval(
.data,
...,
.width = 0.95,
.point = median,
.interval = qi,
.simple_names = FALSE,
na.rm = FALSE,
.exclude = c(".chain", ".iteration", ".draw", ".row"),
.prob
)
qi(x, .width = 0.95, .prob, na.rm = FALSE)
hdi(x, .width = 0.95, .prob, na.rm = FALSE)
Mode(x, na.rm = FALSE)
hdci(x, .width = 0.95, na.rm = FALSE)
mean_qi(.data, ..., .width = 0.95)
median_qi(.data, ..., .width = 0.95)
mode_qi(.data, ..., .width = 0.95)
mean_hdi(.data, ..., .width = 0.95)
median_hdi(.data, ..., .width = 0.95)
mode_hdi(.data, ..., .width = 0.95)
mean_hdci(.data, ..., .width = 0.95)
median_hdci(.data, ..., .width = 0.95)
mode_hdci(.data, ..., .width = 0.95)

.data 
Data frame (or grouped data frame as returned by 
... 
Bare column names or expressions that, when evaluated in the context of

.width 
vector of probabilities to use that determine the widths of the resulting intervals.
If multiple probabilities are provided, multiple rows per group are generated, each with
a different probability interval (and value of the corresponding 
.point 
Point summary function, which takes a vector and returns a single
value, e.g. 
.interval 
Interval function, which takes a vector and a probability
( 
.simple_names 
When 
na.rm 
logical value indicating whether 
.exclude 
A character vector of names of columns to be excluded from summarization if no column names are specified to be summarized. Default ignores several metadata column names used in tidybayes. 
.prob 
Deprecated. Use 
x 
vector to summarize (for interval functions: 
If .data
is a data frame, then ...
is a list of bare names of
columns (or expressions derived from columns) of .data
, on which
the point and interval summaries are derived. Column expressions are processed
using the tidy evaluation framework (see rlang::eval_tidy()
).
For a column named x
, the resulting data frame will have a column
named x
containing its point summary. If there is a single
column to be summarized and .simple_names
is TRUE
, the output will
also contain columns .lower
(the lower end of the interval),
.upper
(the upper end of the interval).
Otherwise, for every summarized column x
, the output will contain
x.lower
(the lower end of the interval) and x.upper
(the upper
end of the interval). Finally, the output will have a .width
column
containing the' probability for the interval on each output row.
If .data
includes groups (see e.g. dplyr::group_by()
),
the points and intervals are calculated within the groups.
If .data
is a vector, ...
is ignored and the result is a
data frame with one row per value of .width
and three columns:
y
(the point summary), ymin
(the lower end of the interval),
ymax
(the upper end of the interval), and .width
, the probability
corresponding to the interval. This behavior allows point_interval
and its derived functions (like median_qi
, mean_qi
, mode_hdi
, etc)
to be easily used to plot intervals in ggplot stats using methods like
stat_eye()
, stat_halfeye()
, or stat_summary()
.
median_qi
, mode_hdi
, etc are short forms for
point_interval(..., .point = median, .interval = qi)
, etc.
qi
yields the quantile interval (also known as the percentile interval or
equitailed interval) as a 1x2 matrix.
hdi
yields the highestdensity interval(s) (also known as the highest posterior
density interval). Note: If the distribution is multimodal, hdi
may return multiple
intervals for each probability level (these will be spread over rows). You may wish to use
hdci
(below) instead if you want a single highestdensity interval, with the caveat that when
the distribution is multimodal hdci
is not a highestdensity interval. Internally hdi
uses
HDInterval::hdi()
with allowSplit = TRUE
(when multimodal) and with
allowSplit = FALSE
(when not multimodal).
hdci
yields the highestdensity continuous interval. Note: If the distribution
is multimodal, this may not actually be the highestdensity interval (there may be a higherdensity
discontinuous interval). Internally hdci
uses
HDInterval::hdi()
with allowSplit = FALSE
; see that function for more
information on multimodality and continuous versus discontinuous intervals.
A data frame containing point summaries and intervals, with at least one column corresponding
to the point summary, one to the lower end of the interval, one to the upper end of the interval, the
width of the interval (.width
), the type of point summary (.point
), and the type of interval (.interval
).
Matthew Kay
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38  library(dplyr)
library(ggplot2)
set.seed(123)
rnorm(1000) %>%
median_qi()
data.frame(x = rnorm(1000)) %>%
median_qi(x, .width = c(.50, .80, .95))
data.frame(
x = rnorm(1000),
y = rnorm(1000, mean = 2, sd = 2)
) %>%
median_qi(x, y)
data.frame(
x = rnorm(1000),
group = "a"
) %>%
rbind(data.frame(
x = rnorm(1000, mean = 2, sd = 2),
group = "b")
) %>%
group_by(group) %>%
median_qi(.width = c(.50, .80, .95))
multimodal_draws = data.frame(
x = c(rnorm(5000, 0, 1), rnorm(2500, 4, 1))
)
multimodal_draws %>%
mode_hdi(.width = c(.66, .95))
multimodal_draws %>%
ggplot(aes(x = x, y = 0)) +
stat_halfeye(point_interval = mode_hdi, .width = c(.66, .95))

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.