Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't automatically determine a default fixed effect for this model #96

Open
rsiugzda opened this issue Jan 24, 2018 · 30 comments

Comments

Projects
None yet
7 participants
@rsiugzda
Copy link

commented Jan 24, 2018

library(simr)
fit <- lmer(oxy ~ 1 + (1|subject), data = df)
power <- powerSim(fit,nsim = 200)

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

any ideas what did go wrong?

@rsiugzda

This comment has been minimized.

Copy link
Author

commented Jan 24, 2018

I saw previous comments, i need to specify test= variable.

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Jan 24, 2018

Looks like I probably need to write a better error message :)

@rsiugzda

This comment has been minimized.

Copy link
Author

commented Jan 24, 2018

hi,
we tried in a different way:
fit <- lmer(oxy ~ (task|subject) + hemi, data = df)

and it gives the same error... help!!

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Jan 24, 2018

Have you specified a test= argument?

@rsiugzda

This comment has been minimized.

Copy link
Author

commented Jan 24, 2018

yes, and now we got another error:

power <- powerSim(lm_ABC, test = "task",nsim=200)
Warning message:
In observedPowerWarning(sim) :
This appears to be an "observed power" calculation​

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Jan 24, 2018

That's a warning rather than an error. It will go away if you specify the relevant parameter (e.g. with fixef<-)

@rsiugzda

This comment has been minimized.

Copy link
Author

commented Jan 24, 2018

sorry, could you be more specific, pls?
if I had this:
power <- powerSim(lm_ABC, test = "task", nsim=200)

how it can be changed? if in lm_ABC i have 3 fixed effects, but I want to test only one (task).

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Jan 25, 2018

You want something like: power <- powerSim(lm_ABC, test=fixed("task"), nsim=200)

You'll also want something like fixef(lm_ABC) <- ??? based on the size of the effect you'd like to be able to detect.

@rsiugzda

This comment has been minimized.

Copy link
Author

commented Jan 29, 2018

thanks we manage to make it work ;)

@Porites

This comment has been minimized.

Copy link

commented Jul 31, 2018

I also received this error message and below is my code for both the model and the powerCurve function. I realize that this is a more complex model than usual so perhaps powerCurve doesn't work at this level.

fit1<-lmer(Coral ~ WYear*Frames*Points + (1+WYear|Trans2) +(1|Year), data=Benthic)
library(simr)
fixef(fit1)["WYear"] <- -0.25  #Changes the size of the fixed effect for this variable
pc1 <- powerCurve(fit1, test=fixed("WYear"), nsim=50)

Oddly enough, powerSim seems to work with the same syntax, but I do receive a large number of errors. BTW, I am expecting very low power among factor levels due to the small differences among years.

## Power for predictor 'WYear', (95% confidence
## interval):===========================================================|
##       0.00% ( 0.00,  7.11)
## Test: Kenward Roger (package pbkrtest)
##    Effect size for WYear is -0.25
## Based on 50 simulations, (50 warnings, 50 errors)
## alpha = 0.05, nrow = 4320
## Time elapsed: 0 h 1 m 49 s 

Any suggestions on the syntax or what might be causing the error message? Thanks

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Jul 31, 2018

What does head(pc1$errors) say?

I suspect the problem is testing the main effect WYear when there are interactions. Perhaps you want test=fcompare(~ Frames*Points)?

@Porites

This comment has been minimized.

Copy link

commented Aug 1, 2018

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Aug 1, 2018

NB: it's better to respond on the gihub website, as things like colour get stripped if you try to reply to emails.

Looks like the problem's fairly simple - you haven't specified an along argument, and simr's very simple heuristics can't guess one when the first term has interactions.

Does it work if you specify along="WYear" (or whichever variable is appropriate in your case)?

@Porites

This comment has been minimized.

Copy link

commented Aug 1, 2018

The next iteration of the code is
pc1 <- powerCurve(fit1, extend(along="WYear"), nsim=25)
but this yielded the same error message.

I also tried
pc1 <- extend(fit1, along="WYear", n=20)
pc2 <- powerCurve(pc1, fixed("WYear"), nsim=25)
thinking that I have to sequence the steps. pc1 was generated, but the powerCurve function returned the same error message. Other suggestions?

@Porites

This comment has been minimized.

Copy link

commented Aug 1, 2018

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Aug 1, 2018

pc1 <- powerCurve(fit1, along="WYear", test=..., nsim=25)
@Porites

This comment has been minimized.

Copy link

commented Aug 1, 2018

@AbsoluteBeginners

This comment has been minimized.

Copy link

commented Aug 13, 2018

Peter thanks for all this info, it is very helpful.
I have a problem when running a model with 4 factors and interactions

fit <- lmer(model ~ A*B*C*D+ (1|Subject), data = Example)

When I am running the power analysis for any main effect or interaction, for example:

power <- powerSim(fit, test=fixed("A*B"), nsim = 200)

I receive this:

Power for predictor 'A*B', (95% confidence interval):
       0.00% ( 0.00,  1.83)
Test: Kenward Roger (package pbkrtest)
Based on 200 simulations, (0 warnings, 200 errors)
alpha = 0.05, nrow = 984
Time elapsed: 0 h 0 m 19 s
nb: result might be an observed power calculation

Note that the A*B interaction is significant (t=4,29)

What am I doing wrong?

AB

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Aug 14, 2018

Have a look at the names in summary(fit)$coef to see which strings are valid for fixed.

Note that you'll probably need to specify a method too, e.g.:

fixed("Asomething:Bsomething", "z")
@jrode11

This comment has been minimized.

Copy link

commented Sep 18, 2018

Hello,

I'm also getting the error: "Couldn't automatically determine a default fixed effect for this model."

I ran this mixed model from the lmerTest package:
mod2 <- lmer(anxiety ~ output*time*session + (time|id), data=long2.t, REML=TRUE) ,

where "output" "time" and "session" are all factor variables, and there is a random slope and intercept for time.

The powerSim function works:
works<-powerSim(mod2, test=fixed("outputspss:timepost:session2", method="t"), nsim=20)

But the powerCurve function doesn't work:
doesnt<-powerCurve(mod2, test=fixed("outputspss:timepost:session2", method="t"), nsim=20)

Sorry if I'm missing something here, but looking for some clarification.

Thank you!!
Jacob

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Sep 18, 2018

I think you just need to specify an along argument for powerCurve.

@jrode11

This comment has been minimized.

Copy link

commented Sep 18, 2018

That worked, thank you!

@MattK99

This comment has been minimized.

Copy link

commented Jan 15, 2019

G'day

I have a similar issue to the one above by AbsoluteBeginners.

Model<-lmer(log(Catch2)~B_A+C_I+B_A:C_I+(1 | id)+(1 | Period),data=AllData)

pow<-powerSim(fixef(Model), test=fixed("B_A:C_I", "anova"), nsim=100, alpha=0.1) ##https://www.rdocumentation.org/packages/simr/versions/1.0.4/topics/powerSim
Warning message:====|
In observedPowerWarning(sim) :
This appears to be an "observed power" calculation
pow
Power for predictor 'B_A:C_I', (95% confidence interval):
0.00% ( 0.00, 3.62)

Test: Type-I F-test

Based on 100 simulations, (0 warnings, 100 errors)
alpha = 0.1, nrow = NA

Time elapsed: 0 h 0 m 0 s

nb: result might be an observed power calculation

I tried summary(Model)
Which gave me the names B_ABefore:C_IImpacted

Using those made no difference. Any help would be appreciated.

Thanks
Matt

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Jan 15, 2019

Try:

pow <- powerSim(Model, ... 

not pow<-powerSim(fixef(Model), ....

@MattK99

This comment has been minimized.

Copy link

commented Jan 29, 2019

Thanks for that.

I haven't seen it noted anywhere, but are you aware of a conflict with the package stringr?
It results in the same problem I described above.

Thanks
Matt

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Jan 29, 2019

Thanks, yes I'm aware of the clash.

@benjaminwnelson

This comment has been minimized.

Copy link

commented Apr 16, 2019

Hello,
Thanks for all your helpful responses. I got the following error

Power for predictor 'group*Task', (95% confidence interval):
0.00% ( 0.00, 1.83)
Test: unknown test
Based on 200 simulations, (0 warnings, 200 errors)
alpha = 0.05, nrow = NA
Time elapsed: 0 h 0 m 12 s
nb: result might be an observed power calculation

Here is the model
hr_unadjusted <- lmer(HeartRate ~ quiet_hr_bl_centered + group*Task + (1 | subject_id), REML = "FALSE", contrasts = "TRUE", data = heart_rate_analyses)

Here is the power code
power <- powerSim(hr_unadjusted, test = fixed("group*Task"), nsim = 200) power

Any idea how to fix this? Thanks!

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Apr 17, 2019

Looks like the problem is your test specification. Maybe e.g. test=fixed("group:Task", "kr")?

@benjaminwnelson

This comment has been minimized.

Copy link

commented Apr 21, 2019

This gives the following error message

Warning message:===========================================================================================| In observedPowerWarning(sim) : This appears to be an "observed power" calculation

Power for predictor 'group:Task', (95% confidence interval):
0.00% ( 0.00, 1.83)

Test: Kenward Roger (package pbkrtest)

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

Any ideas?

@pitakakariki

This comment has been minimized.

Copy link
Owner

commented Apr 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.