Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/gather_variables.R
Given a data frame such as might be returned by tidy_draws
or spread_draws
,
gather variables and their values from that data frame into a ".variable"
and ".value"
column.
1 2  gather_variables(data, exclude = c(".chain", ".iteration", ".draw",
".row"))

data 
A data frame with variable names spread across columns, such as one returned by

exclude 
A character vector of names of columns to be excluded from the gather. Default ignores several metadata column names used in tidybayes. 
This function gathers every column except grouping columns and those matching the expression
exclude
into key/value columns ".variable"
and ".value"
.
Imagine a data frame data
as returned by spread_draws(fit, a[i], b[i,v])
, like this:
column ".chain"
: the chain number
column ".iteration"
: the iteration number
column ".draw"
: the draw number
column "i"
: value in 1:5
column "v"
: value in 1:10
column "a"
: value of "a[i]"
for draw number ".draw"
column "b"
: value of "b[i,v]"
for draw number ".draw"
gather_variables(data)
on that data frame would return a grouped
data frame (grouped by i
and v
), with:
column ".chain"
: the chain number
column ".iteration"
: the iteration number
column ".draw"
: the draw number
column "i"
: value in 1:5
column "v"
: value in 1:10
column ".variable"
: value in c("a", "b")
.
column ".value"
: value of "a[i]"
(when ".variable"
is "a"
;
repeated for every value of "v"
) or "b[i,v]"
(when ".variable"
is
"b"
) for draw number ".draw"
In this example, this call:
1 
Is roughly equivalent to:
1 2 3 
A data frame.
Matthew Kay
1 2 3 4 5 6 7 8 9 10 11 12 13 14  library(dplyr)
data(RankCorr, package = "tidybayes")
RankCorr %>%
spread_draws(b[i,v], tau[i]) %>%
gather_variables() %>%
median_qi()
# the first three lines below are roughly equivalent to ggmcmc::ggs(RankCorr)
RankCorr %>%
tidy_draws() %>%
gather_variables() %>%
median_qi()

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