pitakakariki / simr

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

powerSim error: "wrong number of contrast matrix rows" #148

Closed carolywang closed 4 years ago

carolywang commented 5 years ago

Hi Peter,

Thanks very much for your simr package.

I have been trying the powerSim function with the following scripts:

     powerWord <- powerSim(modelWord, test=fixed("targetWordFactor"), nsim = 20)
     powerWord

But it gives me the following results with errors:

 Power for predictor 'targetWordFactor', (95% confidence interval):
   0.00% ( 0.00, 16.84)

 Test: Likelihood ratio

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

 Time elapsed: 0 h 0 m 4 s

 nb: result might be an observed power calculation

I checked that all of the 20 errors are "wrong number of contrast matrix rows". This is strange because the contrasts I used with the "targetWordFactor" did not cause any problem for the lmer model (modelWord). It is a 3-level default treatment contrast that looks something like this:

         b c
       a 0 0  
       b 1 0 
       c 0 1  

Could you tell me how I can fix this error please?

Many thanks!! Carol

pitakakariki commented 5 years ago

Does the test work outside of simr?

drop1(modelWord, test="Chisq")
carolywang commented 5 years ago

Seems like it works, here is the result to drop1(modelWord, ``test="Chisq"):

screenshot 2019-01-29 at 21 42 26

pitakakariki commented 5 years ago

I'll need more information then, for example the specification of modelWord.

carolywang commented 5 years ago

Thanks for your help! Here is the model (logRTmodelWord is what I used in my original script): logRTmodelWord <- lmer(logRT ~ 1 + targetWordFactor + (1+targetWordFactor|subject) + (1+targetWordFactor|item), data = pauseDetValidNoFillersExcluded, REML=FALSE)

pitakakariki commented 5 years ago

I'll need the bit where you specify the contrasts too.

carolywang commented 5 years ago

The contrasts: pauseDetValidNoFillersExcluded$targetWordFactor <- factor(pauseDetValidNoFillersExcluded$targetWordFactor, c("W","WW","NW")) contrasts(pauseDetValidNoFillersExcluded$targetWordFactor)

pitakakariki commented 5 years ago

So you're not actually manually setting the contrasts?

carolywang commented 5 years ago

Not for treatment contrasts I think, as these are actually the default setting in R.

carolywang commented 5 years ago

So does this mean that the error message is not directly related to contrast?

pitakakariki commented 5 years ago

It's not something I've seen before, could have something to do with the singular fit.

pitakakariki commented 5 years ago

I can't replicate the problem. Check that you've got the latest lme4 and simr, and if it still doesn't work you'll need to send me the dataset and script.

carolywang commented 5 years ago

Hi Peter,

Thank you very much for offering to help. I have checked that I have been using the latest lme4 and simr. Attached please find my script and dataset. You can run the script directly after setting up setwd.

Apart from the powerSim function that produces the error “wrong number of contrasts matrix row”, powerCurve function does not work with my data either and the error shows that "object 'logRT' not found”.

I would sincerely appreciate your help on this.

Many thanks, Carol

On 30 Jan 2019, at 01:18, Peter Green notifications@github.com wrote:

I can't replicate the problem. Check that you've got the latest lme4 and simr, and if it still doesn't work you'll need to send me the dataset and script.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pitakakariki/simr/issues/148#issuecomment-458773419, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ6En-36EWfrYA9ovBgZFPNtJQmoBjmKks5vIPL0gaJpZM4aY9H2.

pitakakariki commented 5 years ago

You can't attach files when replying to Github threads, you'll need to email the files to the address listed on CRAN.

carolywang commented 5 years ago

Hi Peter, I just forwarded the files to your simr gmail. Thanks very much!

pitakakariki commented 5 years ago

It will take me a while to track down the actual problem, but I think it's something to do with missing values.

In the meantime, you can probably work around this by removing incomplete rows from your data before fitting the model.

carolywang commented 5 years ago

Removing missing data did solve the problem! Thanks a lot for your help!