This function uses permutations or sampling with replacement to disrupt relationships between variables but keep the distribution of each variable constant. Variables should be in columns of a matrix.

rand_var(x, MARGIN = 2, replace = FALSE, prob = NULL)

Arguments

x

matrix to be permuted

MARGIN

which dimension of a matrix to permute? Passed to apply.

replace

should sampling be with replacement? Passed to sample.int.

prob

a vector of probability weights for obtaining the elements of the vector being sampled. Passed to sample.int.

Value

Matrix of the same dimention as the original matrix but with values in each column permuted.

Examples

set.seed(4354) N = 100 x = matrix(rnorm(N * 10 * N), N * 10, N) x_rand = rand_var(x, MARGIN = 2, replace = FALSE, prob = NULL)