> Example1$L2_SS13 = Example1$L2_SS - 13
> Example1$L2_AL15 = Example1$L2_AL - 15
> print("Descriptive statistics")
[1] "Descriptive statistics"
> summary(Example1$PAE)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    7.0    13.0    16.0    15.8    19.0    35.0 
> summary(Example1$AL)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    5.0    13.0    15.0    15.2    17.0    24.0 
> summary(Example1$L2_SS)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    8.0    11.0    13.0    12.8    14.0    19.0 
> print("Model 1: Empty Model with Fixed Item Effects")
[1] "Model 1: Empty Model with Fixed Item Effects"
> Model1 = lmer(data = Example1, REML = TRUE, formula = PAE ~ 0 + 
+ Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 + Item8 + 
+ Item9 + Item10 + (1 | PersonID))
> print("Results, ICC, and LRT for random effects")
[1] "Results, ICC, and LRT for random effects"
> summary(Model1, ddf = "Satterthwaite")
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: PAE ~ 0 + Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 +      Item8 + Item9 + Item10 + (1 | PersonID)
   Data: Example1

REML criterion at convergence: 7317.4

Scaled residuals: 
   Min     1Q Median     3Q    Max 
-3.687 -0.525 -0.037  0.507  5.755 

Random effects:
 Groups   Name        Variance Std.Dev.
 PersonID (Intercept) 11.28    3.36    
 Residual              5.67    2.38    
Number of obs: 1500, groups:  PersonID, 150

Fixed effects:
       Estimate Std. Error      df t value Pr(>|t|)
Item1    15.127      0.336 298.840    45.0   <2e-16
Item2    16.213      0.336 298.840    48.2   <2e-16
Item3    14.687      0.336 298.840    43.7   <2e-16
Item4    13.713      0.336 298.840    40.8   <2e-16
Item5    15.487      0.336 298.840    46.1   <2e-16
Item6    16.993      0.336 298.840    50.5   <2e-16
Item7    16.487      0.336 298.840    49.0   <2e-16
Item8    17.987      0.336 298.840    53.5   <2e-16
Item9    16.273      0.336 298.840    48.4   <2e-16
Item10   14.587      0.336 298.840    43.4   <2e-16

Correlation of Fixed Effects:
       Item1 Item2 Item3 Item4 Item5 Item6 Item7 Item8 Item9
Item2  0.665                                                
Item3  0.665 0.665                                          
Item4  0.665 0.665 0.665                                    
Item5  0.665 0.665 0.665 0.665                              
Item6  0.665 0.665 0.665 0.665 0.665                        
Item7  0.665 0.665 0.665 0.665 0.665 0.665                  
Item8  0.665 0.665 0.665 0.665 0.665 0.665 0.665            
Item9  0.665 0.665 0.665 0.665 0.665 0.665 0.665 0.665      
Item10 0.665 0.665 0.665 0.665 0.665 0.665 0.665 0.665 0.665
> icc(Model1)
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.665
  Unadjusted ICC: 0.612
> ranova(Model1)
ANOVA-like table for random-effects: Single term deletions

Model:
PAE ~ 0 + Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 + Item8 + Item9 + Item10 + (1 | PersonID)
               npar logLik  AIC  LRT Df Pr(>Chisq)
<none>           12  -3659 7341                   
(1 | PersonID)   11  -4248 8518 1179  1     <2e-16
> print("Empty model for L1 AL predictor")
[1] "Empty model for L1 AL predictor"
> ModelAL = lmer(data = Example1, REML = TRUE, formula = AL ~ 1 + 
+ (1 | PersonID))
> print("Results, ICC, and LRT for random effects")
[1] "Results, ICC, and LRT for random effects"
> summary(ModelAL, ddf = "Satterthwaite")
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: AL ~ 1 + (1 | PersonID)
   Data: Example1

REML criterion at convergence: 5739.6

Scaled residuals: 
   Min     1Q Median     3Q    Max 
-3.596 -0.597 -0.007  0.605  2.947 

Random effects:
 Groups   Name        Variance Std.Dev.
 PersonID (Intercept) 7.11     2.67    
 Residual             1.86     1.36    
Number of obs: 1500, groups:  PersonID, 150

Fixed effects:
            Estimate Std. Error      df t value Pr(>|t|)
(Intercept)   15.187      0.221 149.000    68.8   <2e-16
> icc(ModelAL)
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.793
  Unadjusted ICC: 0.793
> ranova(ModelAL)
ANOVA-like table for random-effects: Single term deletions

Model:
AL ~ 1 + (1 | PersonID)
               npar logLik  AIC  LRT Df Pr(>Chisq)
<none>            3  -2870 5746                   
(1 | PersonID)    2  -3772 7547 1804  1     <2e-16
> print("Model 2: Add fixed slopes of L2 predictors for mean AL and SS")
[1] "Model 2: Add fixed slopes of L2 predictors for mean AL and SS"
> Model2 = lmer(data = Example1, REML = TRUE, formula = PAE ~ 0 + 
+ Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 + Item8 + 
+ Item9 + Item10 + L2_AL15 + L2_SS13 + (1 | PersonID))
> summary(Model2, ddf = "Satterthwaite")
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: PAE ~ 0 + Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 +      Item8 + Item9 + Item10 + L2_AL15 + L2_SS13 + (1 | PersonID)
   Data: Example1

REML criterion at convergence: 7251.8

Scaled residuals: 
   Min     1Q Median     3Q    Max 
-3.711 -0.534 -0.028  0.505  5.695 

Random effects:
 Groups   Name        Variance Std.Dev.
 PersonID (Intercept) 6.87     2.62    
 Residual             5.67     2.38    
Number of obs: 1500, groups:  PersonID, 150

Fixed effects:
        Estimate Std. Error       df t value       Pr(>|t|)
Item1    15.1851     0.2905 393.2614   52.28        < 2e-16
Item2    16.2718     0.2905 393.2614   56.02        < 2e-16
Item3    14.7451     0.2905 393.2614   50.76        < 2e-16
Item4    13.7718     0.2905 393.2614   47.41        < 2e-16
Item5    15.5451     0.2905 393.2614   53.52        < 2e-16
Item6    17.0518     0.2905 393.2614   58.71        < 2e-16
Item7    16.5451     0.2905 393.2614   56.96        < 2e-16
Item8    18.0451     0.2905 393.2614   62.13        < 2e-16
Item9    16.3318     0.2905 393.2614   56.23        < 2e-16
Item10   14.6451     0.2905 393.2614   50.42        < 2e-16
L2_AL15   0.4694     0.0832 147.0000    5.64 0.000000082933
L2_SS13   0.7554     0.1076 147.0000    7.02 0.000000000076

Correlation of Fixed Effects:
        Item1  Item2  Item3  Item4  Item5  Item6  Item7  Item8  Item9  Item10 L2_AL1
Item2    0.552                                                                      
Item3    0.552  0.552                                                               
Item4    0.552  0.552  0.552                                                        
Item5    0.552  0.552  0.552  0.552                                                 
Item6    0.552  0.552  0.552  0.552  0.552                                          
Item7    0.552  0.552  0.552  0.552  0.552  0.552                                   
Item8    0.552  0.552  0.552  0.552  0.552  0.552  0.552                            
Item9    0.552  0.552  0.552  0.552  0.552  0.552  0.552  0.552                     
Item10   0.552  0.552  0.552  0.552  0.552  0.552  0.552  0.552  0.552              
L2_AL15 -0.061 -0.061 -0.061 -0.061 -0.061 -0.061 -0.061 -0.061 -0.061 -0.061       
L2_SS13  0.077  0.077  0.077  0.077  0.077  0.077  0.077  0.077  0.077  0.077 -0.104
> print("Pseudo-R2 using custom function")
[1] "Pseudo-R2 using custom function"
> PseudoR2(baseModel = Model1, altModel1 = Model2, name1 = "L2pred")
Pseudo-R2 for L2pred 
         term     base    alt1 pR2.alt1
1 (Intercept) 11.28429 6.87196   0.3910
2    Residual  5.67195 5.67195   0.0000
> print("Model 3: Add fixed slope of L1 predictor for CMC AL")
[1] "Model 3: Add fixed slope of L1 predictor for CMC AL"
> Model3 = lmer(data = Example1, REML = TRUE, formula = PAE ~ 0 + 
+ Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 + Item8 + 
+ Item9 + Item10 + L1_AL + L2_AL15 + L2_SS13 + (1 | PersonID))
> summary(Model3, ddf = "Satterthwaite")
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: PAE ~ 0 + Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 +      Item8 + Item9 + Item10 + L1_AL + L2_AL15 + L2_SS13 + (1 |  
    PersonID)
   Data: Example1

REML criterion at convergence: 7038.6

Scaled residuals: 
   Min     1Q Median     3Q    Max 
-3.946 -0.559 -0.039  0.554  5.129 

Random effects:
 Groups   Name        Variance Std.Dev.
 PersonID (Intercept) 6.96     2.64    
 Residual             4.83     2.20    
Number of obs: 1500, groups:  PersonID, 150

Fixed effects:
         Estimate Std. Error        df t value       Pr(>|t|)
Item1     15.2481     0.2816  352.1280   54.14        < 2e-16
Item2     16.2313     0.2816  352.0489   57.64        < 2e-16
Item3     14.7316     0.2816  351.9993   52.32        < 2e-16
Item4     13.7538     0.2816  352.0041   48.84        < 2e-16
Item5     15.5136     0.2816  352.0268   55.09        < 2e-16
Item6     16.9843     0.2816  352.1479   60.31        < 2e-16
Item7     16.5046     0.2816  352.0489   58.61        < 2e-16
Item8     18.1171     0.2816  352.1692   64.33        < 2e-16
Item9     16.3003     0.2816  352.0268   57.89        < 2e-16
Item10    14.7530     0.2817  352.3894   52.38        < 2e-16
L1_AL      0.6746     0.0439 1340.0000   15.36        < 2e-16
L2_AL15    0.4694     0.0832  147.0000    5.64 0.000000082933
L2_SS13    0.7554     0.1076  147.0000    7.02 0.000000000076
> print("Pseudo-R2 and change in R2 using custom function")
[1] "Pseudo-R2 and change in R2 using custom function"
> PseudoR2(baseModel = Model1, altModel1 = Model2, name1 = "L2pred", 
+ altModel2 = Model3, name2 = "L1pred")
Pseudo-R2 and Change in Pseudo-R2 for L2pred vs L1pred 
         term     base    alt1    alt2 pR2.alt1 pR2.alt2 pR2.change
1 (Intercept) 11.28429 6.87196 6.95655   0.3910   0.3835    -0.0075
2    Residual  5.67195 5.67195 4.82599   0.0000   0.1491     0.1491
> print("Model 4: Add random slope L1 predictor for CMC AL and do LRT")
[1] "Model 4: Add random slope L1 predictor for CMC AL and do LRT"
> Model4 = lmer(data = Example1, REML = TRUE, formula = PAE ~ 0 + 
+ Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 + Item8 + 
+ Item9 + Item10 + L1_AL + L2_AL15 + L2_SS13 + (1 + L1_AL | 
+ PersonID))
> print("Results and LRT for random effects")
[1] "Results and LRT for random effects"
> summary(Model4, ddf = "Satterthwaite")
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: PAE ~ 0 + Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 +      Item8 + Item9 + Item10 + L1_AL + L2_AL15 + L2_SS13 + (1 +  
    L1_AL | PersonID)
   Data: Example1

REML criterion at convergence: 6171.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.1173 -0.6266 -0.0086  0.5958  2.9753 

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 PersonID (Intercept) 7.28     2.70          
          L1_AL       1.54     1.24     0.18 
 Residual             1.91     1.38          
Number of obs: 1500, groups:  PersonID, 150

Fixed effects:
        Estimate Std. Error       df t value     Pr(>|t|)
Item1    15.3595     0.2515 226.8568   61.07      < 2e-16
Item2    16.3049     0.2516 226.8037   64.82      < 2e-16
Item3    14.5471     0.2514 226.1559   57.88      < 2e-16
Item4    13.5858     0.2516 227.2683   53.99      < 2e-16
Item5    15.5251     0.2512 225.5376   61.81      < 2e-16
Item6    17.2386     0.2514 226.5713   68.56      < 2e-16
Item7    16.4335     0.2515 226.8145   65.34      < 2e-16
Item8    18.2462     0.2515 226.5690   72.56      < 2e-16
Item9    16.3392     0.2516 227.0591   64.93      < 2e-16
Item10   14.4026     0.2519 228.0621   57.17      < 2e-16
L1_AL     0.6856     0.1061 149.6024    6.46 0.0000000014
L2_AL15   0.4622     0.0821 147.0340    5.63 0.0000000887
L2_SS13   0.6683     0.1063 147.1214    6.29 0.0000000034
> ranova(Model4)
ANOVA-like table for random-effects: Single term deletions

Model:
PAE ~ 0 + Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 + Item8 + Item9 + Item10 + L1_AL + L2_AL15 + L2_SS13 + (1 + L1_AL | PersonID)
                                npar logLik  AIC   LRT Df Pr(>Chisq)
<none>                            17  -3086 6205                    
L1_AL in (1 + L1_AL | PersonID)   15  -3519 7069 867.4  2     <2e-16
> print("Model 5: Add cross-level interaction of L1 AL by L2 SS")
[1] "Model 5: Add cross-level interaction of L1 AL by L2 SS"
> Model5 = lmer(data = Example1, REML = TRUE, formula = PAE ~ 0 + 
+ Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 + Item8 + 
+ Item9 + Item10 + L1_AL + L2_AL15 + L2_SS13 + L1_AL:L2_SS13 + 
+ (1 + L1_AL | PersonID))
> summary(Model5, ddf = "Satterthwaite")
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: PAE ~ 0 + Item1 + Item2 + Item3 + Item4 + Item5 + Item6 + Item7 +  
    Item8 + Item9 + Item10 + L1_AL + L2_AL15 + L2_SS13 + L1_AL:L2_SS13 +      (1 + L1_AL | PersonID)
   Data: Example1

REML criterion at convergence: 6150.4

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.1318 -0.6259 -0.0103  0.5917  3.0149 

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 PersonID (Intercept) 7.25     2.69          
          L1_AL       1.30     1.14     0.17 
 Residual             1.90     1.38          
Number of obs: 1500, groups:  PersonID, 150

Fixed effects:
              Estimate Std. Error       df t value        Pr(>|t|)
Item1          15.3815     0.2511 229.0022   61.27         < 2e-16
Item2          16.3188     0.2511 228.9883   64.99         < 2e-16
Item3          14.5656     0.2509 228.3360   58.06         < 2e-16
Item4          13.6099     0.2512 229.4192   54.19         < 2e-16
Item5          15.5421     0.2507 227.7144   61.99         < 2e-16
Item6          17.2524     0.2510 228.7288   68.75         < 2e-16
Item7          16.4524     0.2511 228.9779   65.53         < 2e-16
Item8          18.2639     0.2510 228.7479   72.77         < 2e-16
Item9          16.3488     0.2511 229.2758   65.10         < 2e-16
Item10         14.4185     0.2514 230.2680   57.35         < 2e-16
L1_AL           0.7352     0.0987 150.3693    7.45 0.0000000000067
L2_AL15         0.4617     0.0821 147.0350    5.62 0.0000000911023
L2_SS13         0.7565     0.1076 147.1105    7.03 0.0000000000716
L1_AL:L2_SS13   0.2467     0.0475 153.7989    5.19 0.0000006522892
> PseudoR2(baseModel = Model4, altModel1 = Model5, name1 = "Cross-level")
Pseudo-R2 for Cross-level 
         term    base    alt1 pR2.alt1
1 (Intercept) 7.28024 7.24785   0.0044
2       L1_AL 1.54272 1.29962   0.1576
4    Residual 1.90601 1.90466   0.0007
