pitakakariki / simr

Power Analysis of Generalised Linear Mixed Models by Simulation
69 stars 19 forks source link

Power Analysis for a Model with Multiple Fixed Effects #166

Open l14864011 opened 4 years ago

l14864011 commented 4 years ago

Hi there,

I built a linear mixed model using data already collected like below. My goal is trying to confirm that the sample size is appropriate to obtain enough power for my model.

fit <- lmer(response_time ~A*B*C+
           (A|user_id) + (1|word_list), REML=TRUE, na.action=na.omit, data = mydata)

Is there a way to calculate the power for the model above with all three fixed effects? (but not just for a specific fixed effect, e.g. A). All the codes that I've seen online using simr are only calculating power for one fixed effect.

If there is no way, do I have to get powers for the three fixed effects separately doing something like this:

sim_a <- powerSim(fit, nsim=100, test = fcompare(y~b*c))
sim_a

sim_b <- powerSim(fit, nsim=100, test = fcompare(y~a*c))
sim_b

sim_c <- powerSim(fit, nsim=100, test = fcompare(y~a*b))
sim_c

So if all the powers above are > 80%, it would mean that my sample size is appropriate?

Any help is greatly appreciated!

pitakakariki commented 4 years ago

simr doesn't have the ability to run multiple tests in the same run yet, so you will need to do separate simulations for now. What you've done looks sensible.

Power isn't an intrinsic property of a model — it only makes sense in the context of a specific test. It would be possible for example for a model to have enough power to find a significant effect for A but insufficient power for B.

As an aside I would recommend removing NA values before fitting the model. simr is not well tested with missing data and there are some known bugs outstanding.

l14864011 commented 4 years ago

It makes sense now. Thank you so much for dedicating your time to help people out.