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

使用simr进行功效分析时遇'non-conformable arguments'错误求助

问题:使用simr进行功效分析时出现“non-conformable arguments”错误

我在用simr做功效分析时,一直碰到“non-conformable arguments”错误。已经确认数据里没有缺失值(NA),但找不到问题根源。后来发现当前拟合的lmer模型是Large lmerModLmerTest类型,而之前能正常配合simr运行的模型是Formal class lmerModLmerTest类型。

我通过过滤数据(代码如下)把模型类型转换成了lmerModLmerTest:

data=bsmu[bsmu$ACC == 1 & bsmu$English_comp >= .60 & bsmu$Span_comp >= .60,]

现在虽然能运行simr相关函数,但执行powerSim时全部报错。以下是模型代码、simr代码和完整报错信息:

> summary(rtlmer <- lmer(RT ~Language*DOB + (1|Probe) + (1|Story_order) + (1|Subject), data=bsmu[bsmu$ACC == 1 & bsmu$English_comp >= .60 & bsmu$Span_comp >= .60,]))
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: RT ~ Language * DOB + (1 | Probe) + (1 | Story_order) + (1 |      Subject)
   Data: bsmu[bsmu$ACC == 1 & bsmu$English_comp >= 0.6 & bsmu$Span_comp >=      0.6, ]

REML criterion at convergence: 125294.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.3849 -0.4550 -0.1815  0.1684 13.8652 

Random effects:
 Groups      Name        Variance Std.Dev.
 Probe       (Intercept)  194742   441.3  
 Subject     (Intercept)  449359   670.3  
 Story_order (Intercept)  101385   318.4  
 Residual                2700600  1643.4  
Number of obs: 7069, groups:  Probe, 380; Subject, 94; Story_order, 8

Fixed effects:
                    Estimate Std. Error       df t value Pr(>|t|)    
(Intercept)         2620.321    139.702   14.935  18.756  8.6e-12 ***
LanguageSpanish      218.495     56.796  643.690   3.847 0.000131 ***
DOB                   -7.895      8.142  105.927  -0.970 0.334393    
LanguageSpanish:DOB  -10.074      4.294 6831.693  -2.346 0.019007 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) LnggSp DOB   
LangugSpnsh -0.201              
DOB         -0.138  0.037       
LnggSpn:DOB  0.028 -0.146 -0.266
> print(PS_RT <- powerSim(rtlmer, nsim=10, test = fcompare(RT ~ Language*DOB)))
Power for model comparison, (95% confidence interval):======================================================================================================|
       0.00% ( 0.00, 30.85)

Test: Likelihood ratio
      Comparison to RT ~ Language * DOB + [re]

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

Time elapsed: 0 h 0 m 0 s

nb: result might be an observed power calculation
Warning message:
In observedPowerWarning(sim) :
  This appears to be an "observed power" calculation
> lastResult()$errors
        stage index                   message
1  Simulating     1 non-conformable arguments
2  Simulating     2 non-conformable arguments
3  Simulating     3 non-conformable arguments
4  Simulating     4 non-conformable arguments
5  Simulating     5 non-conformable arguments
6  Simulating     6 non-conformable arguments
7  Simulating     7 non-conformable arguments
8  Simulating     8 non-conformable arguments
9  Simulating     9 non-conformable arguments
10 Simulating    10 non-conformable arguments

排查与解决思路
  1. 模型类型兼容性问题
    Large lmerModLmerTest是lmerTest包针对大数据集自动生成的简化类,simr对这类模型的支持存在已知bug。你通过过滤数据转回标准lmerModLmerTest是正确方向,但报错说明还有其他维度匹配问题。

  2. “non-conformable arguments”的核心原因
    这个错误本质是矩阵运算维度不匹配,在simr模拟中,大概率和以下两点有关:

  • Story_order仅8个分组,数量过少,simr生成随机效应时可能无法构建符合要求的矩阵。
  • 固定效应交互项LanguageSpanish:DOB的变量类型或设计矩阵存在异常,导致模拟数据的维度和原模型不匹配。
  1. 具体修复步骤
  • 临时移除小样本随机效应:先去掉(1|Story_order)项,测试powerSim是否能正常运行,确认是否是该分组导致的问题。
  • 显式指定模型类:用lmerTest::lmer拟合模型,强制生成标准lmerModLmerTest对象,避免自动切换到大模型类:
    library(lmerTest)
    rtlmer <- lmer(RT ~ Language*DOB + (1|Probe) + (1|Story_order) + (1|Subject), 
                   data=bsmu[bsmu$ACC == 1 & bsmu$English_comp >= .60 & bsmu$Span_comp >= .60,],
                   REML = TRUE)
    
  • 修正fcompare的检验逻辑:你的当前写法可能导致simr误判对比模型,显式指定原模型和简化模型(比如针对交互项检验):
    # 检验Language*DOB交互项的功效
    test = fcompare(~ . - Language:DOB)
    PS_RT <- powerSim(rtlmer, nsim=10, test = test)
    
  • 更新依赖包:旧版本simr对lmerModLmerTest支持不完善,运行以下命令更新到最新版:
    update.packages(c("simr", "lmerTest", "lme4"))
    
  1. 验证模拟数据维度
    手动模拟一次数据,检查生成的数据集和原数据维度是否一致:
sim_data <- simulate(rtlmer)
# 对比行数和列数
dim(sim_data)
dim(bsmu[bsmu$ACC == 1 & bsmu$English_comp >= .60 & bsmu$Span_comp >= .60,])

如果维度不一致,说明模型的变量类型或公式存在问题,需要进一步检查Language、DOB等变量的编码方式。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 17:17:56