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

lmer函数输出未显示分类变量估计值及显著性的问题求助

问题描述

我正在尝试使用以下脚本进行多水平回归分析:

M5 <- lmer(
  health_complaints ~ thinkbody_3cat_ref + IOTF3_ref + sex_ref + age_GMC + 
    fas_sum + thinkbody_3cat_ref*IOTF3_ref +(1|id2),
  data=HBSC2022_FlemishDataset_18_06_completecases,
  REML=FALSE
)
summary(M5)

所有类别均采用虚拟编码,变量IOTF3_ref和thinkbody_3cat_ref均为包含三个类别的分类变量。但在输出结果中,我无法看到不同类别间的估计值,这使得解释显著的交互效应变得困难:

Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's
  method [lmerModLmerTest]
Formula: health_complaints ~ thinkbody_3cat_ref + IOTF3_ref + sex_ref +  
    age_GMC + fas_sum + thinkbody_3cat_ref * IOTF3_ref + (1 |     id2)
   Data: HBSC2022_FlemishDataset_18_06_completecases

     AIC      BIC   logLik deviance df.resid 
 36405.8  36474.3 -18193.9  36387.8    14981 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.0264 -0.6266  0.1417  0.7446  2.5101 

Random effects:
 Groups   Name        Variance Std.Dev.
 id2      (Intercept) 0.01745  0.1321  
 Residual             0.65524  0.8095  
Number of obs: 14990, groups:  id2, 196

Fixed effects:
Estimate Std. Error         df t value
# (Intercept)                   3.968e+00  3.717e-02  5.185e+03 106.750
thinkbody_3cat_ref           -2.342e-01  9.115e-03  1.494e+04 -25.694
IOTF3_ref                    -2.491e-02  1.595e-02  1.493e+04  -1.562
sex_ref                      -4.731e-01  1.400e-02  1.442e+04 -33.780
age_GMC                      -3.744e-02  3.971e-03  6.149e+02  -9.429
fas_sum                       1.656e-02  3.544e-03  1.464e+04   4.674
thinkbody_3cat_ref:IOTF3_ref  2.926e-02  1.038e-02  1.491e+04   2.818
Pr(>|t|)    
# (Intercept)                   < 2e-16 ***
thinkbody_3cat_ref            < 2e-16 ***
IOTF3_ref                     0.11834    
sex_ref                       < 2e-16 ***
age_GMC                       < 2e-16 ***
fas_sum                      2.98e-06 ***
thinkbody_3cat_ref:IOTF3_ref  0.00484 ** 
# ---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) thn_3_ IOTF3_ sex_rf ag_GMC fas_sm
thnkbdy_3c_ -0.161                                   
IOTF3_ref   -0.133  0.238                            
sex_ref     -0.196 -0.163 -0.016                     
age_GMC      0.015 -0.019  0.046  0.034               
fas_sum     -0.903  0.031  0.019  0.046  0.065        
t_3_:IOTF3_  0.069 -0.486 -0.792  0.051 -0.044  0.020

已尝试更新lme4包,请问问题出在哪里?

解决方法
  • 检查并转换变量类型:输出中分类变量只显示单个系数,说明thinkbody_3cat_ref和IOTF3_ref可能被R识别为连续变量。先查看变量类型:
    str(HBSC2022_FlemishDataset_18_06_completecases)
    
    如果是数值型,转为因子:
    HBSC2022_FlemishDataset_18_06_completecases$thinkbody_3cat_ref <- factor(HBSC2022_FlemishDataset_18_06_completecases$thinkbody_3cat_ref)
    HBSC2022_FlemishDataset_18_06_completecases$IOTF3_ref <- factor(HBSC2022_FlemishDataset_18_06_completecases$IOTF3_ref)
    
  • 指定参考类别(可选):R默认将因子的第一个水平作为参考组,若需要自定义参考类别,用relevel():
    # 替换"参考类别名称"为你实际的参考组标签
    HBSC2022_FlemishDataset_18_06_completecases$thinkbody_3cat_ref <- relevel(HBSC2022_FlemishDataset_18_06_completecases$thinkbody_3cat_ref, ref = "参考类别名称")
    HBSC2022_FlemishDataset_18_06_completecases$IOTF3_ref <- relevel(HBSC2022_FlemishDataset_18_06_completecases$IOTF3_ref, ref = "参考类别名称")
    
  • 重新拟合模型:变量转为因子后,再次运行原lmer脚本,summary()会显示每个分类水平相对于参考组的系数,以及交互项的所有组合系数,方便解释交互效应。
  • 用emmeans直观展示交互效应:如果需要更清晰的交互效应结果,安装并使用emmeans包计算边际均值:
    install.packages("emmeans")
    library(emmeans)
    emmeans(M5, ~ thinkbody_3cat_ref * IOTF3_ref)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 16:07:01