### SAS Textbook Examples Introduction to Multilevel Modeling by Kreft and de Leeuw Chapter 4: Analyses

Using proc contents to see the names of the variables and the variable labels.
 1 schid    Num    8   0 School ID
2 stuid    Num    8   8 Student ID
3 ses      Num    8  16 Socioecnonomic Status
4 meanses  Num    8  24 Mean SES for the school
5 homework Num    8  32 Time spent on math homework each week
6 white    Num    8  40 Race: 1=white, 0=non-white
7 parented Num    8  48 Parents highest education level
8 public   Num    8  56 Public school: 1=public, 0=non-public
9 ratio    Num    8  64 Student-Teacher ratio
10 percmin  Num    8  72 Percent minority in school
11 math     Num    8  80 Math score
12 sex      Num    8  88 Sex: 1=male, 2=female
13 race     Num    8  96 race of student, 1=asian, 2=Hispanic, 3=Black, 4=White, 5=Native American
14 sctype   Num    8 104 Type of school, 1=public, 2=catholic, 3=Private
other religious, 4=Private non-r
15 cstr     Num    8 112
16 scsize   Num    8 120
17 urban    Num    8 128
18 region   Num    8 136
Page 64, 4.2.2, The Null Model, Model 0 (SAS Program).
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = / solution ;
random intercept / subject=schid ;
run;
Results from the program (abbreviated).
                  Covariance Parameter Estimates

Standard         Z
Cov Parm      Subject    Estimate       Error     Value        Pr Z
Intercept     schid       26.1211      8.9853      2.91      0.0018
Residual                  81.2442      5.1539     15.76      <.0001

Fit Statistics
-2 Res Log Likelihood          3798.7
AIC (smaller is better)        3802.7
AICC (smaller is better)       3802.7
BIC (smaller is better)        3804.9

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     50.7589      1.1511      22      44.10      <.0001
Page 65, 4.2.3 'Homework and 'MathAchievement', Model 1, (SAS Program).
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework / solution ;
random intercept / subject=schid ;
run;
Results for model 1.
                   Covariance Parameter Estimates

Standard         Z
Cov Parm      Subject    Estimate       Error     Value        Pr Z
Intercept     schid       21.3376      7.5722      2.82      0.0024
Residual                  71.2842      4.5305     15.73      <.0001

Fit Statistics
-2 Res Log Likelihood          3729.3
AIC (smaller is better)        3733.3
AICC (smaller is better)       3733.3
BIC (smaller is better)        3735.6

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     46.3557      1.1627      22      39.87      <.0001
homework       2.3999      0.2772     495       8.66      <.0001
Pages 66 and 67, 4.2.4 Random slope for 'Homework', model 2 (SAS Program).
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework / solution ;
random intercept homework / subject=schid type=un;
run;
Results for model 2.
 Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       62.4231     21.3807      2.92      0.0018
UN(2,1)      schid      -27.5930     10.5657     -2.61      0.0090
UN(2,2)      schid       17.7260      6.2599      2.83      0.0023
Residual                 53.2947      3.4660     15.38      <.0001

Fit Statistics
-2 Res Log Likelihood          3635.6
AIC (smaller is better)        3643.6
AICC (smaller is better)       3643.6
BIC (smaller is better)        3648.1

Null Model Likelihood Ratio Test
DF    Chi-Square      Pr > ChiSq
3        190.19          <.0001

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     46.3256      1.7589      22      26.34      <.0001
homework       1.9802      0.9284      22       2.13      0.0443

Type 3 Tests of Fixed Effects

Num     Den
Effect         DF      DF    F Value    Pr > F
homework        1      22       4.55    0.0443
Page 69, 4.2.5 Adding 'ParentEducation', model 3 (SAS Program).
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework parented / solution ;
random intercept homework / subject=schid type=un;
run;
Results of model 3
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       47.8612     17.0115      2.81      0.0025
UN(2,1)      schid      -21.9452      8.4985     -2.58      0.0098
UN(2,2)      schid       13.8741      5.0365      2.75      0.0029
Residual                 50.7789      3.3118     15.33      <.0001

Fit Statistics
-2 Res Log Likelihood          3600.0
AIC (smaller is better)        3608.0
AICC (smaller is better)       3608.1
BIC (smaller is better)        3612.6

Null Model Likelihood Ratio Test

DF    Chi-Square      Pr > ChiSq
3        119.94          <.0001

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     40.8545      1.7901      22      22.82      <.0001
homework       1.8817      0.8301      22       2.27      0.0336
parented       1.8415      0.2959     472       6.22      <.0001
Page 70 and 71, 4.2.6 Traditional regression model.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework parented / solution ;
run;
Results
            Covariance Parameter Estimates

Standard         Z
Cov Parm     Estimate       Error     Value        Pr Z
Residual      76.1163      4.7388     16.06      <.0001

Fit Statistics
-2 Res Log Likelihood          3720.0
AIC (smaller is better)        3722.0
AICC (smaller is better)       3722.0
BIC (smaller is better)        3726.2
Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     37.2392      0.9963     516      37.38      <.0001
homework       2.3354      0.2684     516       8.70      <.0001
parented       3.0040      0.2765     516      10.86      <.0001
Page 73/74, 4.3.2 A model with 'SchoolSize' (Model 2), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework scsize / solution ;
random intercept homework / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       66.4271     23.3302      2.85      0.0022
UN(2,1)      schid      -28.7509     11.0714     -2.60      0.0094
UN(2,2)      schid       17.7846      6.2816      2.83      0.0023
Residual                 53.3058      3.4673     15.37      <.0001

Fit Statistics
-2 Res Log Likelihood          3634.2
AIC (smaller is better)        3642.2
AICC (smaller is better)       3642.3
BIC (smaller is better)        3646.8

Null Model Likelihood Ratio Test

DF    Chi-Square      Pr > ChiSq
3        189.33          <.0001

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     44.9720      2.7109      21      16.59      <.0001
homework       1.9812      0.9298      22       2.13      0.0445
scsize         0.4259      0.6410     473       0.66      0.5067
Page 74/75, 4.3.3 Changing 'SchoolSize' to 'Public' (Model 3), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework public / solution ;
random intercept homework / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       60.1538     20.8873      2.88      0.0020
UN(2,1)      schid      -27.4478     10.3743     -2.65      0.0082
UN(2,2)      schid       17.3031      6.1085      2.83      0.0023
Residual                 53.3443      3.4716     15.37      <.0001

Fit Statistics
-2 Res Log Likelihood          3628.4
AIC (smaller is better)        3636.4
AICC (smaller is better)       3636.5
BIC (smaller is better)        3640.9

Null Model Likelihood Ratio Test

DF    Chi-Square      Pr > ChiSq
3        157.64          <.0001

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     49.0504      2.1847      21      22.45      <.0001
homework       1.9753      0.9182      22       2.15      0.0427
public        -4.0611      1.9779     473      -2.05      0.0406
Page 77, 4.3.4 Adding a cross level interaction with 'Public',  (Model 4), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework public homework*public / solution ;
random intercept homework / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       62.5515     22.0536      2.84      0.0023
UN(2,1)      schid      -28.9502     11.0801     -2.61      0.0090
UN(2,2)      schid       18.2497      6.5507      2.79      0.0027
Residual                 53.3329      3.4702     15.37      <.0001

Fit Statistics
-2 Res Log Likelihood          3625.2
AIC (smaller is better)        3633.2
AICC (smaller is better)       3633.2
BIC (smaller is better)        3637.7

Null Model Likelihood Ratio Test

DF    Chi-Square      Pr > ChiSq
3        159.63          <.0001

Solution for Fixed Effects

Standard
Effect             Estimate       Error      DF    t Value    Pr > |t|
Intercept           48.5289      3.0160      21      16.09      <.0001
homework             2.2928      1.5913      21       1.44      0.1644
public              -3.2620      3.7145     473      -0.88      0.3803
homework*public     -0.4957      1.9727     473      -0.25      0.8017
Page 80, 4.3.5 Model 4 will full NELS-88 data (we don't have these data, so this is omitted).

Page 80/82, 4.3.6 Deleting 'HomePublic' and adding 'White' (Model 5), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework public white / solution ;
random intercept homework / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       56.0169     19.6224      2.85      0.0022
UN(2,1)      schid      -26.8055      9.9968     -2.68      0.0073
UN(2,2)      schid       16.7698      5.9278      2.83      0.0023
Residual                 52.7291      3.4370     15.34      <.0001

Fit Statistics
-2 Res Log Likelihood          3615.5
AIC (smaller is better)        3623.5
AICC (smaller is better)       3623.5
BIC (smaller is better)        3628.0

Null Model Likelihood Ratio Test

DF    Chi-Square      Pr > ChiSq
3        133.03          <.0001

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     46.6283      2.1921      21      21.27      <.0001
homework       1.8992      0.9049      22       2.10      0.0475
public        -3.8825      1.7987     472      -2.16      0.0314
white          3.3095      0.9699     472       3.41      0.0007
Page 82/83, 4.3.7 Adding a random part for 'White' (Model 6), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework public white / solution ;
random intercept homework white / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       69.1398     31.1837      2.22      0.0133
UN(2,1)      schid      -28.5298     12.2476     -2.33      0.0198
UN(2,2)      schid       16.6238      5.8694      2.83      0.0023
UN(3,1)      schid      -22.0770     20.9222     -1.06      0.2913
UN(3,2)      schid        2.9197      7.9180      0.37      0.7123
UN(3,3)      schid       26.4989     22.5376      1.18      0.1198
Residual                 51.1580      3.3848     15.11      <.0001

Fit Statistics
-2 Res Log Likelihood          3610.5
AIC (smaller is better)        3624.5
AICC (smaller is better)       3624.7
BIC (smaller is better)        3632.4

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     48.2276      2.3398      21      20.61      <.0001
homework       1.9401      0.9003      22       2.16      0.0424
public        -4.9292      1.6507     457      -2.99      0.0030
white          2.5982      1.5538      15       1.67      0.1152
Page 85, 4.3.8 Making the coefficient of 'White' fixed and adding 'MeanSES' (Model 7), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework public white meanses / solution ;
random intercept homework / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       54.1137     19.0857      2.84      0.0023
UN(2,1)      schid      -27.0176      9.8916     -2.73      0.0063
UN(2,2)      schid       16.4294      5.8132      2.83      0.0024
Residual                 52.7965      3.4449     15.33      <.0001

Fit Statistics
-2 Res Log Likelihood          3606.5
AIC (smaller is better)        3614.5
AICC (smaller is better)       3614.6
BIC (smaller is better)        3619.1

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     44.6158      2.2348      20      19.96      <.0001
homework       1.9243      0.8961      22       2.15      0.0430
public         0.1603      2.2708     472       0.07      0.9437
white          3.0971      0.9631     472       3.22      0.0014
meanses        4.9776      1.9507     472       2.55      0.0110
Page 86, 4.3.9 Deleting the school characteristic 'Public' (Model 8), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework white meanses / solution ;
random intercept homework / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       53.5511     18.8970      2.83      0.0023
UN(2,1)      schid      -26.9812      9.8535     -2.74      0.0062
UN(2,2)      schid       16.3851      5.7957      2.83      0.0023
Residual                 52.7925      3.4444     15.33      <.0001

Fit Statistics
-2 Res Log Likelihood          3610.0
AIC (smaller is better)        3618.0
AICC (smaller is better)       3618.1
BIC (smaller is better)        3622.5

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     44.7021      1.7870      21      25.02      <.0001
homework       1.9252      0.8948      22       2.15      0.0427
white          3.1151      0.9570     472       3.25      0.0012
meanses        4.8928      1.3405     472       3.65      0.0003
Page 87/88, 4.3.10 Adding an interaction between 'HomeWork' and 'MeanSES' (Model 9), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework white meanses homework*meanses / solution ;
random intercept homework / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       55.8829     20.0177      2.79      0.0026
UN(2,1)      schid      -28.3876     10.5226     -2.70      0.0070
UN(2,2)      schid       17.2368      6.2097      2.78      0.0028
Residual                 52.7811      3.4431     15.33      <.0001

Fit Statistics
-2 Res Log Likelihood          3607.1
AIC (smaller is better)        3615.1
AICC (smaller is better)       3615.1
BIC (smaller is better)        3619.6

Solution for Fixed Effects

Standard
Effect              Estimate       Error      DF    t Value    Pr > |t|
Intercept            44.6113      1.8361      21      24.30      <.0001
homework              1.9747      0.9291      21       2.13      0.0456
white                 3.1150      0.9571     472       3.25      0.0012
meanses               3.9776      3.0226     472       1.32      0.1888
homework*meanses      0.5531      1.6457     472       0.34      0.7369
Page 88/89, 4.3.11 Adding another student-level variable (Model 10), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework white meanses ses / solution ;
random intercept homework / subject=schid type=un;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       49.8879     17.7280      2.81      0.0024
UN(2,1)      schid      -24.3721      9.0424     -2.70      0.0070
UN(2,2)      schid       14.6440      5.2441      2.79      0.0026
Residual                 51.2969      3.3506     15.31      <.0001

Fit Statistics
-2 Res Log Likelihood          3592.8
AIC (smaller is better)        3600.8
AICC (smaller is better)       3600.8
BIC (smaller is better)        3605.3

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     45.6748      1.7519      21      26.07      <.0001
homework       1.8257      0.8503      22       2.15      0.0431
white          2.1708      0.9733     471       2.23      0.0262
meanses        2.9453      1.4280     471       2.06      0.0397
ses            2.2058      0.5356     471       4.12      <.0001
Page 88/89, 4.3.12: Analyses with NELS-88 (we don't have these data, so these analyses are omitted).
Page 91, 4.4.1 'SES' as a student-level explanatory variable (Model 1), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = ses / solution ;
random intercept / subject=schid ;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm      Subject    Estimate       Error     Value        Pr Z
Intercept     schid       12.6312      5.0151      2.52      0.0059
Residual                  75.3279      4.7872     15.74      <.0001

Fit Statistics
-2 Res Log Likelihood          3746.2
AIC (smaller is better)        3750.2
AICC (smaller is better)       3750.2
BIC (smaller is better)        3752.4

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     51.2009      0.8507      22      60.19      <.0001
ses            4.3323      0.5663     495       7.65      <.0001
Page 92, 4.4.2 Adding a random slope (Model 2), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = ses / solution ;
random intercept ses / subject=schid type=un ;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       12.9434      5.0950      2.54      0.0055
UN(2,1)      schid       -1.4471      3.1449     -0.46      0.6454
UN(2,2)      schid             0           .       .         .
Residual                 75.2360      4.7748     15.76      <.0001

Fit Statistics
-2 Res Log Likelihood          3746.0
AIC (smaller is better)        3752.0
AICC (smaller is better)       3752.0
BIC (smaller is better)        3755.4

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     51.2578      0.8556      22      59.91      <.0001
ses            4.3173      0.5613      22       7.69      <.0001
Page 93, 4.4.3 Adding 'PercentMinorities' (Model 3), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = ses percmin / solution ;
random intercept  / subject=schid type=un ;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       10.6974      4.3367      2.47      0.0068
Residual                 75.1727      4.7693     15.76      <.0001

Fit Statistics
-2 Res Log Likelihood          3741.6
AIC (smaller is better)        3745.6
AICC (smaller is better)       3745.6
BIC (smaller is better)        3747.9

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     53.1266      1.1780      21      45.10      <.0001
ses            4.2988      0.5618     495       7.65      <.0001
percmin       -0.8094      0.3647     495      -2.22      0.0269
Page 95, 4.4.4 Adding 'MeanSES' (Model 4), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = ses percmin meanses / solution ;
random intercept  / subject=schid type=un ;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid        8.8432      3.9345      2.25      0.0123
Residual                 75.2413      4.7777     15.75      <.0001

Fit Statistics
-2 Res Log Likelihood          3735.6
AIC (smaller is better)        3739.6
AICC (smaller is better)       3739.6
BIC (smaller is better)        3741.9

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     53.0969      1.1025      20      48.16      <.0001
ses            3.8848      0.6098     495       6.37      <.0001
percmin       -0.6922      0.3456     495      -2.00      0.0458
meanses        2.8052      1.4792     495       1.90      0.0585
Page 95, 4.4.5 Analyses with NELS-88, models 2 and 3 (we do not have these data, so these analyses are omitted).
Page 99, 4.5.1 Analysis with class size and a cross level interaction (Model 1), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework ratio / solution ;
random intercept homework / subject=schid type=un ;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       63.4439     21.7601      2.92      0.0018
UN(2,1)      schid      -27.6790     10.6264     -2.60      0.0092
UN(2,2)      schid       17.7255      6.2584      2.83      0.0023
Residual                 53.3063      3.4673     15.37      <.0001

Fit Statistics
-2 Res Log Likelihood          3636.6
AIC (smaller is better)        3644.6
AICC (smaller is better)       3644.7
BIC (smaller is better)        3649.2

Solution for Fixed Effects

Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept     47.9615      4.0831      21      11.75      <.0001
homework       1.9794      0.9285      22       2.13      0.0444
ratio        -0.09442      0.2124     473      -0.44      0.6568
Page 100, 4.5.2 Interaction between 'Ratio' and 'HomeWork' (Model 2), SAS Program.
proc mixed data="c:\imm\imm23" covtest;
class schid;
model math = homework homework*ratio / solution ;
random intercept homework / subject=schid type=un ;
run;
And the results are
                  Covariance Parameter Estimates

Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      schid       62.5534     21.4199      2.92      0.0017
UN(2,1)      schid      -27.7993     10.6543     -2.61      0.0091
UN(2,2)      schid       18.0944      6.3898      2.83      0.0023
Residual                 53.2978      3.4664     15.38      <.0001

Fit Statistics
-2 Res Log Likelihood          3637.9
AIC (smaller is better)        3645.9
AICC (smaller is better)       3646.0
BIC (smaller is better)        3650.4

Solution for Fixed Effects

Standard
Effect            Estimate       Error      DF    t Value    Pr > |t|
Intercept          46.3306      1.7606      22      26.32      <.0001
homework            2.8841      2.1568      21       1.34      0.1955
homework*ratio    -0.05259      0.1123     473      -0.47      0.6398
Page 100, 4.5.3 Reporting the modeling session with NELS-88  (we do not have these data, so these analyses are omitted).

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.