generate.data {nlmm} | R Documentation |
Simulate Data from Mixed-Effects Models
Description
This function generates data from a 2-level hierarchical design.
Usage
generate.data(R, n, M, sigma_1 = NULL, sigma_2 = NULL,
shape_1 = NULL, shape_2 = NULL, dist.u, dist.e,
beta, gamma, fixed = FALSE, seed = round(runif(1,1,1000)))
Arguments
R |
number of replications. |
n |
number of observations within cluster. |
M |
number of clusters. |
sigma_1 |
scale parameter for the random effects. |
sigma_2 |
scale parameter for the errors. |
shape_1 |
shape parameter for the random effects. |
shape_2 |
shape parameter for the errors. |
dist.u |
distribution of the random effects. |
dist.e |
distribution of the errors. |
beta |
vector of coefficients for fixed effects. |
gamma |
vector of coefficients for heteroscedasticity. |
fixed |
logical flag. See details. |
seed |
seed for random number generation. |
Details
This function generates data as in the simulation study by Geraci and Farcomeni (2020). The data-generating model is
y[ij] = \beta[0] + \beta[1]x[ij] + \beta[2]z[ij] + u[i] + v[i]x[ij] + (\gamma[0] + \gamma[1]x[ij])e[ij]
where (u[i],v[i])
follows a distribution with scale sigma_1
and shape shape_1
, and e
follows a distribution with scale sigma_2
and shape shape_2
.
The scale parameter sigma_1
must be a 1 by 1 or a 2 by 2 matrix. In the former case, the model will include only random intercepts. In the latter case, then both random intercepts and slopes will be included. Currently, no more than 2 random effects can be specified. The scale parameter sigma_2
must be a matrix n
by n
.
The options for dist.u
and dist.e
are: multivariate normal ("norm") (rmvnorm
), multivariate symmetric Laplace ("laplace") (rmal
), multivariate symmetric generalized Laplace ("genlaplace") rmgl
, and multivariate Student's t ("t") (rmvt
).
The shape parameter specifies the degrees of freedom for Student's t and chi-squared, and the kurtosis of the generalized Laplace.
The values x[ij]
are generated as x[ij] = \delta[i] + \zeta[ij]
, where \delta[i]
and \zeta[ij]
are independent standard normal. If the argument fixed = TRUE
, then x[ij] = j
. The values z[ij]
are generated from Bernoullis with probability 0.5.
Value
nlmm
returns an object of class
nlmm
.
The function summary
is used to obtain and print a summary of the results.
An object of class nlmm
is a list containing the following components:
Y |
a matrix |
X |
an array |
group |
vector of length |
u |
an array |
e |
a matrix |
Author(s)
Marco Geraci
References
Geraci, M. and Farcomeni A. (2020). A family of linear mixed-effects models using the generalized Laplace distribution. Statistical Methods in Medical Research, 29(9), 2665-2682.
See Also
Examples
# Simulate 10 replications from a homoscedastic normal mixed model.
generate.data(R = 10, n = 3, M = 5, sigma_1 = diag(2), sigma_2 = diag(3),
shape_1 = NULL, shape_2 = NULL, dist.u = "norm", dist.e = "norm",
beta = c(1,2,1), gamma = c(1,0))
# Simulate 10 replications from a generalized Laplace. Note: the shape
# parameter that is passed to rmgl corresponds to the reciprocal of the
# parameter alpha in Geraci and Farcomeni (2020)
generate.data(R = 10, n = 3, M = 5, sigma_1 = diag(2), sigma_2 = diag(3),
shape_1 = 1/0.5, shape_2 = 1/0.5, dist.u = "genlaplace", dist.e = "genlaplace",
beta = c(1,2,1), gamma = c(1,0))