This file provides a supplemental example to illustrate the Contextual Effects Model (CEM), Multilevel Linear Model (MLM), and Panel Linear Model (PLM).

Setup

## Load R packages

# Core ----
library(bruceR)  # version >= 0.8.12
library(lmerTest)
library(plm)
library(interactions)

# Others ----
library(car)
library(sjPlot)

Data Simulation

set.seed(1)

N = 122  # Clusters
M = 12   # Group size

center = function(x) x - mean(x)

data = data.table(
  Clus = as.factor(rep(1:N, M)),
  CaseID = as.factor(rep(1:M, each=N))
)

data[, Xb := 1 + rep(center(rnorm(N)), M)]
data[, W := 2 + rep(center(rnorm(N)), M)]
data[, Wcgm := center(W)]
data[, Xw := 2 * scale(rnorm(M)), keyby=Clus]
data[, X := Xb + Xw]
data[, eij := scale(rnorm(M)), keyby=Clus]
data[, Y := 5 +            # Intercept
       -0.2 * Xb +         # Between-level effect of X
        0.2 * Xw +         # Within-level effect of X
        0.1 * Wcgm +       # Between-level effect of W
       -0.2 * Xb * Wcgm +  # Between-level interaction
        0.2 * Xw * Wcgm +  # Cross-level interaction
       eij]

data = data[order(Clus, CaseID), .(
  Clus,    # Cluster
  CaseID,  # Subject ID
  Y,       # L1 Outcome
  X,       # L1 Predictor (X = Xb + Xw)
  Xb,      # X (cluster mean value)
  Xw,      # X (centered within cluster)
  W,       # L2 Predictor
  Wcgm     # W (centered at grand mean)
)]
glimpse(data)
## Rows: 1,464
## Columns: 8
## $ Clus   <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, …
## $ CaseID <fct> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, …
## $ Y      <dbl> 4.361, 3.160, 5.898, 4.428, 5.616, 6.729, 4.525, 4.682, 3.535, …
## $ X      <dbl> 2.6341, -4.4815, -1.2076, -0.5572, -0.3557, 2.3135, 0.3244, 0.9…
## $ Xb     <dbl> 0.2588, 0.2588, 0.2588, 0.2588, 0.2588, 0.2588, 0.2588, 0.2588,…
## $ Xw     <dbl> 2.37533, -4.74025, -1.46633, -0.81594, -0.61450, 2.05477, 0.065…
## $ W      <dbl> 1.848, 1.848, 1.848, 1.848, 1.848, 1.848, 1.848, 1.848, 1.848, …
## $ Wcgm   <dbl> -0.15166, -0.15166, -0.15166, -0.15166, -0.15166, -0.15166, -0.…

Exploratory Description

cor_multilevel(data[, .(Clus, Y, X, W)], "Clus")
## Correlations below and above the diagonal represent
## within-level and between-level correlations, respectively:
## ──────────────────────
##        Y      X      W
## ──────────────────────
## Y        -0.556 -0.348
## X  0.316        -0.057
## W                     
## ──────────────────────
## 
## Within-Level Correlation [95% CI]:
## ─────────────────────────────────────────
##                r       [95% CI]     p    
## ─────────────────────────────────────────
## Y.wg-X.wg  0.316 [0.269, 0.361] <.001 ***
## Y.wg-W.wg                                
## X.wg-W.wg                                
## ─────────────────────────────────────────
## 
## Between-Level Correlation [95% CI]:
## ────────────────────────────────────────────
##                 r         [95% CI]     p    
## ────────────────────────────────────────────
## Y.bg-X.bg  -0.556 [-0.668, -0.420] <.001 ***
## Y.bg-W.bg  -0.348 [-0.496, -0.182] <.001 ***
## X.bg-W.bg  -0.057 [-0.233,  0.122]  .530    
## ────────────────────────────────────────────
## 
## Intraclass Correlation:
## ────────────────────────
##            Y     X     W
## ────────────────────────
## ICC1  -0.022 0.100 1.000
## ICC2  -0.345 0.573 1.000
## ────────────────────────
Describe(data[, Y:Wcgm])
## Descriptive Statistics:
## ───────────────────────────────────────────────────────────
##          N  Mean   SD | Median   Min  Max Skewness Kurtosis
## ───────────────────────────────────────────────────────────
## Y     1464  4.81 1.12 |   4.82  0.60 8.25    -0.04    -0.00
## X     1464  1.00 2.11 |   0.95 -5.12 6.76    -0.00    -0.31
## Xb    1464  1.00 0.88 |   0.94 -1.33 3.29     0.04    -0.07
## Xw    1464  0.00 1.92 |  -0.06 -5.36 5.23    -0.01    -0.47
## W     1464  2.00 1.02 |   1.98 -0.83 4.56     0.16    -0.05
## Wcgm  1464 -0.00 1.02 |  -0.02 -2.83 2.56     0.16    -0.05
## ───────────────────────────────────────────────────────────

Modeling

CEM

CEM (MLM)

## 1-1 Model (Within-level main effect)

CEM.11.F = lmer(
  Y ~ Xb + Xw + (1 | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

CEM.11.R = lmer(
  Y ~ Xb + Xw + (Xw | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

anova(CEM.11.F, CEM.11.R)
## Data: data
## Models:
## CEM.11.F: Y ~ Xb + Xw + (1 | Clus)
## CEM.11.R: Y ~ Xb + Xw + (Xw | Clus)
##          npar  AIC  BIC logLik deviance Chisq Df Pr(>Chisq)    
## CEM.11.F    5 4325 4352  -2158     4315                        
## CEM.11.R    7 4238 4275  -2112     4224  91.6  2     <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Contextual effect
linearHypothesis(CEM.11.F, "Xb = Xw")
## Linear hypothesis test
## 
## Hypothesis:
## Xb - Xw = 0
## 
## Model 1: restricted model
## Model 2: Y ~ Xb + Xw + (1 | Clus)
## 
##   Df Chisq Pr(>Chisq)    
## 1                        
## 2  1   107     <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
linearHypothesis(CEM.11.R, "Xb = Xw")
## Linear hypothesis test
## 
## Hypothesis:
## Xb - Xw = 0
## 
## Model 1: restricted model
## Model 2: Y ~ Xb + Xw + (Xw | Clus)
## 
##   Df Chisq Pr(>Chisq)    
## 1                        
## 2  1  96.7     <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 2-1 Model (Between-level main effect)

CEM.21.F = lmer(
  Y ~ Xb + Xw + Wcgm + (1 | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

CEM.21.R = lmer(
  Y ~ Xb + Xw + Wcgm + (Xw | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

anova(CEM.21.F, CEM.21.R)
## Data: data
## Models:
## CEM.21.F: Y ~ Xb + Xw + Wcgm + (1 | Clus)
## CEM.21.R: Y ~ Xb + Xw + Wcgm + (Xw | Clus)
##          npar  AIC  BIC logLik deviance Chisq Df Pr(>Chisq)    
## CEM.21.F    6 4312 4344  -2150     4300                        
## CEM.21.R    8 4231 4274  -2108     4215    85  2     <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 2x1 Model (Cross-level interaction)

CEM.2x1.F = lmer(
  Y ~ Xb + Xw + Wcgm + Xb:Wcgm + Xw:Wcgm + (1 | Clus), 
  data=data, control=lmerControl(optimizer="bobyqa"))

CEM.2x1.R = lmer(
  Y ~ Xb + Xw + Wcgm + Xb:Wcgm + Xw:Wcgm + (Xw | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

anova(CEM.2x1.F, CEM.2x1.R)
## Data: data
## Models:
## CEM.2x1.F: Y ~ Xb + Xw + Wcgm + Xb:Wcgm + Xw:Wcgm + (1 | Clus)
## CEM.2x1.R: Y ~ Xb + Xw + Wcgm + Xb:Wcgm + Xw:Wcgm + (Xw | Clus)
##           npar  AIC  BIC logLik deviance Chisq Df Pr(>Chisq)
## CEM.2x1.F    8 4041 4083  -2012     4025                    
## CEM.2x1.R   10 4044 4097  -2012     4024   0.6  2       0.74
sim_slopes(CEM.2x1.F, pred=Xw, modx=Wcgm, johnson_neyman=TRUE)
## JOHNSON-NEYMAN INTERVAL 
## 
## When Wcgm is OUTSIDE the interval [-1.11, -0.75], the slope of Xw is p <
## .05.
## 
## Note: The range of observed values of Wcgm is [-2.83, 2.56]
## 
## SIMPLE SLOPES ANALYSIS 
## 
## Slope of Xw when Wcgm = -1.023e+00 (- 1 SD): 
## 
##    Est.   S.E.   t val.      p
## ------- ------ -------- ------
##   -0.02   0.02    -1.12   0.26
## 
## Slope of Xw when Wcgm = -3.094e-17 (Mean): 
## 
##   Est.   S.E.   t val.      p
## ------ ------ -------- ------
##   0.18   0.01    13.70   0.00
## 
## Slope of Xw when Wcgm =  1.023e+00 (+ 1 SD): 
## 
##   Est.   S.E.   t val.      p
## ------ ------ -------- ------
##   0.38   0.02    20.49   0.00
interact_plot(CEM.2x1.F, pred=Xw, modx=Wcgm,
              modx.values="plus-minus",
              modx.labels=c("Low", "High"),
              legend.main="Moderator") +
  ylab("Yij") + xlab("Xw")

johnson_neyman(CEM.2x1.F, pred=Xw, modx=Wcgm)
## JOHNSON-NEYMAN INTERVAL 
## 
## When Wcgm is OUTSIDE the interval [-1.11, -0.75], the slope of Xw is p <
## .05.
## 
## Note: The range of observed values of Wcgm is [-2.83, 2.56]

CEM (PLM)

## 1-1

CEM.PLM.11.R = plm(
  Y ~ Xb + Xw, index=c("Clus"),
  data=data, model="random")
print(summary(CEM.PLM.11.R), digits=3)
## Oneway (individual) effect Random Effect Model 
##    (Swamy-Arora's transformation)
## 
## Call:
## plm(formula = Y ~ Xb + Xw, data = data, model = "random", index = c("Clus"))
## 
## Balanced Panel: n = 122, T = 12, N = 1464
## 
## Effects:
##                var std.dev share
## idiosyncratic 1.16    1.08     1
## individual    0.00    0.00     0
## theta: 0
## 
## Residuals:
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -3.6100 -0.7043 -0.0423  0.7169  4.3357 
## 
## Coefficients:
##             Estimate Std. Error z-value Pr(>|z|)    
## (Intercept)   4.9881     0.0419  119.19  < 2e-16 ***
## Xb           -0.1778     0.0314   -5.66  1.5e-08 ***
## Xw            0.1792     0.0144   12.41  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1840
## Residual Sum of Squares: 1630
## R-Squared:      0.113
## Adj. R-Squared: 0.112
## Chisq: 186.102 on 2 DF, p-value: <2e-16
## Contextual effect
linearHypothesis(CEM.PLM.11.R, "Xb = Xw")
## Linear hypothesis test
## 
## Hypothesis:
## Xb - Xw = 0
## 
## Model 1: restricted model
## Model 2: Y ~ Xb + Xw
## 
##   Res.Df Df Chisq Pr(>Chisq)    
## 1   1462                        
## 2   1461  1   107     <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 2-1

CEM.PLM.21.R = plm(
  Y ~ Xb + Xw + Wcgm, index=c("Clus"),
  data=data, model="random")
print(summary(CEM.PLM.21.R), digits=3)
## Oneway (individual) effect Random Effect Model 
##    (Swamy-Arora's transformation)
## 
## Call:
## plm(formula = Y ~ Xb + Xw + Wcgm, data = data, model = "random", 
##     index = c("Clus"))
## 
## Balanced Panel: n = 122, T = 12, N = 1464
## 
## Effects:
##                var std.dev share
## idiosyncratic 1.16    1.08     1
## individual    0.00    0.00     0
## theta: 0
## 
## Residuals:
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -3.4139 -0.7182 -0.0493  0.7289  4.0502 
## 
## Coefficients:
##             Estimate Std. Error z-value Pr(>|z|)    
## (Intercept)   4.9951     0.0417  119.82  < 2e-16 ***
## Xb           -0.1848     0.0313   -5.90  3.7e-09 ***
## Xw            0.1792     0.0144   12.47  < 2e-16 ***
## Wcgm         -0.1049     0.0269   -3.89  9.9e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1840
## Residual Sum of Squares: 1620
## R-Squared:      0.122
## Adj. R-Squared: 0.12
## Chisq: 203.069 on 3 DF, p-value: <2e-16
## 2x1

CEM.PLM.2x1.R = plm(
  Y ~ Xb + Xw + Wcgm + Xb:Wcgm + Xw:Wcgm, index=c("Clus"),
  data=data, model="random")
print(summary(CEM.PLM.2x1.R), digits=3)
## Oneway (individual) effect Random Effect Model 
##    (Swamy-Arora's transformation)
## 
## Call:
## plm(formula = Y ~ Xb + Xw + Wcgm + Xb:Wcgm + Xw:Wcgm, data = data, 
##     model = "random", index = c("Clus"))
## 
## Balanced Panel: n = 122, T = 12, N = 1464
## 
## Effects:
##               var std.dev share
## idiosyncratic   1       1     1
## individual      0       0     0
## theta: 0
## 
## Residuals:
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -2.5606 -0.6512 -0.0395  0.6822  2.5273 
## 
## Coefficients:
##             Estimate Std. Error z-value Pr(>|z|)    
## (Intercept)   5.0000     0.0380  131.67  < 2e-16 ***
## Xb           -0.2000     0.0286   -7.00  2.6e-12 ***
## Xw            0.1792     0.0131   13.70  < 2e-16 ***
## Wcgm          0.1000     0.0348    2.87   0.0041 ** 
## Xb:Wcgm      -0.2000     0.0241   -8.29  < 2e-16 ***
## Xw:Wcgm       0.1955     0.0128   15.28  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1840
## Residual Sum of Squares: 1340
## R-Squared:      0.273
## Adj. R-Squared: 0.27
## Chisq: 546.925 on 5 DF, p-value: <2e-16

PLM: FEM & REM

## 1-1

PLM.11.F = plm(
  Y ~ X, index=c("Clus"),
  data=data, model="within")

PLM.11.R = plm(
  Y ~ X, index=c("Clus"),
  data=data, model="random")

## 2-1

PLM.21.F = plm(
  Y ~ X + Wcgm, index=c("Clus"),
  data=data, model="within")

PLM.21.R = plm(
  Y ~ X + Wcgm, index=c("Clus"),
  data=data, model="random")

## 2x1

PLM.2x1.F = plm(
  Y ~ X * Wcgm, index=c("Clus"),
  data=data, model="within")

PLM.2x1.R = plm(
  Y ~ X * Wcgm, index=c("Clus"),
  data=data, model="random")

## Hausman Test

phtest(PLM.11.F, PLM.11.R)
## 
##  Hausman Test
## 
## data:  Y ~ X
## chisq = 123, df = 1, p-value <2e-16
## alternative hypothesis: one model is inconsistent
phtest(PLM.21.F, PLM.21.R)
## 
##  Hausman Test
## 
## data:  Y ~ X + Wcgm
## chisq = 123, df = 1, p-value <2e-16
## alternative hypothesis: one model is inconsistent
phtest(PLM.2x1.F, PLM.2x1.R)
## 
##  Hausman Test
## 
## data:  Y ~ X * Wcgm
## chisq = 736, df = 2, p-value <2e-16
## alternative hypothesis: one model is inconsistent

MLM: Fixed & Random

## 1-1 Model (Within-level main effect)

MLM.11.F = lmer(
  Y ~ X + (1 | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

MLM.11.R = lmer(
  Y ~ X + (X | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

## 2-1 Model (Between-level main effect)

MLM.21.F = lmer(
  Y ~ X + Wcgm + (1 | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

MLM.21.R = lmer(
  Y ~ X + Wcgm + (X | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

## 2x1 Model (Cross-level interaction)

MLM.2x1.F = lmer(
  Y ~ X * Wcgm + (1 | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

MLM.2x1.R = lmer(
  Y ~ X * Wcgm + (X | Clus),
  data=data, control=lmerControl(optimizer="bobyqa"))

OLS Regression

## 1-1 Model

CEM.OLS.11 = lm(Y ~ Xb + Xw, data=data)
OLS.11 = lm(Y ~ X, data=data)

## 2-1 Model

CEM.OLS.21 = lm(Y ~ Xb + Xw + Wcgm, data=data)
OLS.21 = lm(Y ~ X + Wcgm, data=data)

## 2x1 Model

CEM.OLS.2x1 = lm(Y ~ Xb + Xw + Wcgm + Xb:Wcgm + Xw:Wcgm, data=data)
OLS.2x1 = lm(Y ~ X * Wcgm, data=data)

Model Summary

Summary based on method

## CEM (Fixed Slopes) Summary

tab_model(
  CEM.11.F,
  CEM.21.F,
  CEM.2x1.F,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("1-1", "2-1", "2x1"),
  title="Contextual Effects Model (Fixed Slopes)")
Contextual Effects Model (Fixed Slopes)
  1-1 2-1 2x1
Predictors Coef. p Coef. p Coef. p
(Intercept) 4.988
(0.042)
<0.001 4.995
(0.042)
<0.001 5.000
(0.038)
<0.001
Xb –0.178
(0.031)
<0.001 –0.185
(0.031)
<0.001 –0.200
(0.029)
<0.001
Xw 0.179
(0.014)
<0.001 0.179
(0.014)
<0.001 0.179
(0.013)
<0.001
Wcgm –0.105
(0.027)
<0.001 0.100
(0.035)
0.004
Xb × Wcgm –0.200
(0.024)
<0.001
Xw × Wcgm 0.195
(0.013)
<0.001
Random Effects
σ2 1.12 1.11 0.92
τ00 0.00 Clus 0.00 Clus 0.00 Clus
N 122 Clus 122 Clus 122 Clus
Observations 1464 1464 1464
Marginal R2 / Conditional R2 0.113 / NA 0.122 / NA 0.272 / NA
## CEM (Random Slopes) Summary

tab_model(
  CEM.11.R,
  CEM.21.R,
  CEM.2x1.R,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("1-1", "2-1", "2x1"),
  title="Contextual Effects Model (Random Slopes)")
Contextual Effects Model (Random Slopes)
  1-1 2-1 2x1
Predictors Coef. p Coef. p Coef. p
(Intercept) 4.998
(0.040)
<0.001 4.995
(0.039)
<0.001 5.000
(0.038)
<0.001
Xb –0.188
(0.030)
<0.001 –0.185
(0.029)
<0.001 –0.200
(0.028)
<0.001
Xw 0.179
(0.023)
<0.001 0.179
(0.023)
<0.001 0.179
(0.014)
<0.001
Wcgm –0.106
(0.025)
<0.001 0.100
(0.035)
0.004
Xb × Wcgm –0.200
(0.024)
<0.001
Xw × Wcgm 0.195
(0.013)
<0.001
Random Effects
σ2 0.96 0.96 0.91
τ00 0.01 Clus 0.00 Clus 0.00 Clus
τ11 0.04 Clus.Xw 0.04 Clus.Xw 0.00 Clus.Xw
ρ01 -1.00 Clus 1.00 Clus  
N 122 Clus 122 Clus 122 Clus
Observations 1464 1464 1464
Marginal R2 / Conditional R2 0.132 / NA 0.122 / 0.243 0.274 / NA
## CEM (PLM-REM) Summary

tab_model(
  CEM.PLM.11.R,
  CEM.OLS.11,
  CEM.PLM.21.R,
  CEM.OLS.21,
  CEM.PLM.2x1.R,
  CEM.OLS.2x1,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("1-1", "1-1 (OLS)", "2-1", "2-1 (OLS)", "2x1", "2x1 (OLS)"),
  title="Contextual Effects Model (Panel [Random Effects] Model)")
Contextual Effects Model (Panel [Random Effects] Model)
  1-1 1-1 (OLS) 2-1 2-1 (OLS) 2x1 2x1 (OLS)
Predictors Coef. p Coef. p Coef. p Coef. p Coef. p Coef. p
(Intercept) 4.988
(0.042)
<0.001 4.988
(0.042)
<0.001 4.995
(0.042)
<0.001 4.995
(0.042)
<0.001 5.000
(0.038)
<0.001 5.000
(0.038)
<0.001
Xb –0.178
(0.031)
<0.001 –0.178
(0.031)
<0.001 –0.185
(0.031)
<0.001 –0.185
(0.031)
<0.001 –0.200
(0.029)
<0.001 –0.200
(0.029)
<0.001
Xw 0.179
(0.014)
<0.001 0.179
(0.014)
<0.001 0.179
(0.014)
<0.001 0.179
(0.014)
<0.001 0.179
(0.013)
<0.001 0.179
(0.013)
<0.001
Wcgm –0.105
(0.027)
<0.001 –0.105
(0.027)
<0.001 0.100
(0.035)
0.004 0.100
(0.035)
0.004
Xb × Wcgm –0.200
(0.024)
<0.001 –0.200
(0.024)
<0.001
Xw × Wcgm 0.195
(0.013)
<0.001 0.195
(0.013)
<0.001
Observations 1464 1464 1464 1464 1464 1464
R2 / R2 adjusted 0.113 / 0.112 0.113 / 0.112 0.122 / 0.120 0.122 / 0.120 0.273 / 0.270 0.273 / 0.270
## FEM Summary

tab_model(
  PLM.11.F,
  PLM.21.F,
  PLM.2x1.F,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("1-1", "2-1", "2x1"),
  title="Panel Linear Model (Fixed Effects Model)")
Panel Linear Model (Fixed Effects Model)
  1-1 2-1 2x1
Predictors Coef. p Coef. p Coef. p
X 0.179
(0.015)
<0.001 0.179
(0.015)
<0.001 0.179
(0.014)
<0.001
X × Wcgm 0.195
(0.013)
<0.001
Observations 1464 1464 1464
R2 / R2 adjusted 0.100 / 0.018 0.100 / 0.018 0.224 / 0.153
## REM Summary

tab_model(
  PLM.11.R,
  OLS.11,
  PLM.21.R,
  OLS.21,
  PLM.2x1.R,
  OLS.2x1,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("1-1", "1-1 (OLS)", "2-1", "2-1 (OLS)", "2x1", "2x1 (OLS)"),
  title="Panel Linear Model (Random Effects Model)")
Panel Linear Model (Random Effects Model)
  1-1 1-1 (OLS) 2-1 2-1 (OLS) 2x1 2x1 (OLS)
Predictors Coef. p Coef. p Coef. p Coef. p Coef. p Coef. p
(Intercept) 4.693
(0.032)
<0.001 4.693
(0.032)
<0.001 4.694
(0.032)
<0.001 4.694
(0.032)
<0.001 4.699
(0.031)
<0.001 4.699
(0.031)
<0.001
X 0.117
(0.014)
<0.001 0.117
(0.014)
<0.001 0.116
(0.014)
<0.001 0.116
(0.014)
<0.001 0.117
(0.013)
<0.001 0.117
(0.013)
<0.001
Wcgm –0.090
(0.028)
0.001 –0.090
(0.028)
0.001 –0.205
(0.030)
<0.001 –0.205
(0.030)
<0.001
X × Wcgm 0.112
(0.013)
<0.001 0.112
(0.013)
<0.001
Observations 1464 1464 1464 1464 1464 1464
R2 / R2 adjusted 0.048 / 0.048 0.048 / 0.048 0.055 / 0.054 0.055 / 0.054 0.104 / 0.102 0.104 / 0.102
## MLM (Fixed Slopes) Summary

tab_model(
  MLM.11.F,
  MLM.21.F,
  MLM.2x1.F,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("1-1", "2-1", "2x1"),
  title="Multilevel Linear Model (Fixed Slopes)")
Multilevel Linear Model (Fixed Slopes)
  1-1 2-1 2x1
Predictors Coef. p Coef. p Coef. p
(Intercept) 4.680
(0.035)
<0.001 4.684
(0.034)
<0.001 4.665
(0.045)
<0.001
X 0.130
(0.014)
<0.001 0.126
(0.014)
<0.001 0.154
(0.013)
<0.001
Wcgm –0.090
(0.031)
0.004 –0.252
(0.044)
<0.001
X × Wcgm 0.160
(0.013)
<0.001
Random Effects
σ2 1.17 1.17 1.01
τ00 0.03 Clus 0.02 Clus 0.14 Clus
N 122 Clus 122 Clus 122 Clus
Observations 1464 1464 1464
Marginal R2 / Conditional R2 0.059 / 0.084 0.063 / 0.080 0.171 / 0.273
## MLM (Random Slopes) Summary

tab_model(
  MLM.11.R,
  MLM.21.R,
  MLM.2x1.R,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("1-1", "2-1", "2x1"),
  title="Multilevel Linear Model (Random Slopes)")
Multilevel Linear Model (Random Slopes)
  1-1 2-1 2x1
Predictors Coef. p Coef. p Coef. p
(Intercept) 4.681
(0.042)
<0.001 4.692
(0.037)
<0.001 4.676
(0.043)
<0.001
X 0.146
(0.020)
<0.001 0.144
(0.020)
<0.001 0.154
(0.014)
<0.001
Wcgm –0.121
(0.034)
<0.001 –0.241
(0.042)
<0.001
X × Wcgm 0.159
(0.014)
<0.001
Random Effects
σ2 1.03 1.04 0.99
τ00 0.10 Clus 0.06 Clus 0.12 Clus
τ11 0.03 Clus.X 0.03 Clus.X 0.00 Clus.X
ρ01 -0.59 Clus -0.35 Clus 0.16 Clus
N 122 Clus 122 Clus 122 Clus
Observations 1464 1464 1464
Marginal R2 / Conditional R2 0.072 / 0.214 0.083 / 0.216 0.170 / 0.278

Summary based on model

Note: The “Marginal R2 / Conditional R2” in each table indeed refers to Marginal R2 / Conditional R2 for models built with lmer() and R2 / R2 adjusted for models built with plm(). For an appropriate comparison, only the R2 displayed before the slash “/” can be interpreted and compared across models, which refers to the proportion of variance explained by predictors.

## 1-1 Model (Within-level main effect)

tab_model(
  CEM.11.F,
  CEM.11.R,
  CEM.PLM.11.R,
  PLM.11.F,
  PLM.11.R,
  MLM.11.F,
  MLM.11.R,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("CEM<br/>MLM-Fixed", "CEM<br/>MLM-Random", "CEM<br/>PLM-REM (OLS)",
              "PLM-FEM", "PLM-REM (OLS)", "MLM-Fixed", "MLM-Random"),
  title="1-1 Model (Within-level main effect)")
1-1 Model (Within-level main effect)
  CEM
MLM-Fixed
CEM
MLM-Random
CEM
PLM-REM (OLS)
PLM-FEM PLM-REM (OLS) MLM-Fixed MLM-Random
Predictors Coef. p Coef. p Coef. p Coef. p Coef. p Coef. p Coef. p
(Intercept) 4.988
(0.042)
<0.001 4.998
(0.040)
<0.001 4.988
(0.042)
<0.001 4.693
(0.032)
<0.001 4.680
(0.035)
<0.001 4.681
(0.042)
<0.001
Xb –0.178
(0.031)
<0.001 –0.188
(0.030)
<0.001 –0.178
(0.031)
<0.001
Xw 0.179
(0.014)
<0.001 0.179
(0.023)
<0.001 0.179
(0.014)
<0.001
X 0.179
(0.015)
<0.001 0.117
(0.014)
<0.001 0.130
(0.014)
<0.001 0.146
(0.020)
<0.001
Random Effects
σ2 1.12 0.96       1.17 1.03
τ00 0.00 Clus 0.01 Clus       0.03 Clus 0.10 Clus
τ11   0.04 Clus.Xw         0.03 Clus.X
ρ01   -1.00 Clus         -0.59 Clus
N 122 Clus 122 Clus       122 Clus 122 Clus
Observations 1464 1464 1464 1464 1464 1464 1464
Marginal R2 / Conditional R2 0.113 / NA 0.132 / NA 0.113 / 0.112 0.100 / 0.018 0.048 / 0.048 0.059 / 0.084 0.072 / 0.214
## 2-1 Model (Between-level main effect)

tab_model(
  CEM.21.F,
  CEM.21.R,
  CEM.PLM.21.R,
  PLM.21.F,
  PLM.21.R,
  MLM.21.F,
  MLM.21.R,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("CEM<br/>MLM-Fixed", "CEM<br/>MLM-Random", "CEM<br/>PLM-REM (OLS)",
              "PLM-FEM", "PLM-REM (OLS)", "MLM-Fixed", "MLM-Random"),
  title="2-1 Model (Between-level main effect)")
2-1 Model (Between-level main effect)
  CEM
MLM-Fixed
CEM
MLM-Random
CEM
PLM-REM (OLS)
PLM-FEM PLM-REM (OLS) MLM-Fixed MLM-Random
Predictors Coef. p Coef. p Coef. p Coef. p Coef. p Coef. p Coef. p
(Intercept) 4.995
(0.042)
<0.001 4.995
(0.039)
<0.001 4.995
(0.042)
<0.001 4.694
(0.032)
<0.001 4.684
(0.034)
<0.001 4.692
(0.037)
<0.001
Xb –0.185
(0.031)
<0.001 –0.185
(0.029)
<0.001 –0.185
(0.031)
<0.001
Xw 0.179
(0.014)
<0.001 0.179
(0.023)
<0.001 0.179
(0.014)
<0.001
Wcgm –0.105
(0.027)
<0.001 –0.106
(0.025)
<0.001 –0.105
(0.027)
<0.001 –0.090
(0.028)
0.001 –0.090
(0.031)
0.004 –0.121
(0.034)
<0.001
X 0.179
(0.015)
<0.001 0.116
(0.014)
<0.001 0.126
(0.014)
<0.001 0.144
(0.020)
<0.001
Random Effects
σ2 1.11 0.96       1.17 1.04
τ00 0.00 Clus 0.00 Clus       0.02 Clus 0.06 Clus
τ11   0.04 Clus.Xw         0.03 Clus.X
ρ01   1.00 Clus         -0.35 Clus
N 122 Clus 122 Clus       122 Clus 122 Clus
Observations 1464 1464 1464 1464 1464 1464 1464
Marginal R2 / Conditional R2 0.122 / NA 0.122 / 0.243 0.122 / 0.120 0.100 / 0.018 0.055 / 0.054 0.063 / 0.080 0.083 / 0.216
## 2x1 Model (Cross-level interaction)

tab_model(
  CEM.2x1.F,
  CEM.2x1.R,
  CEM.PLM.2x1.R,
  PLM.2x1.F,
  PLM.2x1.R,
  MLM.2x1.F,
  MLM.2x1.R,
  show.ci=FALSE, show.se=TRUE, collapse.se=TRUE, string.est="Coef.",
  show.icc=FALSE, show.aic=FALSE, minus.sign="\u2013", digits=3,
  dv.labels=c("CEM<br/>MLM-Fixed", "CEM<br/>MLM-Random", "CEM<br/>PLM-REM (OLS)",
              "PLM-FEM", "PLM-REM (OLS)", "MLM-Fixed", "MLM-Random"),
  title="2x1 Model (Cross-level interaction)")
2x1 Model (Cross-level interaction)
  CEM
MLM-Fixed
CEM
MLM-Random
CEM
PLM-REM (OLS)
PLM-FEM PLM-REM (OLS) MLM-Fixed MLM-Random
Predictors Coef. p Coef. p Coef. p Coef. p Coef. p Coef. p Coef. p
(Intercept) 5.000
(0.038)
<0.001 5.000
(0.038)
<0.001 5.000
(0.038)
<0.001 4.699
(0.031)
<0.001 4.665
(0.045)
<0.001 4.676
(0.043)
<0.001
Xb –0.200
(0.029)
<0.001 –0.200
(0.028)
<0.001 –0.200
(0.029)
<0.001
Xw 0.179
(0.013)
<0.001 0.179
(0.014)
<0.001 0.179
(0.013)
<0.001
Wcgm 0.100
(0.035)
0.004 0.100
(0.035)
0.004 0.100
(0.035)
0.004 –0.205
(0.030)
<0.001 –0.252
(0.044)
<0.001 –0.241
(0.042)
<0.001
Xb × Wcgm –0.200
(0.024)
<0.001 –0.200
(0.024)
<0.001 –0.200
(0.024)
<0.001
Xw × Wcgm 0.195
(0.013)
<0.001 0.195
(0.013)
<0.001 0.195
(0.013)
<0.001
X 0.179
(0.014)
<0.001 0.117
(0.013)
<0.001 0.154
(0.013)
<0.001 0.154
(0.014)
<0.001
X × Wcgm 0.195
(0.013)
<0.001 0.112
(0.013)
<0.001 0.160
(0.013)
<0.001 0.159
(0.014)
<0.001
Random Effects
σ2 0.92 0.91       1.01 0.99
τ00 0.00 Clus 0.00 Clus       0.14 Clus 0.12 Clus
τ11   0.00 Clus.Xw         0.00 Clus.X
ρ01             0.16 Clus
N 122 Clus 122 Clus       122 Clus 122 Clus
Observations 1464 1464 1464 1464 1464 1464 1464
Marginal R2 / Conditional R2 0.272 / NA 0.274 / NA 0.273 / 0.270 0.224 / 0.153 0.104 / 0.102 0.171 / 0.273 0.170 / 0.278