pitakakariki / simr

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

intercept only model #279

Closed JJ-Zhang-DS closed 2 months ago

JJ-Zhang-DS commented 3 months ago

Hello, simr looks like must have fix effect in the model.

If my model is intercept only, how to use simr to do the power analysis for the intercepts? Any suggestions?
My aim is to evaluate the sample sizes for random effect ( A, B, C and D) and determine whether it can detect the difference of 5% change of response variable (y, but in the model logit transformed).

model <- lmer(y_logit ~ 1 +  (1|A/B) +  (1|C/D) +  (1|E) +  (1|A:C),
                  data = data, REML = TRUE,  control = lmerControl(optimizer = 'bobyqa'))`

I am struggling on this. Thank you for any comments and suggestions.

pitakakariki commented 3 months ago

Intercept-only models are supported. It's possible you haven't specified a test, e.g. you could use rcompare(~(1|A) + (1|C/D) + (1|E) + (1|A:C)) to test significance of B.

JJ-Zhang-DS commented 3 months ago

Thank you for pointing out. Yes, it works for test factor B significance. Thank you for developing this package, really powerful.

But when I used powerCurve or powerSim for simulation-based power analysis. It asks me to specify what the fixed effect is.

model <- lmer(y_logit ~ 1 + (1|A/B) + (1|C/D) + (1|E) + (1|A:C), data = data, REML = TRUE, control = lmerControl(optimizer = 'bobyqa'))

powerCruve(model, along = "A")

the error message is.

Error in getDefaultXname(fit) : Couldn't automatically determine a default fixed effect for this model.

Thank you for helping.

pitakakariki commented 3 months ago

I can see how that error message might be confusing. The reason simr is trying to determine a default fixed effect is in order to choose a default test.

In your case you will need to specify a test explicitly (e.g. using test=rcompare(~(1|A)+(1|C/D)+(1|E)+ (1|A:C))).

JJ-Zhang-DS commented 2 months ago

Yes, it it. Thank you so much.