Vectors Representing Random Variables

Random vectors, called rvecs. An rvec holds multiple draws, but tries to behave like a standard R vector, including working well in data frames. Rvecs are useful for analysing output from a simulation or a Bayesian analysis.


rvec

R-CMD-check Codecov testcoverage CRANstatus

Tools for working with random draws, including draws from a simulation or Bayesian analysis. The main data structure is an rvec, which holds multiple draws but which behaves (mainly) like a standard R vector.

Installation

install.packages(rvec)

Example

library(rvec, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)

Create an rvec.

x <- rvec(rbind(c(10, 11),
                c(100, 101),
                c(1000, 1001)))
x
#> <rvec_dbl<2>[3]>
#> [1] 10,11     100,101   1000,1001

Perform arithmetic on it.

x + 1
#> <rvec_dbl<2>[3]>
#> [1] 11,12     101,102   1001,1002

Put it in a tibble.

df <- tibble(g = c(1, 2, 1), x)
df
#> # A tibble: 3 × 2
#>       g         x
#>   <dbl> <rdbl<2>>
#> 1     1     10,11
#> 2     2   100,101
#> 3     1 1000,1001

Manipulate it in a tibble.

df %>%
  group_by(g) %>%
  count(wt = x)
#> # A tibble: 2 × 2
#> # Groups:   g [2]
#>       g         n
#>   <dbl> <rdbl<2>>
#> 1     1 1010,1012
#> 2     2   100,101

Summarise it.

draws_mean(x)
#> [1]   10.5  100.5 1000.5

Other packages for working with random draws

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rvec")

1.0.5 by John Bryant, 17 days ago


https://bayesiandemography.github.io/rvec/, https://github.com/bayesiandemography/rvec


Report a bug at https://github.com/bayesiandemography/rvec/issues


Browse source code at https://github.com/cran/rvec


Authors: John Bryant [aut, cre] , Bayesian Demography Limited [cph]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, glue, graphics, grDevices, lifecycle, Matrix, matrixStats, methods, rlang, stats, tibble, tidyselect, utils, vctrs

Suggests bookdown, covr, dplyr, ggplot2, knitr, rmarkdown, testthat, tidyr, withr


Imported by poputils.

Depended on by bage.


See at CRAN