This function gather every column except grouping columns and those matching the regular expression
ignore_columns
into key/value columns "term"
and "estimate"
.
This function uses "term"
and "estimate"
instead of names like "parameter"
and "value"
in order to be consistent with the naming scheme of tidy
.
Imagine a data frame data
as returned by spread_samples(fit, a[i], b[i,v])
, like this:
column ".chain"
: the chain number
column ".iteration"
: the interation number
column "i"
: value in 1:5
column "v"
: value in 1:10
column "a"
: value of "a[i]"
for iteration number
".iteration"
on chain number ".chain"
column "b"
: value of "b[i,v]"
for iteration number
".iteration"
on chain number ".chain"
gather_terms(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 interation number
column "i"
: value in 1:5
column "v"
: value in 1:10
column "term"
: value in c("a", "b")
.
column "estimate"
: value of "a[i]"
(when "term"
is "a"
;
repeated for every value of "v"
) or "b[i,v]"
(when "term"
is
"b"
) for iteration number ".iteration"
on chain number ".chain"
In this example, this call:
gather_terms(data)
Is roughly equivalent to:
data %>%
gather(term, estimate, -c(.chain, .iteration, i, v)) %>%
group_by(term, add = TRUE)