I'm trying to simulate data for a model expressed with the following formula:lme4::lmer(y ~ a + b + (1|subject), data)
but with a set of given parameters:
a <- rnorm()
measured atsubject
level (e.gnSubjects = 50
)y
is measured at the observation level (e.g.nObs = 7
for eachsubject
b <- rnorm()
measured atobservation
level and correlated at a givenr
witha
- variance ratio of the random effects in
lmer(y ~ 1 + (1 | subject), data)
is fixed at for example 50/50 or 10/90 (and so on) - some random noise is present (so that a full model does not explain all the variance)
- effect size of the fixed effects can be set at a predefined level (e.g.
dCohen=0.5
)
I played with various packages like: powerlmm
, simstudy
or simr
but still fail to find a working solution that will accommodate the amount of parameters I'd like to define beforehand.
Also for my learning purposes I'd prefer a base R method than a package solution.
The closest example I found is a blog post by Ben Ogorek "Hierarchical linear models and lmer" which looks great but I can't figure out how to control for parameters listed above.
Any help would be appreciated. Also if there a package that I don't know of, that can do these type of simulations please let me know.
y ~ 1 + (1 | subject)
where the ratio of random variances was as I intended (for example 50/50 or some other). I didn't know how to include different level variables and keep the random variance ratio, how to include a correlation between fixed effects and how to include Cohen's d (but I can live without the ES if you say it's hard to get) – blazej