pitakakariki / simr

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

Many errors in simulation #272

Open Code3020 opened 4 months ago

Code3020 commented 4 months ago

Hi,

In the simulation I tried to run based on the model output of a model I tested, there were lots of errors - in 1000 simulations, there were 1000 errors.

Here are the codes: b = c(2.66,.11,-.65,-.03,.003,-.01) V1 <- 1.16
V2 <- matrix(c(1.16,0,0,.02),2) s <- .74

model1 <- makeLmer(pos_mean ~ sleep_quality * dep01 + Gender + Age + (1 + sleep_quality|ID), fixef=b, VarCorr=V2, sigma=s, data=df1) print(model1)

sim_p <- powerSim(model1, fixed("x","kr"), test = fcompare(~ sleep_quality * dep01), alpha=.05, nsim=1000)

print(sim_p)

Here is the output:

Power for predictor 'sleep_quality', (95% confidence interval):

0.00% ( 0.00, 0.37)

Test: Kenward Roger (package pbkrtest)

Based on 1000 simulations, (0 warnings, 1000 errors)

alpha = 0.05, nrow = NA

Time elapsed: 0 h 0 m 0 s

Many thanks for your help!

pitakakariki commented 4 months ago

You've passed powerSim two test specifications: fixed("x","kr") and test = fcompare(~ sleep_quality * dep01). Because you've named the second one, the first is being used as the sim argument which is causing the errors.

Code3020 commented 4 months ago

Thanks for your quick reply! I tried several single tests but I still got the same amount of errors and the same output.

Here are the ones I've tried: fixed("kr"), test = fixed("sleep_quality"), and test = fcompare(~ sleep_quality * dep01)

pitakakariki commented 4 months ago

You can access the error log using sim_p$errors.

Code3020 commented 4 months ago

All the error messages are the same

non-conformable arrays

pitakakariki commented 4 months ago

I don't have access to your df1 data frame, but that error often comes up if there is missing data.

Code3020 commented 3 months ago

Thanks for the hint!

Only one variable used in the formula had missing data so I subsetted the data by removing the rows containing these missing data. But now I got 1000 warnings and 1000 errors per 1000 simulations. The warnings are

boundary (singular) fit: see help('isSingular')

I guess that it's because I cluster-mean standardized the continuous independent variables.

Any suggestions or thoughts?

pitakakariki commented 2 months ago

If you are getting errors those are what you should focus on.