You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

混合模型因子设计功效模拟异常:powerSim结果为0%的排查

混合模型因子设计的功效模拟问题

问题背景

我正在为含两个因子编码变量(用于检验线性或二次效应)的混合模型计算固定效应功效,但运行powerSim后结果显示0%,尽管效应本身显著。使用原始变量建模时无此问题。

代码及输出

建模代码

freq <- as.factor(b1$f)
loc <- as.factor(b1$l)
cp <- contr.poly 
m2 <- lmer(scr~ freq+loc+freq:loc+(1|id), data=b1, contrasts=list(freq=cp))
summary(m2)

模型输出

Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: scr ~ freq + loc + freq:loc + (1 | id)
   Data: b1

REML criterion at convergence: 3672.8

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.3274 -0.4298 -0.0761  0.2343  6.0536 

Random effects:
 Groups   Name        Variance Std.Dev.
 id       (Intercept) 0.00242  0.04919 
 Residual             0.19264  0.43891 
Number of obs: 3008, groups:  id, 44

Fixed effects:
              Estimate Std. Error         df t value Pr(&gt;|t|)    
(Intercept) -8.180e-03  1.093e-02  4.073e+01  -0.748   0.4585    
freq.L       8.393e-02  1.962e-02  2.951e+03   4.277 1.95e-05 ***
freq.Q       1.789e-02  1.961e-02  2.952e+03   0.912   0.3617    
freq.C      -1.788e-03  1.961e-02  2.952e+03  -0.091   0.9273    
freq^4      -1.207e-02  1.960e-02  2.951e+03  -0.616   0.5381    
freq^5      -4.180e-02  1.959e-02  2.951e+03  -2.134   0.0329 *  
loc1         2.257e-03  8.003e-03  2.952e+03   0.282   0.7779    
freq.L:loc1 -3.800e-02  1.962e-02  2.952e+03  -1.937   0.0529 .  
freq.Q:loc1  3.671e-02  1.961e-02  2.951e+03   1.872   0.0613 .  
freq.C:loc1 -6.637e-03  1.961e-02  2.951e+03  -0.339   0.7350    
freq^4:loc1  3.510e-02  1.960e-02  2.952e+03   1.791   0.0734 .  
freq^5:loc1 -2.724e-02  1.959e-02  2.952e+03  -1.391   0.1644    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

功效模拟代码及输出

powerSim(m2,test=fixed("freq"), nsim=100)
Power for predictor 'freq', (95% confidence interval):==============================================|
       0.00% ( 0.00,  3.62)

Test: unknown test

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

Time elapsed: 0 h 0 m 1 s

nb: result might be an observed power calculation

问题

请问是否可以对混合模型的因子设计进行功效模拟?


解答

原因

simr包的powerSim无法直接识别多项式对比编码下fixed("freq")的联合检验——此时freq被拆分成了多个正交分量(线性、二次、三次等),模拟时找不到对应的整体检验统计量,导致100次模拟全部报错,功效结果为0%。

可行的解决方法

  1. 检验单个效应分量:如果只关注特定的效应(比如线性效应freq.L),直接指定该分量即可:
powerSim(m2, test = fixed("freq.L"), nsim = 100)
  1. 检验整个freq因子的联合效应:通过模型比较来实现联合检验,使用fcompare构建原模型与去掉freq所有项的模型之间的对比:
powerSim(m2, test = fcompare(m2, ~ . - freq), nsim = 100)
  1. 额外注意:确保使用最新版本的simr包,旧版本对复杂对比编码的支持有限;若模拟时遇到模型收敛问题,可以通过control = lmerControl(...)调整lmer的收敛参数。

内容的提问来源于stack exchange,提问作者MiO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 19:25:27