mutate_variables {posterior} | R Documentation |
Mutate variables in draws
objects
Description
Mutate variables in a draws
object.
Usage
mutate_variables(.x, ...)
## S3 method for class 'draws_matrix'
mutate_variables(.x, ...)
## S3 method for class 'draws_array'
mutate_variables(.x, ...)
## S3 method for class 'draws_df'
mutate_variables(.x, ...)
## S3 method for class 'draws_list'
mutate_variables(.x, ...)
## S3 method for class 'draws_rvars'
mutate_variables(.x, ...)
Arguments
.x |
(draws) A |
... |
Name-value pairs of expressions, each with either length 1 or the
same length as in the entire input (i.e., number of iterations or draws).
The name of each argument will be the name of a new variable, and the value
will be its corresponding value. Use a |
Details
In order to mutate variables in draws_matrix
and draws_array
objects,
they are transformed to draws_df
objects first and then transformed back
after mutation. As those transformations are quite expensive for larger
number of draws, we recommend using mutate_variables
on draws_df
and
draws_list
objects if speed is an issue.
In draws_rvars
objects, the output of each expression in ...
is
coerced to an rvar
object if it is not already one using as_rvar()
.
Value
Returns a draws
object of the same format as .x
, with variables mutated
according to the expressions provided in ...
.
See Also
Examples
x <- as_draws_df(example_draws())
x <- subset(x, variable = c("mu", "tau"))
mutate_variables(x, tau2 = tau^2)
mutate_variables(x, scale = 1.96 * tau, lower = mu - scale)