as_rvar {posterior} | R Documentation |
Convert x
to an rvar
object.
as_rvar(x, dim = NULL, dimnames = NULL, nchains = NULL) as_rvar_numeric(x, dim = NULL, dimnames = NULL, nchains = NULL)
x |
(multiple options) An object that can be converted to an |
dim |
(integer vector) One or more integers giving the maximal indices
in each dimension to override the dimensions of the |
dimnames |
(list) Character vectors giving the names in each dimension
to override the names of the dimensions of the |
nchains |
(positive integer) The number of chains. The default is |
For objects that are already rvar
s, returns them (with modified dimensions
if dim
is not NULL
).
For numeric or logical vectors or arrays, returns an rvar
with a single draw and
the same dimensions as x
. This is in contrast to the rvar()
constructor, which
treats the first dimension of x
as the draws dimension. As a result, as_rvar()
is useful for creating constants.
While as_rvar()
attempts to pick the most suitable subtype of rvar
based on the
type of x
(possibly returning a an rvar_factor
or rvar_ordered
),
as_rvar_numeric()
always coerces the draws of the output rvar
to be numeric
,
and always returns a base rvar
, never a subtype.
An object of class "rvar"
(or one of its subtypes) representing a random variable.
rvar()
to construct rvar
s directly. See rdo()
, rfun()
, and
rvar_rng()
for higher-level interfaces for creating rvar
s.
# You can use as_rvar() to create "constant" rvars (having only one draw): x <- as_rvar(1) x # Such constants can be of arbitrary shape: as_rvar(1:4) as_rvar(matrix(1:10, nrow = 5)) as_rvar(array(1:12, dim = c(2, 3, 2))) # as_rvar_numeric() coerces subtypes of rvar to the base rvar type y <- as_rvar_factor(c("a", "b", "c")) y as_rvar_numeric(y)