简体   繁体   English

simr:如何在 lm() 或 aov() 模型中指定预期效果大小?

[英]simr: how to specify expected effect size in lm() or aov() models?

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.在给定一组试验数据的情况下,我正在尝试使用simR来评估简单 GLM 检测特定效果大小的能力。 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 (ie 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:这在处理LMER模型时很容易做到,使用fixef function,例如:

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.不幸的是,这个 function 不适用于aov()lm()模型。 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() ?我可以使用另一种方法/包/解决方法来更改aov()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.我想这可能需要“破解”摘要 output 以改变 F 值(对于aov() )或系数值(对于lm() ),但是我没有任何运气让它工作。

Any advice would be greatly appreciated!任何建议将不胜感激!

Edits编辑

To clarify, by 'effect size' I mean the fixed effect coefficient generated by the model.澄清一下,“效应大小”是指由 model 生成的固定效应系数。 So in the following output:所以在下面的output中:

# Call:
# lm(formula = y ~ x, data = simdata)

# Coefficients:
# (Intercept)            x  
#     10.6734      -0.2398

The 'effect size' of x is -0.2398. x的“效果大小”为 -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:例如,在使用 LMER 时,使用fixef()更改效果大小会直接影响统计功效:

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:我尝试使用以下方法修改lm()的系数值:

m1 = lm(y ~ x, data=simdata)
m1$coefficients['x'] = <expected effect size>

However this has no effect on power, eg when changing the coefficient from 0.9 to 0.09但是,这对功率没有影响,例如,将系数从 0.9 更改为 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?所以我想我的问题的更准确的措辞是:如何以反映统计能力变化的方式更改aov() / lm()模型的效果大小?

You need to use:你需要使用:

coef(m1)['x'] = <expected effect size>

Instead of代替

fixef(m1)['x'] = <expected effect size>

The simplest solution to this is to avoid powerSim altogether and instead use pwr.f2.test from the package pwr.最简单的解决方案是完全避免使用powerSim ,而是使用pwr.f2.test pwr 中的 pwr.f2.test。 This provides a precise measure of power (as opposed to simulated power), given particular model parameters and the expected effect size.考虑到特定的 model 参数和预期效果大小,这提供了功率的精确测量(与模拟功率相反)。

m1 = lm(y ~ x, data=simdata)
anova(m1) 

# Analysis of Variance Table
# 
# Response: y
# Df  Sum Sq Mean Sq F value Pr(>F)
# x          1  14.231 14.2308  1.5943 0.2171
# Residuals 28 249.925  8.9259 

Use the df values from anova(m1) for the u and v arguments to pwr.f.test将 anova anova(m1)中的 df 值用于uv arguments 到pwr.f.test

pwr.f2.test(u=1, v=28, f2=<expected effect size>)

Thanks to @StupidWolf for figuring this out!感谢@StupidWolf 解决了这个问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM