pitakakariki / simr

Power Analysis of Generalised Linear Mixed Models by Simulation
70 stars 20 forks source link

powerSim for models with interaction terms? #90

Open xl624 opened 7 years ago

xl624 commented 7 years ago

Hi,

powerSim doesn't seem to work for me when the model includes interaction terms. lastResult()$errors gives me "Test did not return a p-value", but I do see p-values when I summary the model. I used lmer with lmerTest installed. Any suggestions? Thanks.

pitakakariki commented 7 years ago

What does your model look like, and your powerSim call?

xl624 commented 7 years ago

a = lmer(rating~letterCondtrustheartCond+(1|SID)+(1|faceID),data=d) powerSim(a,test = fixed("letterCond",method="z"),nsim=10)

pitakakariki commented 7 years ago

Is letterCond a factor? If so you'll need to specify something like fixed("letterCond:A", "z").

Note that you probably shouldn't be testing main effects when there's an interaction. Something like fcompare(~heartCond) might make more sense.

xl624 commented 7 years ago

Doing fixed("letterCond:A", "z") didn't solve the problem... Am I getting something wrong here? But seems I can just leave the cond variable as a numerical one and the errors no longer pop out - I'm not sure if the variable type will change the powerSim result though? Thanks!

pitakakariki commented 7 years ago

What does the output of summary look like?

mayabraun commented 4 years ago

Is letterCond a factor? If so you'll need to specify something like fixed("letterCond:A", "z").

Note that you probably shouldn't be testing main effects when there's an interaction. Something like fcompare(~heartCond) might make more sense.

I'm having a hard time understanding when it makes sense to use fixed and when fcompare.

I have two main effects (that are factors) and their interaction. I used fcompare (compared the full model to a model with just the main effects) My code is

model <- lmer(OnlineMeasure ~ Group * Block + (1|ID) , data = online, REML=T)
powerSim(model, fcompare(~Group+Block), nsim=30)

This works decently (I get low power, and explored bigger sample sizes with the extend function). I originally intended to use fixed

powerSim(model, fixed("Group|Block", "z"), nsim = 30)

But I keep getting 0 for my power here! Am I right to use fcompare or should I try to figure out what I did wrong with fixed?