I am trying to use simR
to assess the power of simple GLMs to detect a particular effect size, given a set of pilot data. For example:
library(simr)
m1 = lm(y ~ x, data=simdata)
powerSim(m1)
I have no problem doing this when testing power to detect the "observed" effect size (i.e. whatever effect size is present in the pilot data), however I would like to specify an "expected" effect size. This is easy to do when dealing with LMER
models, using the fixef
function, for example:
m2 = lmer(y ~ x + (1|g), data=simdata)
fixef(m2)['x'] = <expected effect size>
Unfortunately this function does not work with aov()
or lm()
models. For example, using...
fixef(m1)['x'] = <expected effect size>
Results in the following error:
Error in UseMethod("fixef") :
no applicable method for 'fixef' applied to an object of class "c('aov', 'lm')"
Is there another method/package/workaround I can use to change effect sizes for aov()
or lm()
? I imagine this might entail "hacking" the summary output in a way that alters the F value (for aov()
) or coefficient value (for lm()
), however I haven't had any luck getting this to work.
Any advice would be greatly appreciated!
Edits
To clarify, by 'effect size' I mean the fixed effect coefficient generated by the model. So in the following output:
# Call:
# lm(formula = y ~ x, data = simdata)
# Coefficients:
# (Intercept) x
# 10.6734 -0.2398
The 'effect size' of x
is -0.2398. In the context of power analysis, changing the effect size should directly affect statistical power (because large effects require less power to detect, and vice-versa). For example, when using LMER, changing the effect size with fixef()
directly affects statistical power:
m2 = lmer(y ~ x + (1|g), data=simdata)
summary(powerSim(m2, progress=F, nsim=100)
# successes trials mean lower upper
# 1 96 100 0.96 0.9007428 0.9889955
Specify smaller effect size and re-assess power:
fixef(m2)['x'] = 0.05
summary(powerSim(m2, progress=F, nsim=100)
# successes trials mean lower upper
# 1 12 100 0.12 0.0635689 0.2002357
I have tried to modify the coefficient values for lm()
with the following approach:
m1 = lm(y ~ x, data=simdata)
m1$coefficients['x'] = <expected effect size>
However this has no effect on power, e.g. when changing the coefficient from 0.9 to 0.09
m1$coefficients['x'] = 0.9
summary(powerSim(m1, progress=F, nsim=100))
# successes trials mean lower upper
# 1 22 100 0.22 0.1433036 0.3139197
m1$coefficients['x'] = 0.09
summary(powerSim(m1, progress=F, nsim=100))
# successes trials mean lower upper
# 1 24 100 0.24 0.1602246 0.3357355
So I suppose a more accurate wording of my question would be: how do I change effect sizes for aov()
/lm()
models in a way that reflects changes in statistical power?