Power analysis from scratch"

If pilot data is not available, simr can be used to create lme4 objects from scratch as a starting point. This requires more paramters to be specified by the user. Values for these parameters might come from the literature or the user's own knowledge and experience.

library(simr)
simrOptions(nsim=100, progress=FALSE)

Covariates and parameters

First set up some covariates with expand.grid.

x <- 1:10
g <- letters[1:3]

X <- expand.grid(x=x, g=g)

Specify some fixed and random parameters.

b <- c(2, -0.1) # fixed intercept and slope
V1 <- 0.5 # random intercept variance
V2 <- matrix(c(0.5,0.05,0.05,0.1), 2) # random intercept and slope variance-covariance matrix
s <- 1 # residual standard deviation

Build a model object

Use the makeLmer or makeGlmer function to build an artificial lme4 object.

model1 <- makeLmer(y ~ x + (1|g), fixef=b, VarCorr=V1, sigma=s, data=X)
print(model1)
model2 <- makeGlmer(z ~ x + (x|g), family="poisson", fixef=b, VarCorr=V2, data=X)
print(model2)

Start the power analysis

Now we have "pilot" models, which can be used with simr.

powerSim(model1, nsim=20)
powerSim(model2, nsim=20)


Try the simr package in your browser

Any scripts or data that you put into this service are public.

simr documentation built on April 14, 2023, 12:24 a.m.