r - 如何修复线性混合模型中的奇异拟合?
问题描述
我正在运行一个线性混合模型,以查看任务的反应时间是否因受试者、实验条件或目标而异。但是,当我运行 lme 时,它会警告我关于奇异拟合。
我知道奇异拟合可能表示模型过拟合,但我不明白为什么我的模型与我拥有的数据量过拟合。
有关更多信息,该实验涉及受试者命名一系列图片,我们记录反应时间 (RT)。每个参与者看到所有图片(目标)并具有所有 4 个条件。每个条件有 440 个目标,其中 110 个目标。
我的第一个模型没有单一的拟合问题:
model1 = lmer(log(RTs300ms)~Condition+(1|Targets)+(1|Subject),data=beh_acc2)
REML criterion at convergence: -6030.481
Random effects:
Groups Name Std.Dev.
Targets (Intercept) 0.07918
Subject (Intercept) 0.13678
Residual 0.17972
Number of obs: 10985, groups: Targets, 110; Subject, 27
Fixed Effects:
(Intercept) ConditionTh ConditionUnTa ConditionUnTh
6.67960 -0.03549 -0.01475 -0.01700
但是从我的第二个模型开始,我开始遇到问题:
model2 = lmer(log(RTs300ms)~Condition+(1|Targets)+(1+Condition|Subject),data=beh_acc2)
REML criterion at convergence: -6037.6
Scaled residuals:
Min 1Q Median 3Q Max
-7.3985 -0.6456 -0.1593 0.4551 5.3105
Random effects:
Groups Name Variance Std.Dev. Corr
Targets (Intercept) 6.270e-03 0.079184
Subject (Intercept) 1.947e-02 0.139546
ConditionTh 2.482e-05 0.004982 0.58
ConditionUnTa 2.273e-04 0.015078 -0.50 0.41
ConditionUnTh 1.200e-04 0.010956 -0.64 0.26 0.99
Residual 3.226e-02 0.179597
Number of obs: 10985, groups: Targets, 110; Subject, 27
Fixed effects:
Estimate Std. Error t value
(Intercept) 6.679624 0.028108 237.641
ConditionTh -0.035441 0.004949 -7.162
ConditionUnTa -0.014807 0.005648 -2.621
ConditionUnTh -0.017071 0.005293 -3.225
Correlation of Fixed Effects:
(Intr) CndtnT CondtnUnT
ConditionTh 0.022
ConditinUnT -0.321 0.463
ConditnUnTh -0.321 0.471 0.597
convergence code: 0
boundary (singular) fit: see ?isSingular
理想情况下,我希望我的最终模型能够工作,但它是三个模型中最复杂的一个:
model3 = lmer(log(RTs300ms)~Condition+(1+Condition|Targets)+(1+Condition|Subject),data=beh_acc2)
REML criterion at convergence: -6068.3
Scaled residuals:
Min 1Q Median 3Q Max
-7.3684 -0.6393 -0.1575 0.4541 5.2834
Random effects:
Groups Name Variance Std.Dev. Corr
Targets (Intercept) 6.931e-03 0.083252
ConditionTh 1.008e-03 0.031748 -0.19
ConditionUnTa 1.419e-03 0.037676 -0.35 0.58
ConditionUnTh 1.727e-03 0.041553 -0.29 0.72 0.98
Subject (Intercept) 1.951e-02 0.139662
ConditionTh 2.575e-05 0.005074 0.57
ConditionUnTa 2.371e-04 0.015399 -0.50 0.43
ConditionUnTh 1.237e-04 0.011124 -0.63 0.28 0.99
Residual 3.187e-02 0.178527
Number of obs: 10985, groups: Targets, 110; Subject, 27
Fixed effects:
Estimate Std. Error t value
(Intercept) 6.679466 0.028234 236.574
ConditionTh -0.035074 0.005785 -6.063
ConditionUnTa -0.014748 0.006706 -2.199
ConditionUnTh -0.016823 0.006607 -2.546
Correlation of Fixed Effects:
(Intr) CndtnT CondtnUnT
ConditionTh -0.008
ConditinUnT -0.325 0.497
ConditnUnTh -0.306 0.548 0.722
convergence code: 0
boundary (singular) fit: see ?isSingular
我不确定如何解决我在模型 2 和模型 3 上遇到的奇异拟合问题。我已经阅读了一些我不熟悉的尝试贝叶斯模型的建议。
对此问题的任何建议或进一步建议将不胜感激!
解决方案
在您的第一个模型中,您不包含任何随机效应。但是,在返回错误的模型中,您现在包含了条件的随机效应。我的猜测是,您的条件影响实际上没有随机性。
您可以使用以下代码检查rePCA
函数: . 结果将提供一个表格,其中提供了随机效应结构中解释的方差比例。如果您有任何列可以解释接近 0 的方差比例,则这很可能是问题所在,并且会导致奇异拟合误差。确认这一点的另一种方法是,由参与者绘制每个条件的平均 RT,以创建所谓的“意大利面条图”。添加行并按参与者分组,以便您可以看到参与者对每个条件的 RT 变化。如果这些线都是平行的(或几乎平行),那么这表明您的条件影响可能没有随机性。lme4
summary(rePCA(model2))
推荐阅读
- android - 使用改造从 Android 和 Kotlin 将数据发布到 Google 表单
- python - Python - glob.glob 与 grep?
- r - 循环使用“If Else”语句来比较 R 中每天的 covid 增加
- java - 添加 orphanRemoval 属性后休眠异常
- r - sjPlot 使用 plot_models 函数重新排序估计
- flutter - 绘制图表后如何在 mp_chart 中启用/禁用网格线以防颤动
- react-native - 多个复选框在本机反应中相互覆盖
- python - 在 Python 代码中创建的模式/数据库未出现在 MySQL Workbench / MySQL Server 中
- java - 使用 EasyMock 或 Mockito 模拟 void 方法的 try catch 块并捕获异常
- c# - 如何将变量值从控制台应用程序传递到 C# 中的 Windows 窗体应用程序(Visual Studio)