rvmatrix | R Documentation |
Arrange a given random vector into a matrix or array form.
rvmatrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) rvarray(data = NA, dim = length(data), dimnames = NULL)
data |
an optional data vector. |
nrow |
the desired number of rows. |
ncol |
the desired number of columns. |
byrow |
logical. If |
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. |
These are 'rv' compatible versions of the functions matrix
and
array
.
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.
Jouni Kerman jouni@kerman.com
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")
.
To plot random matrices, see mlplot
.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.