View source: R/generateMixedEffectDatasets.R
| generateRepeatedMeasuresDatasets | R Documentation |
Generate balanced repeated-measures datasets with a structured random-effect covariance.
generateRepeatedMeasuresDatasets(
numberOfDatasetsToGenerate,
numberOfSubjects,
numberOfVisits,
numberOfReplicates = 1L,
structure = c("unstructured", "cs", "ar1", "diag"),
marginalSd = 1,
correlation = 0,
trueBeta = 0,
trueSigma = 1,
errorGenerator = rnorm,
randomEffectGenerator = rnorm
)
numberOfDatasetsToGenerate |
number of datasets to generate. |
numberOfSubjects |
number of subjects (grouping levels). |
numberOfVisits |
number of levels of the within-subject factor (the dimension of the random effect). |
numberOfReplicates |
number of replicates per subject-by-visit cell. |
structure |
random-effect covariance structure, one of
|
marginalSd |
marginal standard deviation(s) of the random effects,
recycled to length |
correlation |
the structure's single correlation parameter (the
common correlation for |
trueBeta |
the true intercept (the only fixed effect). |
trueSigma |
the true residual standard deviation. |
errorGenerator, randomEffectGenerator |
functions used to draw the
errors and spherical random effects, see
|
Each subject is observed once per level of a within-subject factor
visit (with numberOfVisits levels), optionally replicated
numberOfReplicates times, giving a numberOfVisits-dimensional
random effect per subject through the term (0 + visit | subject).
The random-effect covariance follows the requested structure:
"unstructured"an arbitrary covariance (the
(0 + visit | subject) term).
"cs"compound symmetry: a common correlation
between all visits (cs(0 + visit | subject)).
"ar1"autoregressive: \mathrm{Cor}(i, j) =
\code{correlation}^{|i - j|} (ar1(0 + visit | subject)).
"diag"uncorrelated visits (diag(0 + visit |
subject)).
The data are simulated from the chosen covariance using the same
machinery as generateMixedEffectDatasets; the returned
object has the identical interface (including generateData,
formula and the fitDatasets_* compatibility) and stores the
structured covariance in trueTheta. Structured covariances require
lme4 >= 2.0-0.
A list with the same structure as the return value of
generateMixedEffectDatasets.
generateMixedEffectDatasets,
generateLongitudinalDatasets
if (packageVersion("lme4") >= "2.0.0") {
datasets <- generateRepeatedMeasuresDatasets(
1, numberOfSubjects = 30, numberOfVisits = 3, numberOfReplicates = 4,
structure = "cs", marginalSd = c(2, 1.5, 1.2), correlation = 0.5)
fit <- rlmer(datasets$formula, datasets$generateData(1), method = "DASvar")
VarCorr(fit)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.