pitakakariki / simr

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

PowerCurve does not produce a curve #164

Closed ediachek closed 4 years ago

ediachek commented 4 years ago

Hi,

I am testing complex fixed effects on the data that has already been collected. Here is the model:

_m <- glmer(response.numeric ~ 1+ memory + disfluency + planning.hypothesis + pauses.ums + (1|participantid) + (1|item), data=data,family=binomial)

Now, I'd like to do a replication study and I want to figure out the sample size. I am using the powerCurve function. The code is below:

_c.memory <- powerCurve(m, along = "participantid", test=fixed("memory"), nsim=100)

Unfortunately, what I get is the following:

Screen Shot 2019-09-13 at 5 27 43 PM

I have been trying to extend my data but I get the following error:

_> m_ext_subj <- extend(m, along="participantid", n=20) Error in levels<-.factor(*tmp*, value = values) : number of levels differs

I'd appreciate any suggestions on how to fix this!

pitakakariki commented 4 years ago

I think that might be a bug in extend.

Does changing participant_id from a factor to a character (or numeric) vector fix this?

ediachek commented 4 years ago

Hi,

I changed participant_id to a numeric vector and this is what I am getting:

Screen Shot 2019-09-17 at 10 01 36 AM

I’m not sure why it’s only showing me 20 participants (I have 102 in my data). I’m new to R, so it’s quite possible that there’s an error in my code. Here are the commands that I’m using:

data$participant_id <- as.numeric(data$participant_id) m_ext_subj <- extend(m, along="participant_id", n=20) c.memory <- powerCurve(m_ext_subj, along = "participant_id", test=fixed("memory"), nsim=2)

I’d appreciate any help!

pitakakariki commented 4 years ago

It's better to comment on github rather than reply to the notification emails. Looks like it scrubbed an attachment?

ediachek commented 4 years ago

Just updated the comment!

pitakakariki commented 4 years ago

The argument n=20 "extends" the dataset to 20 participants (extend is a bit of a misnomer in this case). I'm not sure why you'd want to extend when your power is already high, but if you do e.g. n=122 will add 20 participants (you might need to check with getData afterwards though, extend is fairly simpe and can unbalance your data).

Have a look at c.memory$warnings and c.memory$errors to see if any problems were logged during the simulations.

Note that if you have a large number of observations per participant you might still have high power with fewer participants.

ediachek commented 4 years ago

I'm trying to replicate the experiment and I'd like to see what the sample size should be to get the same effect size for multiple fixed effects.

Yes, it looks like I have high power even with as few as 30 people.

ediachek commented 4 years ago

Ok, I have managed to resolve the issue by: i) changing "participant_id" from a factor to numeric; ii) testing the fixed effect that is smaller than the original one; iii) increasing the number of simulations. Attaching the power curve for 100 simulations.

planning hypothesis_nsims100

Thank you for your help!