`R/rvar-summaries-over-draws.R`

`rvar-summaries-over-draws.Rd`

Compute summaries within elements of an `rvar`

and over draws of each element,
producing an array of the same shape as the input random variable (except in
the case of `range()`

, see **Details**).

```
E(x, ...)
# S3 method for rvar
mean(x, ...)
Pr(x, ...)
# S3 method for default
Pr(x, ...)
# S3 method for logical
Pr(x, ...)
# S3 method for rvar
Pr(x, ...)
# S3 method for rvar
median(x, ...)
# S3 method for rvar
min(x, ...)
# S3 method for rvar
max(x, ...)
# S3 method for rvar
sum(x, ...)
# S3 method for rvar
prod(x, ...)
# S3 method for rvar
all(x, ...)
# S3 method for rvar
any(x, ...)
# S3 method for rvar
Summary(...)
# S3 method for rvar
variance(x, ...)
var(x, ...)
# S3 method for default
var(x, ...)
# S3 method for rvar
var(x, ...)
sd(x, ...)
# S3 method for default
sd(x, ...)
# S3 method for rvar
sd(x, ...)
mad(x, ...)
# S3 method for default
mad(x, ...)
# S3 method for rvar
mad(x, ...)
# S3 method for rvar_ordered
mad(x, ...)
# S3 method for rvar
range(x, ...)
# S3 method for rvar
is.finite(x)
# S3 method for rvar
is.infinite(x)
# S3 method for rvar
is.nan(x)
# S3 method for rvar
is.na(x)
```

- x
(rvar) An

`rvar`

.- ...
Further arguments passed to underlying functions (e.g.,

`base::mean()`

or`base::median()`

), such as`na.rm`

.

A numeric or logical vector with the same dimensions as the given random variable, where
each entry in the vector is the mean, median, or variance of the corresponding entry in `x`

.

Summaries include expectations (`E()`

or `mean()`

), probabilities (`Pr()`

),
medians (`median()`

), spread (`var()`

, `variance()`

, `sd()`

, `mad()`

), sums and
products (`sum()`

, `prod()`

), extrema and ranges (`min()`

, `max()`

, `range()`

),
logical summaries (`all()`

, `any()`

), and special value predicates (`is.finite()`

,
`is.infinite()`

, `is.nan()`

, `is.na()`

).

Unless otherwise stated, these functions return a numeric array with the same shape
(same dimensions) as the input `rvar`

, `x`

.

`range(x)`

returns an array with dimensions `c(2, dim(x))`

, where the last
dimension contains the minimum and maximum values.

`is.infinite(x)`

, `is.nan(x)`

, and `is.na(x)`

return logical arrays, where each
element is `TRUE`

if **any** draws in its corresponding element in `x`

match
the predicate. Each elements in the result of `is.finite(x)`

is `TRUE`

if
**all** draws in the corresponding element in `x`

are finite.

Both `E()`

, `mean()`

, and `Pr()`

return the means of each element in the input.
`Pr()`

additionally checks that the provided `rvar`

is a logical variable (hence, taking its expectation results in a probability).

For consistency, `E()`

and `Pr()`

are also defined for base arrays so that
they can be used as summary functions in `summarise_draws()`

.

rvar-summaries-within-draws for summary functions within draws. rvar-dist for density, CDF, and quantile functions of random variables.

Other rvar-summaries:
`rvar-summaries-within-draws`

,
`rvar_is_finite()`

```
set.seed(5678)
x = rvar_rng(rnorm, 4, mean = 1:4, sd = 2)
# These should all be ~= c(1, 2, 3, 4)
E(x)
#> [1] 1.004952 1.955997 3.011070 3.963980
mean(x)
#> [1] 1.004952 1.955997 3.011070 3.963980
median(x)
#> [1] 0.9557178 1.9170014 3.0024683 3.9274693
# This ...
Pr(x < 1.5)
#> [1] 0.59800 0.41100 0.22300 0.10775
# ... should be about the same as this:
pnorm(1.5, mean = 1:4, sd = 2)
#> [1] 0.5987063 0.4012937 0.2266274 0.1056498
```