UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Textbook Examples
Applied Longitudinal Data Analysis: Modeling Change and Event Occurrence
by Judith D. Singer and John B. Willett
Chapter 4: Doing Data Analysis with the Multilevel Model for Change


Figure 4.1, page 77

proc greplay igout = work.gseg nofs;
  delete _all_;
run;
goptions reset=all noborder ftext=swiss htext=3 hby=0;
proc gplot data="c:\alda\alcohol1_pp" uniform ;
  where id in (4,14,23,32,41,56,65,82);
  by id;
  note justify=center 'ID #byval(ID)';  
  symbol color=black interpol=reg value=dot height=2 ;
  axis1 label=("AGE") order=(13 to 17 by 1) offset=(5) minor=none ;
  axis2 label=("Alcuse") order=(-1 to 4 by 1) minor=none;  
  plot alcuse*age / nolegend haxis=axis1 vaxis=axis2 noframe;
run;
goptions reset=all noborder hby=3 rotate=portrait hsize= 7in ;
proc greplay igout=work.gseg tc=sashelp.templt
             template=h4 nofs;
   treplay 1:1  2:2  3:3  4:4;
   treplay 1:5  2:6  3:7  4:8;
run;
quit;
proc greplay igout=work.gseg tc=sashelp.templt
             template=v2 nofs nobyline;
   treplay 1:template 2:templat1;
  run;
quit;


Figure 4.2, page 79. We will first present a simple-minded approach: no sub-sampling and no thickening the lines for coincident trajectories. The very much more complicated approach for sampling and adjusting the thickness of lines based on the number of coincidence of trajectories is presented afterwards.

proc greplay igout = work.fig42 nofs;
  delete _all_;
run;
*top 2 panels;
proc sort data='c:\alda\alcohol1_pp' ;
  by coa;
run;
goptions reset=global noborder ftext=titalic htext=2;
title justify = left height=1.5 move=(5, -5) 'ALCUSE';
axis1 label=("AGE") order=(14 to 16 by 1) minor=none color=black;
axis2 label=none order=(-1 to 4 by 1) minor=none color=black;
symbol1 color=black interpol=rl value=none height=.5 repeat=1000;
proc gplot data='c:\alda\alcohol1_pp' gout=fig42 uniform;
  by coa;
  plot alcuse*age=id / nolegend haxis=axis1 vaxis=axis2 noframe;
run;
quit;
*bottom 2 panels;
data alc1;
  set "c:\alda\alcohol1_pp" ;
   hipeer = (peer > 1.0175595);
run;
proc sort data=alc1 out=alc1;
  by hipeer;
run;
proc gplot data=alc1 gout=fig42;
  by hipeer;
  plot alcuse*age=id / nolegend haxis=axis1 vaxis=axis2 noframe;
run;
quit;
* show all 4 panels ;
goptions reset=all noborder hby=0 device = gif570 rotate=portrait ;
proc greplay igout=fig42 gout = fig42 nofs ; 
  tc sashelp.templt ; 
  template l2r2;
  treplay 1:1 2:3 3:2 4:4;
run;
quit;

Now let us try to incorporate the sampling idea and the adjusting the thickness of the lines based on the number of coincidence of trajectories. We are going to do only for variable coa.

a) Sampling issue

Because this is person-period data, each subject has multiple observations. The first step is to create a data set with one observation per subject. The random sample will be drawn from it and we merge it back with the original data to get all the other observations for each of the subjects. We will use proc surveyselect to create a subsample of size 32 from the whole data set.

proc sort data="c:\alda\alcohol1_pp" out=alc1;
  by id;
run;
data alcohol_1;
 set alc1;
   by id;
   if first.id then output;
run;
proc surveyselect data = alcohol_1 method = SRS rep = 1 
                  sampsize = 32 seed = 12345 out = alcohol_s;
  id _all_;
run;
data mysample;
  merge alc1 (in=frm1) alcohol_s (in=frm2);
  by id;
  if frm1 = frm2 = 1;
run;

b) Plot with different thickness

proc sort data = mysample;
  by coa id; 
proc reg data = mysample outest = t;
  by coa id;
  model alcuse = age;
run;
quit;
proc sql;
  create table t1 as
  select coa, intercept as b_int, age as b_age, count(id) as freq
  from t
  group by coa, intercept, age;
quit;

data ta_coa0 ta_coa1;
  length function $8;
  retain xsys ysys hsys '2';
   set t1 ;
   if coa = 0 then do;
   x = 14;
   y = b_int + b_age*x; 
   function = 'move';
   size = freq/2;
   output ta_coa0;
   x = 16;
   y = b_int + b_age*x; 
   function = 'draw';
   size = freq/4;
   output ta_coa0;
   end;
   if coa = 1 then do;
   x = 14;
   y = b_int + b_age*x; 
   function = 'move';
   size = freq/2;
   output ta_coa1;
   x = 16;
   y = b_int + b_age*x; 
   function = 'draw';
   size = freq/4;
   output ta_coa1;
   end;
run;

data ta_0;
  set ta_coa0;
   if freq = 9 ;
run;
data ta_1;
  set ta_coa1;
   if freq = 3 ;
run;

proc sort data = ta_0;
  by x;
run; 
proc sort data = ta_1;
  by x;
run; 
proc greplay igout = work.gseg nofs;
  delete _all_;
run;
goptions reset = all htext = 2 ftext = titalic;
axis1 order = (13 to 17 by 1) minor = none label=("AGE");
axis2 order = (-1 to 4 by 1)  minor = none label=("ALCUSE");
symbol i = join w=1.5 ;
proc gplot data = ta_0;
  title 'COA=0';
  plot y*x  / haxis = axis1 vaxis=axis2 anno=ta_coa0 noframe;
run;
quit;
proc gplot data = ta_1;
  title 'COA=1';
  plot y*x  / haxis = axis1 vaxis=axis2 anno=ta_coa1 noframe;
run;
quit;
goptions reset=all noborder hby=0 device = gif570 rotate=portrait ;
proc greplay  igout = work.gseg nofs ; 
  tc sashelp.templt ; 
  template h2;
  treplay 1:1 2:2;
run;
quit;

Table 4.1, pages 94-95

* Table 4.1 ;
title1 "Table 4.1: Alcohol use data (alcohol1_pp): Fitted multilevel models for change";
proc mixed data="c:\alda\alcohol1_pp" method=ml noclprint noinfo covtest;
  title2 "Model A";
  class id;
  model alcuse = /solution notest;
  random intercept/sub=id;

proc mixed data="c:\alda\alcohol1_pp" method=ml noclprint noinfo covtest;
  title2 "Model B";
  class id;
  model alcuse = age_14/solution notest;
  random intercept age_14/type=un sub=id;

proc mixed data="c:\alda\alcohol1_pp" method=ml noclprint noinfo covtest;
  title2 "Model C";
  class id;
  model alcuse = coa age_14 coa*age_14/solution notest;
  random intercept age_14/type=un sub=id;

proc mixed data="c:\alda\alcohol1_pp" method=ml noclprint noinfo covtest;
  title2 "Model D";
  class id;
  model alcuse = coa peer age_14 coa*age_14 peer*age_14 /solution notest;
  random intercept age_14/type=un sub=id;

proc mixed data="c:\alda\alcohol1_pp" method=ml noclprint noinfo covtest;
  title2 "Model E";
  class id;
  model alcuse = coa peer age_14 peer*age_14 /solution notest;
  random intercept age_14/type=un sub=id;

proc mixed data="c:\alda\alcohol1_pp" method=ml noclprint noinfo covtest;
  title2 "Model F";
  class id;
  model alcuse = coa cpeer age_14 cpeer*age_14 /solution notest;
  random intercept age_14/type=un sub=id;

proc mixed data="c:\alda\alcohol1_pp" method=ml noclprint noinfo covtest;
  title2 "Model G";
  class id;
  model alcuse = ccoa cpeer age_14 cpeer*age_14 /solution notest;
  random intercept age_14/type=un sub=id;
run;

Table 4.1: Alcohol use data (alcohol1_pp): Fitted multilevel models for change
Model A
                  Covariance Parameter Estimates

                                     Standard         Z
Cov Parm      Subject    Estimate       Error     Value        Pr Z
Intercept     ID           0.5639      0.1191      4.73      <.0001
Residual                   0.5617     0.06203      9.06      <.0001

           Fit Statistics
-2 Log Likelihood               670.2
AIC (smaller is better)         676.2
AICC (smaller is better)        676.3
BIC (smaller is better)         683.4

                   Solution for Fixed Effects

                         Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept      0.9220     0.09571      81       9.63      <.0001

Table 4.1: Alcohol use data (alcohol1_pp): Fitted multilevel models for change
Model B
                  Covariance Parameter Estimates

                                    Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      ID           0.6244      0.1481      4.22      <.0001
UN(2,1)      ID         -0.06844     0.07008     -0.98      0.3288
UN(2,2)      ID           0.1512     0.05647      2.68      0.0037
Residual                  0.3373     0.05268      6.40      <.0001

           Fit Statistics
-2 Log Likelihood               636.6
AIC (smaller is better)         648.6
AICC (smaller is better)        649.0
BIC (smaller is better)         663.1

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

                   Solution for Fixed Effects

                         Standard
Effect       Estimate       Error      DF    t Value    Pr > |t|
Intercept      0.6513      0.1051      81       6.20      <.0001
AGE_14         0.2707     0.06245      81       4.33      <.0001

Table 4.1: Alcohol use data (alcohol1_pp): Fitted multilevel models for change
Model C

                  Covariance Parameter Estimates

                                    Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      ID           0.4876      0.1278      3.81      <.0001
UN(2,1)      ID         -0.05934     0.06573     -0.90      0.3666
UN(2,2)      ID           0.1506     0.05639      2.67      0.0038
Residual                  0.3373     0.05268      6.40      <.0001

           Fit Statistics
-2 Log Likelihood               621.2
AIC (smaller is better)         637.2
AICC (smaller is better)        637.8
BIC (smaller is better)         656.5

  Null Model Likelihood Ratio Test

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

                   Solution for Fixed Effects

                          Standard
Effect        Estimate       Error      DF    t Value    Pr > |t|
Intercept       0.3160      0.1307      80       2.42      0.0179
COA             0.7432      0.1946      82       3.82      0.0003
AGE_14          0.2930     0.08423      80       3.48      0.0008
COA*AGE_14    -0.04943      0.1254      82      -0.39      0.6944


Table 4.1: Alcohol use data (alcohol1_pp): Fitted multilevel models for change
Model D
                  Covariance Parameter Estimates

                                    Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      ID           0.2409     0.09259      2.60      0.0046
UN(2,1)      ID         -0.00612     0.05500     -0.11      0.9115
UN(2,2)      ID           0.1391     0.05481      2.54      0.0056
Residual                  0.3373     0.05268      6.40      <.0001

           Fit Statistics
-2 Log Likelihood               588.7
AIC (smaller is better)         608.7
AICC (smaller is better)        609.6
BIC (smaller is better)         632.8

  Null Model Likelihood Ratio Test

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

                    Solution for Fixed Effects

                           Standard
Effect         Estimate       Error      DF    t Value    Pr > |t|
Intercept       -0.3165      0.1481      79      -2.14      0.0356
COA              0.5792      0.1625      82       3.56      0.0006
PEER             0.6943      0.1115      82       6.23      <.0001
AGE_14           0.4294      0.1137      79       3.78      0.0003
COA*AGE_14     -0.01403      0.1248      82      -0.11      0.9107
PEER*AGE_14     -0.1498     0.08564      82      -1.75      0.0840

Table 4.1: Alcohol use data (alcohol1_pp): Fitted multilevel models for change
Model E

                  Covariance Parameter Estimates

                                    Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      ID           0.2409     0.09259      2.60      0.0046
UN(2,1)      ID         -0.00614     0.05501     -0.11      0.9111
UN(2,2)      ID           0.1392     0.05481      2.54      0.0056
Residual                  0.3373     0.05268      6.40      <.0001

           Fit Statistics
-2 Log Likelihood               588.7
AIC (smaller is better)         606.7
AICC (smaller is better)        607.5
BIC (smaller is better)         628.4


  Null Model Likelihood Ratio Test

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

                    Solution for Fixed Effects

                           Standard
Effect         Estimate       Error      DF    t Value    Pr > |t|
Intercept       -0.3138      0.1461      79      -2.15      0.0348
COA              0.5712      0.1462      82       3.91      0.0002
PEER             0.6952      0.1113      82       6.25      <.0001
AGE_14           0.4247      0.1056      80       4.02      0.0001
PEER*AGE_14     -0.1514     0.08451      82      -1.79      0.0770

Table 4.1: Alcohol use data (alcohol1_pp): Fitted multilevel models for change
Model F

                  Covariance Parameter Estimates

                                    Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      ID           0.2409     0.09259      2.60      0.0046
UN(2,1)      ID         -0.00614     0.05501     -0.11      0.9111
UN(2,2)      ID           0.1392     0.05481      2.54      0.0056
Residual                  0.3373     0.05268      6.40      <.0001

           Fit Statistics
-2 Log Likelihood               588.7
AIC (smaller is better)         606.7
AICC (smaller is better)        607.5
BIC (smaller is better)         628.4

  Null Model Likelihood Ratio Test

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

                    Solution for Fixed Effects

                            Standard
Effect          Estimate       Error      DF    t Value    Pr > |t|
Intercept         0.3939      0.1035      79       3.80      0.0003
COA               0.5712      0.1462      82       3.91      0.0002
CPEER             0.6952      0.1113      82       6.25      <.0001
AGE_14            0.2706     0.06127      80       4.42      <.0001
CPEER*AGE_14     -0.1514     0.08451      82      -1.79      0.0770

Table 4.1: Alcohol use data (alcohol1_pp): Fitted multilevel models for change
Model G
      Covariance Parameter Estimates

                                    Standard         Z
Cov Parm     Subject    Estimate       Error     Value        Pr Z
UN(1,1)      ID           0.2409     0.09259      2.60      0.0046
UN(2,1)      ID         -0.00614     0.05501     -0.11      0.9111
UN(2,2)      ID           0.1392     0.05481      2.54      0.0056
Residual                  0.3373     0.05268      6.40      <.0001

           Fit Statistics
-2 Log Likelihood               588.7
AIC (smaller is better)         606.7
AICC (smaller is better)        607.5
BIC (smaller is better)         628.4

  Null Model Likelihood Ratio Test

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

                    Solution for Fixed Effects

                            Standard
Effect          Estimate       Error      DF    t Value    Pr > |t|
Intercept         0.6515     0.07979      79       8.17      <.0001
CCOA              0.5712      0.1462      82       3.91      0.0002
CPEER             0.6952      0.1113      82       6.25      <.0001
AGE_14            0.2706     0.06127      80       4.42      <.0001
CPEER*AGE_14     -0.1514     0.08451      82      -1.79      0.0770

Figure 4.3 on page 99. The first two plots are based on the output data sets created by proc mixed using the outpm option after the model statement. The most right panel has to be created manually, since we have to create a new variable indicating the level of PEER.

proc greplay igout = fig43 nofs;
  delete _all_;
run;
proc mixed data="c:\alda\alcohol1_pp" method=ml ;
  class id;
  model alcuse = age_14/outpm = mb;
  random intercept age_14/type=un sub=id;
run;
goptions reset=all noborder  ftext=simplex htext=1.5 hsize=3.3in;
axis1 label=("AGE") order=(13 to 17 by 1) minor=none ;
axis2 label=none order=(0 to 2 by 1) minor=none ;
symbol1 i=join value=none w=1.5;

proc gplot data=mb gout=fig43;
  title1 justify = center 'Model B'
         justify = center 'Unconditional growth model';
  title2 move=(5,-1) 'ALCUSE';
  plot pred *age / nolegend haxis=axis1 vaxis=axis2 noframe;
run;
quit;
proc mixed data="c:\alda\alcohol1_pp" method=ml noclprint noinfo covtest;
  class id;
  model alcuse = coa age_14 coa*age_14/solution notest outpm = mc;
  random intercept age_14/type=un sub=id;
run;

legend1 label=none value=(font=swiss)
        position=(bottom right inside) mode=share ;

proc gplot data=mc gout=fig43;
  title1 justify=center 'Model C'
         justify=center 'Uncontrolled effects of COA';
  title2 move=(5,-1) 'ALCUSE';
  plot pred*age=coa / legend = legend1 haxis=axis1 vaxis=axis2 noframe;
run;
quit;
data fig43r;
  do age = 14 to 16;
    do p = 0 to 1;
      do coa = 0 to 1;
	    if p = 0 then peer = .655; 
        if P = 1 then peer = 1.381;
        alcusehat = -.314 + .571*coa + .695*peer + .425*(age-14) + -.151*(age-14)*peer;
	    if coa = 0 and p = 0 then coapeer = "Low Peer , COA=0";
		if coa = 0 and p = 1 then coapeer = "High Peer, COA=0";
		if coa = 1 and p = 0 then coapeer = "Low Peer , COA=1";
		if coa = 1 and p = 1 then coapeer = "High Peer, COA=1";
        output;
      end;
	end;
  end;
run;

legend1 label=none value=(h=1 font=swiss)
        position=(bottom right inside) mode=share ;
proc gplot data=fig43r gout=fig43;
  title justify = center 'Model E'
       justify = center '"Final" model for the'
       justify = center 'controlled effects of COA';  
  title2 move=(5,-2) 'ALCUSE';
  plot alcusehat*age = coapeer/legend=legend1 haxis=axis1 vaxis=axis2 noframe;
run;
quit;
* Show all 3 panels together ;
goptions reset=all device=jpeg;
proc greplay igout=fig43 nofs ; 
  tc sashelp.templt ; 
  template h3;
  treplay 1:1 2:2 3:3 ;
run;
quit;

Table on the bottom of page 112.

proc sort data  = fig43r (where=(age<=15)) out=page112;
 by p coa age;
run;
data page112a;
   retain initial slope;
   set page112;
   lagp = lag(alcusehat);
   if age=14 then initial = alcusehat; 
   if age = 15 then slope = alcusehat - lagp;
   drop lagp age;
   if age = 15;
run;
proc sort data = page112a;
 by p coa;

proc print data = page112a ;
 id coapeer;
 var initial slope;
run;
    coapeer         initial     slope
Low Peer , COA=0    0.14123    0.32610
Low Peer , COA=1    0.71223    0.32610
High Peer, COA=0    0.64580    0.21647
High Peer, COA=1    1.21680    0.21647

Test of equation 4.18 on page 123 using model F.

proc mixed data="c:\alda\alcohol1_pp" method=ml;
  title2 "Model F";
  class id;
  model alcuse = coa cpeer age_14 cpeer*age_14 /solution chisq ;
  random intercept age_14/type=un sub=id;
  contrast 'Equation 4.18' intercept 1, age_14 1/ chisq ;
run;
The Mixed Procedure
                                   Contrasts
                  Num     Den
Label              DF      DF    Chi-Square    F Value      Pr > ChiSq    Pr > F
Equation 4.18       2      80         51.03      25.51          <.0001    <.0001

Figure 4.4 on page 130.

proc sort data = 'c:\alda\alcohol1_pp' out=fig4_4;
 by id;
run;
proc reg data = fig4_4 outest=est;
   by id;
  model alcuse = age_14;
run;
quit;
data fig4_4l;
  merge est(rename=(age_14=pred)) fig4_4;
  by id;
run;

proc corr data = fig4_4l nosimple noprob;
  var coa peer;
  with intercept pred;
run;
The CORR Procedure
                    COA          PEER
Intercept       0.38867       0.57808
pred           -0.04349      -0.19404
proc greplay igout=fig4_4 nofs;
  delete _all_;
run;

goptions reset = all noborder ftext=titalic htext=3 ;
axis1 order = (0 to 1 by 1) offset = (6,6) minor=none;
axis2 order = (-1 to 4 by 1) label=none offset = (2,0) minor=none;
symbol i = none v=dot ;

proc gplot data = fig4_4l gout=fig4_4;
  title1 move=(4,-1) font=greek h=2.75 'p'
         move=(6,-.5) h=1.7 font=simplex '0'
         move=(18, -0) h=2.5 'r=.39';
  plot intercept*coa /noframe vref=0 haxis=axis1 vaxis=axis2;
run;
quit;
axis2 order = (-1 to 2 by 1) label = none offset = (2,0) minor=none;
proc gplot data = fig4_4l gout=fig4_4;
  title1 move=(4,-1) font=greek h=2.75 'p'
         move=(6,-.5) h=1.7 font=simplex '1'
         move=(18, -0) h=2.5 'r=-0.04';
  plot pred*coa /noframe vref=0 haxis=axis1 vaxis=axis2;
run;
quit;
axis1 order = (0 to 3 by 1) offset = (6,6) minor=none;
axis2 order = (-1 to 4 by 1) label=none offset = (2,0) minor=none;
proc gplot data = fig4_4l gout=fig4_4;
  title1 move=(4,-1) font=greek h=2.75 'p'
         move=(6,-.5) h=1.7 font=simplex '0'
         move=(18, -0) h=2.5 'r=.58';
  plot intercept*peer /noframe vref=0 haxis=axis1 vaxis=axis2;
run;
quit;

axis2 order = (-1 to 2 by 1) label=none offset = (2,0) minor=none;
proc gplot data = fig4_4l gout=fig4_4;
  title1 move=(4,-1) font=greek h=2.75 'p'
         move=(6,-.5) h=1.7 font=simplex '1'
         move=(18, -0) h=2.5 'r=-0.19';
  plot pred*peer /noframe vref=0 haxis=axis1 vaxis=axis2;
run;
quit;
goptions reset=all device=jpeg ;
proc greplay igout=fig4_4 nofs ; 
  tc sashelp.templt ; 
  template l2r2;
  treplay 1:1 2:2 3:3 4:4 ;
run;
quit;


Figure 4.5 on page 131.

proc mixed data="c:\alda\alcohol1_pp" covtest method=ml;
  title2 "Model F";
  class id;
  model alcuse = coa cpeer age_14 cpeer*age_14 / outp=fig4_5 solution chisq ;
  random intercept age_14/type=un sub=id solution;
  ods output SolutionR = fig4_5a;
run;
Part 1: Left upper one:
goptions reset = all device=jpeg;
symbol v=dot;
proc univariate data = fig4_5 noprint;
  var resid;
  qqplot /vref=0 ;
run;

Part 2: Left middle one:

proc univariate data = fig4_5a noprint;
  where effect = "Intercept";
  var estimate;
  qqplot /vref=0 normal;
run;

Part 3: Left lower one:

proc univariate data = fig4_5a noprint;
  where effect = "AGE_14";
  var estimate;
  qqplot /vref=0 ;
run;

Part 4: Right upper one:

proc stdize data = fig4_5 out=fig4_5r;
  var resid;
run;
goptions reset = all;
symbol i = none v=dot;
proc gplot data = fig4_5r;
  plot resid*id /vref=0 vminor=0 hminor=0 ;
run;
quit;

Part 5: Right middle one:

proc stdize data = fig4_5a out=fig4_5rm (rename=(estimate = int));
 where effect = "Intercept";
  var estimate;
run;
goptions reset = all device=jpeg ;
symbol i = none v=dot;
proc gplot data = fig4_5rm;
  format int 3.0;
  plot int*id /vref=0 vminor=0 hminor=0 ;
run;
quit;

Part 6: Right lower one:

proc stdize data = fig4_5a out=fig4_5rm (rename=(estimate=age));
 where effect = "AGE_14";
  var estimate;
run;
goptions reset = all device=jpeg;
symbol i = none v=dot;
proc gplot data = fig4_5rm;
  format age 3.0;
  plot age*id /vref=0 vminor=0 hminor=0 ;
run;
quit;

Figure 4.6 on page 133.

Part 1: Left upper plot:

goptions reset = all device=jpeg;
symbol v=dot;
axis1 order = (13 to 17 by 1) minor = none;
axis2 order = (-2 to 2 by 1) minor = none;
proc gplot data = fig4_5 ;
  plot resid*age /haxis=axis1 vaxis=axis2 vref = 0;
run;
quit;

Part 2: Left middle plot:

proc sort data = fig4_a;
  by id;
proc sort data = "c:\alda\alcohol1_pp";
  by id;
run;
data fig4_6int;
  merge fig4_5a (where=(effect="Intercept"))
        "c:\alda\alcohol1_pp";
  by id;
run;
goptions reset = all device = jpeg;
symbol i = none v=dot;
axis1 order = (0 1) offset =(10,10) minor = none;
axis2 order = (-1 to 1 by 1) label=('Int') minor = none;
proc gplot data = fig4_6int;
  format estimate 3.0;
  plot estimate*coa /haxis=axis1 vaxis = axis2 vref=0 ;
run;
quit;

Part 3: Left lower plot:

data fig4_6age;
  merge fig4_5a (where=(effect="AGE_14"))
        "c:\alda\alcohol1_pp";
  by id;
run;

axis1 order = (0 1) offset =(10,10) minor = none;
axis2 order = (-1 to 1 by 1) label=('AGE') minor = none;
proc gplot data = fig4_6age;
  format estimate 3.0;
  plot estimate*coa /haxis=axis1 vaxis = axis2 vref=0 ;
run;
quit;

Part 4: Right middle plot:

axis1 order = (0 to 3 by 1) offset =(2,2) minor = none;
axis2 order = (-1 to 1 by 1) label=('Int') minor = none;
proc gplot data = fig4_6int;
  format estimate 3.0;
  plot estimate*peer /haxis=axis1 vaxis = axis2 vref=0 ;
run;
quit;

Part 5: Right lower plot:

axis1 order = (0 to 3 by 1) offset =(2,2) minor = none;
axis2 order = (-1 to 1 by 1) label=('AGE') minor = none;
proc gplot data = fig4_6age;
  format estimate 3.0;
  plot estimate*peer /haxis=axis1 vaxis = axis2 vref=0 ;
run;
quit;


Figure 4.7 on page 136.

proc mixed data="c:\alda\alcohol1_pp" covtest method=ml;
  title2 "Model F";
  class id;
  model alcuse = coa cpeer age_14 cpeer*age_14 
		/outp=fig4_7p outpm = fig4_7pm  solution chisq ;
  random intercept age_14/type=un sub=id solution;
run;
proc sort data = fig4_7p; 
  by id;
proc sort data = fig4_7pm;
  by id;
run;
data fig4_7;
  merge fig4_7p (rename = (pred=p)) fig4_7pm (rename=(pred=pm));
  by id;
  keep age id p pm alcuse;
  where id in (4,14,23,32,41,56,65,82);
run;
goptions reset = all noborder ftext=swiss htext=2 hby=0;
proc greplay igout = work.gseg nofs;
  delete _all_;
run;
symbol1 i=r value =dot  color = black line= 4 repeat=1 ;
symbol2 i= join line= 1 w=3 color = blue value =none repeat=1;
symbol3 i = join l= 1 w=2 color = red value =none repeat=1;
axis1 order = (13 to 17 by 1) minor = none;
axis2 order = (-1 to 4 by 1) minor = none;
proc gplot data = fig4_7 uniform  ;
  by id;
  plot alcuse*age p*age
       pm*age /haxis=axis1 vaxis=axis2 overlay noframe;
run;
quit;
goptions reset = all device=jpeg;
proc greplay igout=work.gseg tc=sashelp.templt
             template=h4 nofs;
   treplay 1:1  2:2  3:3  4:4;
   treplay 1:5  2:6  3:7  4:8;
run;
quit;
proc greplay igout=work.gseg tc=sashelp.templt
             template=v2 nofs nobyline;
   treplay 1:template 2:templat1;
  run;
quit;


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


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