pitakakariki / simr

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

Zero power in multilevel models? #215

Open lesegura opened 3 years ago

lesegura commented 3 years ago

Hi,

I can't find the answer to why I get 0 power using powerSim on a multilevel model.

This is my model

model.of.interest.1 <- glmer(Y ~ exposure * var2 + (1 | group), offset = log(POP), 
                           data = df, family = poison)

doTest(model.of.interest.1, fcompare('~exposure + var2', "lr")) p-value for model comparison: 0.1283276

Test: Likelihood ratio Comparison to ~exposure + var2 + [re]

fixef(model.of.interest.1) (Intercept) exposureYes var2 exposureYes:var2 -9.631803098 0.036445561 0.001069716 -0.002806280

fixef(model.of.interest.1)['exposureYes:var2'] <- 0.1823216

powerSim(model.of.interest.1, fcompare('~exposureYes:month_new', 'lr'), nsim = 10)

Power for model comparison, (95% confidence interval):==================================================================================| 0.00% ( 0.00, 30.85)

Test: Likelihood ratio Comparison to ~exposure * month_new + [re]

Based on 10 simulations, (0 warnings, 10 errors) alpha = 0.05, nrow = NA

Time elapsed: 0 h 1 m 31 s

lasResult()$errors

    stage index                                                                                       message

1 Simulating 1 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 2 Simulating 2 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 3 Simulating 3 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 4 Simulating 4 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 5 Simulating 5 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 6 Simulating 6 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 7 Simulating 7 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 8 Simulating 8 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 9 Simulating 9 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE 10 Simulating 10 NAs are not allowed in prediction data for grouping variables unless allow.new.levels is TRUE

Not sure how to fix this and get power for this complex model with an interaction and why I get this error.

pitakakariki commented 3 years ago

Check your two fcompares carefully. The second one doesn't make sense to me, were they meant to be the same?

lesegura commented 3 years ago

Thank you Peter, so yes you are right there were two problems. The compare was wrong and my data had missing.

fixef(model.of.interest.1)['exposureYes:month_new'] <- 0.2776317

powerSim(model.of.interest.1, test = fixed('exposureYes:month_new', 'z'), nsim = 10)

These worked.

So, those two things were messing me up. I was able to run the power analysis, but it takes a loooooong time. I guess because of the interaction in the multilevel model and the size of my dataset(1.3 million).

For some odd reason they run very slow even if I run them in an AWS server with 8 GPUs. Any idea on why?