从R中的多层次模型绘制多层次模型分类x连续交互

时间:2019-01-30 20:21:05

标签: r lme4 multilevel-analysis

我已经使用lmer估计了R中的多级模型。我的虚拟变量之一和连续变量之间存在显着的相互作用。虚拟变量实际上代表一个三级因子。有没有办法我可以直观地绘制此交互关系,以便表示原始变量的所有三个级别?

model <- lmer (
dPrime ~ 1 + 
targetRaceDummy2Black + targetRaceDummy2Asian + 
targetRaceSelfStatusLLC + 
pRaceDummy2Asian + pRaceDummy2Black + 
targetRaceDummy2Black*pRaceDummy2Asian + 
targetRaceDummy2Asian*pRaceDummy2Asian + 
targetRaceDummy2Black*pRaceDummy2Black + 
targetRaceDummy2Asian*pRaceDummy2Black + 
stigConscIndexLLC + 
grpIdIndexLLC + 
targetRaceContactLLC + 
sdoIndexLLC + 
stigConscIndexLLC*pRaceDummy2Asian + stigConscIndexLLC*pRaceDummy2Black 
+ 
sdoIndexLLC*targetRaceDummy2Asian + sdoIndexLLC*targetRaceDummy2Black + 
(1 + targetRaceDummy2Black + 
targetRaceDummy2Asian + 
targetRaceSelfStatusLLC + 
targetRaceContactLLC || ResponseID), 
data = analysisDataSubset, 
REML = FALSE, 
na.action = na.omit)

固定效果的摘要如下:

  Fixed effects:
                                          Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)                              6.294e-01  1.433e-01  3.006e+02   4.390 1.57e-05 ***
targetRaceDummy2Black1                  -2.329e-01  7.243e-02  2.803e+02  -3.215  0.00146 ** 
targetRaceDummy2Asian1                  -2.294e-01  7.324e-02  3.545e+02  -3.132  0.00188 ** 
targetRaceSelfStatusLLC                  1.655e-03  7.170e-03  5.291e+02   0.231  0.81749    
pRaceDummy2Asian                         2.755e-01  1.531e-01  2.528e+02   1.799  0.07315 .  
pRaceDummy2Black                        -4.547e-02  1.637e-01  2.412e+02  -0.278  0.78146    
stigConscIndexLLC                        7.894e-02  3.580e-02  1.944e+02   2.205  0.02861 *  
grpIdIndexLLC                           -3.957e-02  1.789e-02  2.025e+02  -2.212  0.02811 *  
targetRaceContactLLC                     1.568e-03  1.017e-02  3.909e+02   0.154  0.87761    
sdoIndexLLC                             -7.264e-02  2.347e-02  2.995e+02  -3.095  0.00215 ** 
targetRaceDummy2Black1:pRaceDummy2Asian -8.389e-02  7.551e-02  2.232e+02  -1.111  0.26777    
targetRaceDummy2Asian1:pRaceDummy2Asian  1.354e-01  8.429e-02  3.369e+02   1.606  0.10916    
targetRaceDummy2Black1:pRaceDummy2Black  1.972e-01  8.797e-02  2.672e+02   2.242  0.02579 *  
targetRaceDummy2Asian1:pRaceDummy2Black  5.433e-02  7.930e-02  3.105e+02   0.685  0.49377    
pRaceDummy2Asian:stigConscIndexLLC      -1.053e-01  4.869e-02  1.979e+02  -2.162  0.03179 *  
pRaceDummy2Black:stigConscIndexLLC      -4.983e-04  4.838e-02  2.014e+02  -0.010  0.99179    
targetRaceDummy2Asian1:sdoIndexLLC       3.931e-02  2.241e-02  2.969e+02   1.754  0.08044 .  
targetRaceDummy2Black1:sdoIndexLLC       2.826e-02  2.178e-02  2.183e+02   1.298  0.19578    

我可以使用以下代码成功绘制pRaceDummy2Asian:stigConscIndexLLC交互:

ef1 <- effect(term="pRaceDummy2Asian*stigConscIndexLLC", xlevels= list(pRaceDummy2Asian=c(0, 1)), mod=addControlsInterX)
ef1

efdata1<-as.data.frame(ef1) #convert the effects list to a data frame
efdata1 #print effects data frame


efdata1$pRaceDummy2Asian<-as.factor(efdata1$pRaceDummy2Asian)

ggplot(efdata1, aes(x=stigConscIndexLLC, y=fit, color=pRaceDummy2Asian,group=pRaceDummy2Asian)) + 
    geom_point() + 
    geom_line(size=1.2) +
    geom_ribbon(aes(ymin=fit-se, ymax=fit+se, fill=pRaceDummy2Asian),alpha=0.3) + 
    labs(title = "Title", x= "Stigma consciousness", y="Recognition", color="0=white/black 1=asian", fill="0=white/black 1=asian") + theme_classic() + theme(text=element_text(size=20))

enter image description here

有没有办法绘制出显示所有三个种族水平的模型?

0 个答案:

没有答案