# simr power simulation testing interaction term for 2 factors

I have a model with two factors: a (4 levels) and b (3 levels). Each participant receives two problems (id as a random effect). I want to estimate sample size based on pilot data to give me sufficient power to detect an interaction effect.

The model would be as follows:

mod1 <- lmer(outcome ~ a*b+ (1 | id), data).

If I run a powerSim on the interaction given the current data (without changing effect sizes), the power is ~ 66% using the following:

powerSim(mod1, fixed(“a:b”, "lr"), nsim=100)

And is similar if I were to test the interaction using fcompare (to the main effects):

powerSim(mod1, fcompare(~ a+b), nsim=100)

Now I know that estimating power based on one’s own data is not good, so I want to change the effect size estimates. However, I am unsure whether I need to change each fixed effect (e.g., a1:b1, a2:b1…) separately, or if there is a way to test the whole interaction with one test (e.g., like the fcompare test above)? If I do need to change the fixed effect estimate for each of the interaction terms, do I do so individually, estimate the power/sample size, and repeat for each fixed effect or do all changes in the same model (e.g., change all fixed effects)?

e.g.,:

fixef(mod1)["a1:b1"] <- 2
fixef(mod1)["a1:b2"] <- 2.1 ...

If not, how do I change the effect estimate for the interaction term to test the whole interaction?

The next step would then be to extend the model and increase the sample within each group, for example:

mod2 <- extend(mod1, within=“a+b”, n=100)

I have seen the interaction term tested when one of the predictors is continuous, but not when both are factors. Any help would be much appreciated.

• Did you try using the fcompare function, as explained here: cran.r-project.org/web/packages/simr/vignettes/examples.html? This function allows you to test the model without an interaction against the model with an interaction term. – Isabella Ghement May 20 at 18:34
• Thanks @IsabellaGhement I did try using the fcompare function to test the interaction. This works but it is an estimate based on my own pilot data which I understand is not a good thing to do for a power calculation. I am not sure how to modify/extend my model to change the effect of the interaction. For instance, do I need to change the coefficient/fixed effect for each individual factor combination? Or is there a way to change the effect the whole interaction explains. Does this help to clarify the problem I am having? – MMed May 21 at 19:40