GLMM固定效应与EMM不符:R与Jamovi结果差异原因咨询
问题:glmer固定效应估计与EMM、Jamovi结果存在差异的原因
我用R的lme4包中glmer函数拟合GLMM时,发现固定效应估计值与估计边际均值(EMM)相差较大,远小于预期。虽然知道固定效应和EMM可能有差异,但我设置的对比编码应该能让系数和EMM匹配,因此怀疑模型有问题。后来用Jamovi的GAMLj包拟合相同GLMM,系数符合预期且与EMM一致,想知道R中glmer结果差异的原因。
缩放对比编码下的GLMM输出结果
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] Family: inverse.gaussian ( identity ) Formula: latency ~ Con_shape * Cue + (1 + Con_shape | subject) Data: SN_P_PMT_match_data_rt Control: glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05)) AIC BIC logLik deviance df.resid 81984.2 82071.9 -40979.1 81958.2 6269 Scaled residuals: Min 1Q Median 3Q Max -3.1154 -0.6553 -0.1732 0.4628 4.9629 Random effects: Groups Name Variance Std.Dev. Corr subject (Intercept) 1.718e+03 41.44726 Con_shapeS vs. F 4.076e+03 63.84257 0.02 Con_shapeS vs. Str 4.896e+03 69.97401 0.18 -0.57 Residual 7.191e-05 0.00848 Number of obs: 6282, groups: subject, 42 Fixed effects: Estimate Std. Error t value Pr(>|z|) (Intercept) 796.370 14.132 56.354 < 2e-16 *** Con_shapeS vs. F 16.932 13.337 1.270 0.204 Con_shapeS vs. Str 95.656 15.344 6.234 4.55e-10 *** CueSad vs Neu -3.186 4.045 -0.788 0.431 Con_shapeS vs. F:CueSad vs Neu -7.216 10.676 -0.676 0.499 Con_shapeS vs. Str:CueSad vs Neu -1.303 11.727 -0.111 0.911 - Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Correlation of Fixed Effects: (Intr) C_Sv.F C_Sv.S CSdvsN C_vFvN Cn_shpSvs.F 0.088 Cn_shpSvs.S 0.028 -0.271 CueSadvsNeu -0.014 0.016 0.001 C_Sv.F:CSvN -0.096 -0.099 -0.055 0.019 C_Sv.S:CSvN 0.061 0.129 0.001 0.130 -0.548
估计边际均值(EMM)结果
Con_shape Cue emmean SE df asymp.LCL asymp.UCL self sad 728.7943 13.14691 Inf 703.0269 754.5618 friend sad 785.5311 13.31949 Inf 759.4254 811.6369 stranger sad 811.8101 13.48155 Inf 785.3868 838.2334 self neutral 733.1200 13.98504 Inf 705.7098 760.5302 friend neutral 781.1784 14.08376 Inf 753.5748 808.7821 stranger neutral 810.0302 14.53561 Inf 781.5409 838.5194
缩放对比编码设置
#Contrast coding - categorical variables (non-orthogonal)# contrasts(data$Con_shape) <- cbind("S vs. F" = c(-.5,.5,0), "S vs. Str" = c(-.5,0,.5)) S vs. F S vs. Str self -0.5 -0.5 friend 0.5 0.0 stranger 0.0 0.5 contrasts(data$Cue) <- cbind("Sad vs Neu" = c(-.5,.5)) Sad vs Neu sad -0.5 neutral 0.5
GLMM拟合代码
#Run glmer model <- glmer(latency ~ Con_shape*Cue + (1+ Con_shape|subject), data=data, family=inverse.gaussian(link="identity"), control=glmerControl (optimizer="bobyqa",optCtrl=list(maxfun=2e5)))
未缩放对比编码的尝试
我怀疑差异源于缩放对比编码,于是尝试未缩放编码(-1,1,0),此时效应显著性符合EMM可视化结果,但系数仍差异较大,还出现奇异拟合问题。
未缩放对比编码设置
contrasts(SN_P_PMT_data$Con_shape) <- cbind("S vs. F" = c(-1,1,0), "S vs. Str" = c(-1,0,1)) contrasts(SN_P_PMT_data$Cue) <- cbind("Sad vs Neu" = c(-1,1))
未缩放编码下的GLMM输出结果
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] Family: inverse.gaussian ( identity ) Formula: latency ~ 1 + Con_shape * Cue + (1 + Con_shape | subject) Data: SN_P_PMT_match_data_rt Control: glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05)) AIC BIC logLik deviance df.resid 82171.8 82259.5 -41072.9 82145.8 6269 Scaled residuals: Min 1Q Median 3Q Max -3.0716 -0.6663 -0.1754 0.4809 5.3294 Random effects: Groups Name Variance Std.Dev. Corr subject (Intercept) 1.734e+03 41.642073 Con_shapeS vs. F 5.894e+00 2.427823 1.00 Con_shapeS vs. Str 8.270e+02 28.758130 0.19 0.19 Residual 7.405e-05 0.008605 Number of obs: 6282, groups: subject, 42 Fixed effects: Estimate Std. Error t value Pr(>|z|) (Intercept) 786.600 13.085 60.113 < 2e-16 *** Con_shapeS vs. F 10.198 3.057 3.336 0.000851 *** Con_shapeS vs. Str 43.327 8.685 4.989 6.07e-07 *** CueSad vs Neu -1.804 2.118 -0.852 0.394476 Con_shapeS vs. F:CueSad vs Neu -1.788 2.972 -0.602 0.547312 Con_shapeS vs. Str:CueSad vs Neu -0.504 3.137 -0.161 0.872377 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Correlation of Fixed Effects: (Intr) C_Sv.F C_Sv.S CSdvsN C_vFvN Cn_shpSvs.F 0.220 Cn_shpSvs.S 0.127 -0.150 CueSadvsNeu -0.004 0.001 -0.007 C_Sv.F:CSvN 0.001 -0.009 0.013 0.009 C_Sv.S:CSvN 0.013 0.012 -0.006 0.150 -0.574 optimizer (bobyqa) convergence code: 0 (OK) boundary (singular) fit: see help('isSingular')
内容的提问来源于stack exchange,提问作者nalee_psych
相关产品推荐
相关产品推荐

