STA429/1007 F 2004 Handout 7: The School Data
More proc glm
/* school.sas */
options linesize=79 noovp formdlim='_';
title 'Training school example: Nested with covariates';
data teach;
infile 'school1.dat' firstobs=2; /* Skip the first line*/
input id School Instr Learn x1 x2 x3;
/* Explore Character-valued vars and if statements */
if school=1 and instr=1 then iname = 'Che Guevarra';
if school=1 and instr=2 then iname = 'Amelia Airheart';
if school=2 and instr=1 then iname = 'Oscar Robertson';
if school=2 and instr=2 then iname = 'Earl Monroe';
if school=3 and instr=1 then iname = 'Kareem Abdul-Jabbar';
if school=3 and instr=2 then iname = 'Stanley';
attrib iname2 length=$20; /* The default length appears to be 12 */
if school=1 and instr=1 then iname2 = 'Che Guevarra';
if school=1 and instr=2 then iname2 = 'Amelia Airheart';
if school=2 and instr=1 then iname2 = 'Oscar Robertson';
if school=2 and instr=2 then iname2 = 'Earl Monroe';
if school=3 and instr=1 then iname2 = 'Kareem Abdul-Jabbar';
if school=3 and instr=2 then iname2 = 'Stanley';
proc freq;
tables iname iname2;
proc glm;
title2 'Traditional ANCOVA';
class school instr;
model learn = x1 x2 x3 school|instr;
proc glm;
title2 'Check some ANCOVA Interactions';
class school instr;
model learn = x1 x2 x3 school|instr
x1*school x1*instr x1*school*instr;
/* x1*school|instr produced wrong results & no error message */
proc glm;
title2 'Nested with covariates';
class school instr;
model learn = x1 x2 x3 school instr(school);
/* x1*instr(school) yields garbage */
Here is school.lst
_______________________________________________________________________________
Training school example: Nested with covariates 1
15:08 Monday, October 25, 2004
The FREQ Procedure
Cumulative Cumulative
iname Frequency Percent Frequency Percent
-----------------------------------------------------------------
Amelia Airhe 4 16.67 4 16.67
Che Guevarra 4 16.67 8 33.33
Earl Monroe 4 16.67 12 50.00
Kareem Abdul 4 16.67 16 66.67
Oscar Robert 4 16.67 20 83.33
Stanley 4 16.67 24 100.00
Cumulative Cumulative
iname2 Frequency Percent Frequency Percent
------------------------------------------------------------------------
Amelia Airheart 4 16.67 4 16.67
Che Guevarra 4 16.67 8 33.33
Earl Monroe 4 16.67 12 50.00
Kareem Abdul-Jabbar 4 16.67 16 66.67
Oscar Robertson 4 16.67 20 83.33
Stanley 4 16.67 24 100.00
_______________________________________________________________________________
Training school example: Nested with covariates 2
Traditional ANCOVA
15:08 Monday, October 25, 2004
The GLM Procedure
Class Level Information
Class Levels Values
School 3 1 2 3
Instr 2 1 2
Number of observations 24
_______________________________________________________________________________
Training school example: Nested with covariates 3
Traditional ANCOVA
15:08 Monday, October 25, 2004
The GLM Procedure
Dependent Variable: Learn
Sum of
Source DF Squares Mean Square F Value Pr > F
Model 8 1448.111948 181.013993 32.37 <.0001
Error 15 83.888052 5.592537
Corrected Total 23 1532.000000
R-Square Coeff Var Root MSE Learn Mean
0.945243 15.76570 2.364855 15.00000
Source DF Type I SS Mean Square F Value Pr > F
x1 1 513.3577789 513.3577789 91.79 <.0001
x2 1 261.2204365 261.2204365 46.71 <.0001
x3 1 95.4069087 95.4069087 17.06 0.0009
School 2 106.5247571 53.2623785 9.52 0.0021
Instr 1 36.2982831 36.2982831 6.49 0.0223
School*Instr 2 435.3037834 217.6518917 38.92 <.0001
Source DF Type III SS Mean Square F Value Pr > F
x1 1 0.0658667 0.0658667 0.01 0.9150
x2 1 0.0315433 0.0315433 0.01 0.9411
x3 1 0.0003791 0.0003791 0.00 0.9935
School 2 248.1908971 124.0954485 22.19 <.0001
Instr 1 143.8713283 143.8713283 25.73 0.0001
School*Instr 2 435.3037834 217.6518917 38.92 <.0001
_______________________________________________________________________________
Training school example: Nested with covariates 4
Check some ANCOVA Interactions
15:08 Monday, October 25, 2004
The GLM Procedure
Class Level Information
Class Levels Values
School 3 1 2 3
Instr 2 1 2
Number of observations 24
_______________________________________________________________________________
Training school example: Nested with covariates 5
Check some ANCOVA Interactions
15:08 Monday, October 25, 2004
The GLM Procedure
Dependent Variable: Learn
Sum of
Source DF Squares Mean Square F Value Pr > F
Model 13 1500.100705 115.392362 36.17 <.0001
Error 10 31.899295 3.189929
Corrected Total 23 1532.000000
R-Square Coeff Var Root MSE Learn Mean
0.979178 11.90692 1.786037 15.00000
Source DF Type I SS Mean Square F Value Pr > F
x1 1 513.3577789 513.3577789 160.93 <.0001
x2 1 261.2204365 261.2204365 81.89 <.0001
x3 1 95.4069087 95.4069087 29.91 0.0003
School 2 106.5247571 53.2623785 16.70 0.0006
Instr 1 36.2982831 36.2982831 11.38 0.0071
School*Instr 2 435.3037834 217.6518917 68.23 <.0001
x1*School 2 45.1803418 22.5901709 7.08 0.0121
x1*Instr 1 2.7005761 2.7005761 0.85 0.3792
x1*School*Instr 2 4.1078399 2.0539199 0.64 0.5457
Source DF Type III SS Mean Square F Value Pr > F
x1 1 12.89766778 12.89766778 4.04 0.0721
x2 1 4.32737404 4.32737404 1.36 0.2712
x3 1 0.28081944 0.28081944 0.09 0.7728
School 2 1.17098878 0.58549439 0.18 0.8351
Instr 1 8.23324748 8.23324748 2.58 0.1392
School*Instr 2 3.33431131 1.66715565 0.52 0.6083
x1*School 2 4.02861991 2.01430996 0.63 0.5518
x1*Instr 1 5.43700043 5.43700043 1.70 0.2209
x1*School*Instr 2 4.10783988 2.05391994 0.64 0.5457
_______________________________________________________________________________
Training school example: Nested with covariates 6
Nested with covariates
15:08 Monday, October 25, 2004
The GLM Procedure
Class Level Information
Class Levels Values
School 3 1 2 3
Instr 2 1 2
Number of observations 24
_______________________________________________________________________________
Training school example: Nested with covariates 7
Nested with covariates
15:08 Monday, October 25, 2004
The GLM Procedure
Dependent Variable: Learn
Sum of
Source DF Squares Mean Square F Value Pr > F
Model 8 1448.111948 181.013993 32.37 <.0001
Error 15 83.888052 5.592537
Corrected Total 23 1532.000000
R-Square Coeff Var Root MSE Learn Mean
0.945243 15.76570 2.364855 15.00000
Source DF Type I SS Mean Square F Value Pr > F
x1 1 513.3577789 513.3577789 91.79 <.0001
x2 1 261.2204365 261.2204365 46.71 <.0001
x3 1 95.4069087 95.4069087 17.06 0.0009
School 2 106.5247571 53.2623785 9.52 0.0021
Instr(School) 3 471.6020665 157.2006888 28.11 <.0001
Source DF Type III SS Mean Square F Value Pr > F
x1 1 0.0658667 0.0658667 0.01 0.9150
x2 1 0.0315433 0.0315433 0.01 0.9411
x3 1 0.0003791 0.0003791 0.00 0.9935
School 2 248.1908971 124.0954485 22.19 <.0001
Instr(School) 3 471.6020665 157.2006888 28.11 <.0001