mre: Multivariate Random Effects

Description Usage Arguments Details Value Author(s) Examples

Description

mre handles the evaluation of multivariate random effects with two behaviours. It evaluates the multivariate effects applied to the factor x if size == NULL and it simulates the replicated factor x if size is provided.

Usage

1
mre(x, sigma, groups, size = NULL, replace = TRUE)

Arguments

x

A replicated covariate factor of length nq to evaluate the multivariate effects. It is a q times replicated vector of x*. If size != NULL, x is the output of the function.

sigma

A qxq covariance matrix S for the random effects.

groups

A character vector of length k to name the levels of the factor x or a numeric value indicating the number of groups of x.

size

A numeric value n representing the number of units, it is used to simulate the covariate x. In case size == NULL, mfa evaluates the effects.

replace

An logical value provided to the function sample to allow repetition of groups or not. It is used to simulate an independent random effect with one repetition (e.g. mre(groups = 100, size = 100, replace = FALSE)).

Details

Considering x* the n-length factor under study with k levels and X the associated nxk design matrix with dummy variables corresponding to each level of the factor, the returning multivariate effect is

vec(XU),

where U is a kxq matrix of random effects and vec(.) represents a vectorization by columns of the provided matrix. Each row u_i of U is assumed to come from a zero-mean normal distribution with covariance matrix S of dimension qxq,

Value

A simulated replicated factor x in case size is provided; otherwise, a nq-length numeric vector of the evaluated multivariate effects.

Author(s)

Erick A. Chacón-Montalván

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Multivariate random effects for 10 units belonging to 3 groups.
Sigma <- matrix(c(1, 0.8, 0.5, 0.8, 1, 0.5, 0.5, 0.5, 1), nrow = 3)
(x <- mre(groups = 3, sigma = Sigma, size = 10))
(effect <- mre(x, sigma = Sigma))

# Multivariate independent random effects for 10 units.
Sigma <- matrix(c(1, 0.8, 0.5, 0.8, 1, 0.5, 0.5, 0.5, 1), nrow = 3)
(x <- mre(groups = 10, sigma = Sigma, size = 10, replace = FALSE))
(effect <- mre(x, sigma = Sigma))

# Multivariate random effects for 500 units belonging to 100 groups.
Sigma <- matrix(c(1, 0.8, 0.5, 0.8, 1, 0.5, 0.5, 0.5, 1), nrow = 3)
(x <- mre(groups = 100, sigma = Sigma, size = 500))
(effect <- mre(x, sigma = Sigma))

# Check empirical covariance matrix of the random effects.
cov(unique(matrix(effect, ncol = nrow(Sigma))))

ErickChacon/datasim documentation built on March 25, 2020, 7:53 p.m.