Description Usage Arguments Details Value Examples
View source: R/stroop_simulate.R
Simulate data from a mixed factorial design based on the Many Labs 3 (ML3) \insertCiteML3autocorr Stroop data.
1 2 3 4 5 6 7 8 | simulate_stroop(
n_subj,
B1 = 0,
B2 = 0,
rivar = diag(autocorr::stroop_mod$covmx)[1],
rsvar = diag(autocorr::stroop_mod$covmx)[2],
verbose = FALSE
)
|
n_subj |
Number of subjects. |
B1 |
Fixed effect of congruency. |
B2 |
Fixed effect of the between-subjects factor. |
rivar |
Random intercept variance. |
rsvar |
Random slope variance. |
verbose |
Whether to return error components (random effects and residuals). |
The ML3 data was from a simple design including only the
within-factor of congruency. The simulated data includes an
additional between-subjects factor. The simulation parameters are
taken from stroop_mod, with a random subset of
residuals grafted onto the fitted values for each subject.
The simulated response latency for observation j of subject
i is given by the following formula:
latency_ij = B0 + b_0i + B2 * B_i + (B1 + b_1i) * W_ij + e_ij
where B0 is stroop_mod$fixed["(Intercept)"],
b_0i and b_1i are the random intercept and random
slope for subject i, W_ij and B_i are
deviation-coded predictors for the within- and between- subject
factors respectively, B1 and B2 are the raw within- and
between- subject effect sizes, and e_ij is the jth
residual for subject i.
Note that whereas the original dataset had 63 observations per subject (with 2/3 in the incongruent condition and 1/3 in the congruent condition), the current dataset had 1/2 congruent and 1/2 incongruent. Also, only the first 20 of the 63 residuals were used, to eliminate discontinuities introduced at the start of each 21-trial block.
A data frame with n_subj * 20 simulated observations
on 7 (or 10) variables, depending on verbose:
session_idA factor with session_id values
corresponding to the subjects whose residuals were sampled from
stroop_mod[["resid"]]
.
trialAn integer specifying the trial number (1 to 20).
congruencyLevel of within-subject factor (congruent or incongruent).
groupLevel of between-subject factor (G1 or G2).
W_ijDeviation-coded predictor for factor congruency.
B_iDeviation-coded predictor for factor group.
Y_ijSimulated response latency in milliseconds.
b_0iRandom effect for subject i (verbose mode only).
b_1iRandom slope for subject i (verbose mode only).
e_ijResidual for subject i, observation j (verbose mode only).
1 2 3 4 5 | ## use parameters from Many Labs 3 model fit
dat <- simulate_stroop(48, A = stroop_mod$fixed["cong"])
mod <- lme4::lmer(Y_ij ~ W_ij + B_i + (W_ij || session_id), dat)
summary(mod)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.