Matrices and Arrays of Random Vectors

Share:

Description

Arrange a given random vector into a matrix or array form.

These are 'rv' compatible versions of the functions matrix and array.

Usage

1
2
3
4
5
6
 rvarray(data = NA, dim = length(data), dimnames = NULL) 
 rvmatrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL)
 ## S3 method for class 'rv'
is.matrix(x)
 ## S3 method for class 'rv'
as.matrix(x, ...)

Arguments

data

an optional data vector.

nrow

the desired number of rows.

ncol

the desired number of columns.

byrow

logical. If FALSE (the default) the matrix is filled by columns, otherwise the matrix is filled by rows.

dimnames

A dimnames attribute for the matrix: a list of length 2 giving the row and column names respectively.

dim

the dim attribute for the array to be created, that is a vector of length one or more giving the maximal indices in each dimension.

...

arguments passed to other methods

x

an R object.

Details

The function rvmatrix generates the random variable matrix via an rvarray call.

The rvarray function calls first array to set the dimensions of the argument data and then coerces the resulting array object to an 'rv' object.

Author(s)

Jouni Kerman jouni@kerman.com

References

Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.

See also vignette("rv").

See Also

To plot random matrices, see mlplot.

Examples

1
2
3
4
5
6
7
8
  n.rows <- 3; n.cols <- 4; n <- (n.rows*n.cols)
  mu.true <- rnorm(1:n.rows, mean=1:n.rows, sd=1)
  theta <- rvmatrix(rvnorm(n=n.cols, mean=mu.true, sd=0.5), nrow=n.rows)
  col.labels <- paste("Time", 1:n.cols, sep=":")
  row.labels <- paste("Unit", 1:n.rows, sep=":")
  dimnames(theta) <- list(row.labels, col.labels)
  print(theta)
  print(E(theta))  

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.