使用R包simr进行混合效应模型功效分析时遭遇‘object is not a matrix’错误的技术求助
混合效应模型功效分析(simr包)求助
我构建了如下混合效应模型:
ModelPower <- lmer(DV ~ GroupAbstract * Condition_Cat_Abs + (1|Participant) + (1 + GroupAbstract|Stimulus), data = Dataset)
模型输出结果
随机效应:
| Groups | Name | Variance | Std.Dev. | Corr |
|---|---|---|---|---|
| Participant | (Intercept) | 377.401 | 19.427 | |
| Stimulus | (Intercept) | 91.902 | 9.587 | |
| Stimulus | GroupAbstractOutgroup | 2.003 | 1.415 | -0.40 |
| Residual | 338.927 | 18.410 |
观测数:16512,分组:Participant(344组);Stimulus(32组)
固定效应:
| Term | Estimate | Std. Error | df | t value | Pr(> | t | ) |
|---|---|---|---|---|---|---|---|
| (Intercept) | 65.8962 | 2.0239 | 59.6906 | 32.559 | < 0.0000000000000002 *** | ||
| GroupAbstractOutgroup | -0.9287 | 0.5561 | 129.9242 | -1.670 | 0.0973 . | ||
| Condition_Cat_AbsSecondOrderIn | -2.2584 | 0.4963 | 16103.9277 | -4.550 | 0.00000539 *** | ||
| Condition_Cat_AbsSecondOrderOut | -7.0821 | 0.4963 | 16103.9277 | -14.270 | < 0.0000000000000002 *** | ||
| GroupAbstractOutgroup:Condition_Cat_AbsSecondOrderIn | -3.0229 | 0.7019 | 16103.9277 | -4.307 | 0.00001665 *** | ||
| GroupAbstractOutgroup:Condition_Cat_AbsSecondOrderOut | 7.8765 | 0.7019 | 16103.9277 | 11.222 | < 0.0000000000000002 *** |
问题描述
我重点关注交互项GroupAbstractOutgroup:Condition_Cat_AbsSecondOrderIn,想使用simr包估计能检测到至少**-2效应量**的样本量。原模型中该交互项的斜率是-3.02,所以我用下面的代码修改了模型参数:
ModelPower@beta[names(fixef(ModelPower)) %in% "GroupAbstractOutgroup:Condition_Cat_AbsSecondOrderIn"] <- -2
但不管怎么设置powerSim函数(示例如下),得到的功效始终是0%。而且运行lastResult()$errors时,会出现错误提示:object is not a matrix。我理解这个错误的字面意思,但就算把原始数据框和固定效应表都转换成矩阵,错误还是存在。我搞不清这个错误到底指向哪个对象,也没法得到有效的功效分析结果,恳请大家帮忙解决!
尝试过的powerSim调用示例
powerSim(ModelPower, test=fixed("GroupAbstract", "anova"), nsim=10, seed=1)
powerSim(ModelPower, test=fixed("GroupAbstractOutgroup:Condition_Cat_AbsSecondOrderIn", "anova"), nsim=10, seed=1)
内容的提问来源于stack exchange,提问作者Joseph K.
相关产品推荐
相关产品推荐

