Ordenes Sas Littell 2006

Embed Size (px)

Citation preview

  • 7/31/2019 Ordenes Sas Littell 2006

    1/10

    *-------------------------------------------------------------------*//*

    *//* SAS for Mixed Models, Second Edition

    *//* by Ramon C. Littell, George A. Milliken, Walter W. Stroup,

    *//* Russell D. Wolfinger, Oliver Schabenberger*//* Copyright (c) 2006 by SAS Institute Inc., Cary, NC, USA

    *//* SAS Publications order 1-59047-500-3

    *//*

    *//*-------------------------------------------------------------------

    *//*

    */

    /* This material is provided "as is" by SAS Institute Inc. There*//* are no warranties, expressed or implied, as to merchantability or

    *//* fitness for a particular purpose regarding the materials or code

    *//* contained herein. The Institute is not responsible for errors

    *//* in this material as it now exists or will exist, nor does the

    *//* Institute provide technical support for it.

    *//*

    *//*-------------------------------------------------------------------

    *//* Date Last Updated: 31JAN06

    *//*-------------------------------------------------------------------

    *//* Questions or problem reports concerning this material may be

    *//* addressed to the authors:

    *//*

    *//* SAS Institute Inc.

    *//* SAS Press

    *//* Attn: Ramon C. Littell, George A. Milliken, Walter W. Stroup,

    *//* Russell D. Wolfinger, Oliver Schabenberger

    *//* SAS Campus Drive

    *//* Cary, NC 27513

    *//*

    *//* If you prefer, you can send e-mail to: [email protected]

    */

  • 7/31/2019 Ordenes Sas Littell 2006

    2/10

    /* Use this for subject field:*//* Comments for Ramon C. Littell, George A. Milliken,

    *//* Walter W. Stroup, Russell D. Wolfinger, Oliver Schabenberger

    */

    /**//*-------------------------------------------------------------------

    */

    /*-------------------------------------------------------*//*---Notes ---*//*--- ---*//*---This file contains the SAS code for SAS for ---*//*---Mixed Models, Second Edition. ---*//*---To run the code for the book successfully, ---*//*---you need the following ---*/

    /*--- ---*//*--- 1) SAS 9.1 (or 9.1.2, 9.1.3) with the modules ---*//*--- SAS/BASE ---*//*--- SAS/STAT ---*//*--- SAS/GRAPH ---*//*--- SAS/IML (for Chapter 12 only) ---*//*--- licensed and installed ---*//*--- ---*//*--- 2) In SAS 9.1, to run examples that contain ---*//*--- PROC GLIMMIX code, you need to download ---*//*--- PROC GLIMMIX from www.sas.com/statistics ---*//*--- and install it. PROC GLIMMIX in SAS 9.1 ---*//*--- requires a standalone installation of SAS ---*//*--- on the 32-bit Windows platform ---*//*--- ---*//*---The code is organized by chapters. ---*//*--- ---*//*---Many programs make use of the ODS SELECT state- ---*//*---ment in order to reduce the procedure output ---*//*---to what is shown in the book. For example, ---*//*--- ---*//*--- Output 4.21 ---*//*--- proc mixed data=variety_eval; ---*//*--- class block type dose; ---*//*--- model y=type logdose(type) ld_sq /noint ---*//*--- ddfm=satterth solution; ---*//*--- random block block*dose; ---*//*--- ods select SolutionF; ---*//*--- run; ---*//*--- ---*//*---To see the full output of the procedure, ---*//*---remove the ODS SELECT statements. ---*//*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---CHAPTER 5: Analysis of Repeated Measures Data ---*//*-------------------------------------------------------*/

    /*-------------------------------------------------------*/

    /*---Data Set 5.2 Respiratory Ability ---*/data FEV1;

  • 7/31/2019 Ordenes Sas Littell 2006

    3/10

    input patient basefev1 fev11h fev12h fev13h fev14h fev15hfev16h fev17h fev18h drug $;

    datalines;201 2.46 2.68 2.76 2.50 2.30 2.14 2.40 2.33 2.20 a202 3.50 3.95 3.65 2.93 2.53 3.04 3.37 3.14 2.62 a203 1.96 2.28 2.34 2.29 2.43 2.06 2.18 2.28 2.29 a

    204 3.44 4.08 3.87 3.79 3.30 3.80 3.24 2.98 2.91 a205 2.80 4.09 3.90 3.54 3.35 3.15 3.23 3.46 3.27 a206 2.36 3.79 3.97 3.78 3.69 3.31 2.83 2.72 3.00 a207 1.77 3.82 3.44 3.46 3.02 2.98 3.10 2.79 2.88 a208 2.64 3.67 3.47 3.19 2.19 2.85 2.68 2.60 2.73 a209 2.30 4.12 3.71 3.57 3.49 3.64 3.38 2.28 3.72 a210 2.27 2.77 2.77 2.75 2.75 2.71 2.75 2.52 2.60 a211 2.44 3.77 3.73 3.67 3.56 3.59 3.35 3.32 3.18 a212 2.04 2.00 1.91 1.88 2.09 2.08 1.98 1.70 1.40 a214 2.77 3.36 3.42 3.28 3.30 3.31 2.99 3.01 3.08 a215 2.96 4.31 4.02 3.38 3.31 3.46 3.49 3.38 3.35 a216 3.11 3.88 3.92 3.71 3.59 3.57 3.48 3.42 3.63 a217 1.47 1.97 1.90 1.45 1.45 1.24 1.24 1.17 1.27 a

    218 2.73 2.91 2.99 2.87 2.88 2.84 2.67 2.69 2.77 a219 3.25 3.59 3.54 3.17 2.92 3.48 3.05 3.27 2.96 a220 2.73 2.88 3.06 2.75 2.71 2.83 2.58 2.68 2.42 a221 3.30 4.04 3.94 3.84 3.99 3.90 3.89 3.89 2.98 a222 2.85 3.38 3.42 3.28 2.94 2.96 3.12 2.98 2.99 a223 2.72 4.49 4.35 4.38 4.36 3.77 4.23 3.83 3.89 a224 3.68 4.17 4.30 4.16 4.07 3.87 3.87 3.85 3.82 a232 2.49 3.73 3.51 3.16 3.26 3.07 2.77 2.92 3.00 a

    201 2.30 3.41 3.48 3.41 3.49 3.33 3.20 3.07 3.15 c202 2.91 3.92 4.02 4.04 3.64 3.29 3.10 2.70 2.69 c203 2.08 2.52 2.44 2.27 2.23 2.01 2.26 2.34 2.44 c204 3.02 4.43 4.30 4.08 4.01 3.62 3.23 2.46 2.97 c205 3.26 4.55 4.58 4.44 4.04 4.33 3.87 3.75 3.81 c206 2.29 4.25 4.37 4.10 4.20 3.84 3.43 3.79 3.74 c207 1.96 3.00 2.80 2.59 2.42 1.61 1.83 1.21 1.50 c208 2.70 4.06 3.98 4.06 3.93 3.61 2.91 2.07 2.67 c209 2.50 4.37 4.06 3.68 3.64 3.17 3.37 3.20 3.25 c210 2.35 2.83 2.79 2.82 2.79 2.80 2.76 2.64 2.69 c211 2.34 4.06 3.68 3.59 3.27 2.60 2.72 2.22 2.68 c212 2.20 2.82 1.90 2.57 2.30 1.67 1.90 2.07 1.76 c214 2.78 3.18 3.13 3.11 2.97 3.06 3.27 3.24 3.33 c215 3.43 4.39 4.63 4.19 4.00 4.01 3.66 3.47 3.22 c216 3.07 3.90 3.98 4.09 4.03 4.07 3.56 3.83 3.75 c217 1.21 2.31 2.19 2.21 2.09 1.75 1.72 1.80 1.36 c218 2.60 3.19 3.18 3.15 3.14 3.08 2.96 2.97 2.85 c219 2.61 3.54 3.45 3.25 3.01 3.07 2.65 2.47 2.55 c220 2.48 2.99 3.02 3.02 2.94 2.69 2.66 2.68 2.70 c221 3.73 4.37 4.20 4.17 4.19 4.07 3.86 3.89 3.89 c222 2.54 3.26 3.39 3.27 3.20 3.32 3.09 3.25 3.15 c223 2.83 4.72 4.97 4.99 4.96 4.95 4.82 4.56 4.49 c224 3.47 4.27 4.50 4.34 4.00 4.11 3.93 3.68 3.77 c232 2.79 4.10 3.85 4.27 4.01 3.78 3.14 3.94 3.69 c201 2.14 2.36 2.36 2.28 2.35 2.31 2.62 2.12 2.42 p202 3.37 3.03 3.02 3.19 2.98 3.01 2.75 2.70 2.84 p203 1.88 1.99 1.62 1.65 1.68 1.65 1.85 1.96 1.30 p204 3.10 3.24 3.37 3.54 3.31 2.81 3.58 3.76 3.05 p205 2.91 3.35 3.92 3.69 3.97 3.94 3.63 2.92 3.31 p206 2.29 3.04 3.28 3.17 2.99 3.31 3.21 2.98 2.82 p207 2.20 2.46 3.22 2.65 3.02 2.25 1.50 2.37 1.94 p

    208 2.70 2.85 2.81 2.96 2.69 2.18 1.91 2.21 1.71 p209 2.25 3.45 3.48 3.80 3.60 2.83 3.17 3.22 3.13 p

  • 7/31/2019 Ordenes Sas Littell 2006

    4/10

    210 2.48 2.56 2.52 2.67 2.60 2.68 2.64 2.65 2.61 p211 2.12 2.19 2.44 2.41 2.55 2.93 3.08 3.11 3.06 p212 2.37 2.14 1.92 1.75 1.58 1.51 1.94 1.84 1.76 p214 2.73 2.57 3.08 2.62 2.91 2.71 2.39 2.42 2.73 p215 3.15 2.90 2.80 3.17 2.39 3.01 3.22 2.75 3.14 p216 2.52 3.02 3.21 3.17 3.13 3.38 3.25 3.29 3.35 p

    217 1.48 1.35 1.15 1.24 1.32 0.95 1.24 1.04 1.16 p218 2.52 2.61 2.59 2.77 2.73 2.70 2.72 2.71 2.75 p219 2.90 2.91 2.89 3.01 2.74 2.71 2.86 2.95 2.66 p220 2.83 2.78 2.89 2.77 2.77 2.69 2.65 2.84 2.80 p221 3.50 3.81 3.77 3.78 3.90 3.80 3.78 3.70 3.61 p222 2.86 3.06 2.95 3.07 3.10 2.67 2.68 2.94 2.89 p223 2.42 2.87 3.08 3.02 3.14 3.67 3.84 3.55 3.75 p224 3.66 3.98 3.77 3.65 3.81 3.77 3.89 3.63 3.74 p232 2.88 3.04 3.00 3.24 3.37 2.69 2.89 2.89 2.76 p

    ;/*-------------------------------------------------------*/

    /*---convert data to univariate form ---*/

    data fev1uni; set fev1;array f{8} fev1:;

    do hour=1 to 8; fev = f{hour}; output; end;drop fev1:;

    run;data fev1uni; set fev1uni; rename fev=fev1; run;proc sort data=fev1uni; by drug hour;run;

    /*-------------------------------------------------------*//*---Output 5.1, Output 5.2, Output 5.3, Output 5.4 ---*//*---Output 5.5, Output 5.6 ---*/

    proc mixed data=fev1uni;class drug patient hour;model fev1=drug hour drug*hour;repeated hour / subject=patient(drug) type=un r rcorr;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.7, Output 5.8, Output 5.9, Output 5.10 ---*/

    proc mixed data=fev1uni;class drug patient hour;model fev1=drug hour drug*hour;repeated hour / sub=patient(drug) type=cs r rcorr;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.11 ---*/

    proc mixed data=fev1uni;class drug patient hour;model fev1=drug hour drug*hour;repeated hour / sub=patient(drug) type=un;estimate 'drug a-c at hour 1'

    drug 1 -1drug*hour 1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0;

    estimate 'hour 1-2 drug a'

    hour 1 -1drug*hour 1 -1 0 0 0 0 0 0;

  • 7/31/2019 Ordenes Sas Littell 2006

    5/10

    ods select Estimates;run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.12 ---*/

    proc mixed data=fev1uni;class drug patient hour;model fev1=drug hour drug*hour;repeated hour / sub=patient(drug) type=cs;estimate 'drug a-c at hour 1'

    drug 1 -1drug*hour 1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0

    /e ;estimate 'hour 1-2 drug a'

    hour 1 -1drug*hour 1 -1 0 0 0 0 0 0;

    ods select Estimates;run;

    /*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.13 ---*//*---Figure 5.3 ---*/

    proc mixed data=fev1uni;class drug patient hour;model fev1 = drug|hour;repeated / type=un subject=patient(drug) sscp rcorr;ods output covparms=cov rcorr=corr;

    run;

    data times;do time1=1 to 8;do time2=1 to time1;dist=time1-time2;output;

    end;end;

    run;

    data covplot; merge times cov;run;

    proc print data=covplot(where=((time1

  • 7/31/2019 Ordenes Sas Littell 2006

    6/10

    mode =protectposition=(top right inside);

    symbol1 color=black interpol=join line=1 value=square;symbol2 color=black interpol=join line=2 value=circle;symbol3 color=black interpol=join line=20 value=triangle;symbol4 color=black interpol=join line=3 value=plus;

    symbol5 color=black interpol=join line=4 value=star;symbol6 color=black interpol=join line=5 value=dot;symbol7 color=black interpol=join line=6 value=_;symbol8 color=black interpol=join line=10 value==;

    proc gplot data=covplot;plot estimate*dist=time2 / noframe

    vaxis = axis1haxis = axis2legend = legend1;

    run;

    /*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.14 ---*/

    proc mixed data=fev1uni;class drug patient hour;model fev1 = drug hour drug*hour;repeated hour / sub=patient(drug) type=ar(1);ods select CovParms;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.15 ---*//*---Output 5.17 ---*/

    proc mixed data=fev1uni;class drug patient hour;model fev1 = drug hour drug*hour;repeated hour / sub=patient(drug) type=ar(1);random patient(drug);ods select CovParms FitStatistics;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.16 ---*//*---Output 5.18 ---*/

    proc mixed data=fev1uni;class drug patient hour;model fev1 = drug hour drug*hour;repeated hour / sub=patient(drug) type=toep;ods select CovParms FitStatistics;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.19 ---*/

    proc mixed data=fev1uni;class drug hour patient;model fev1 = basefev1 drug|hour;random patient(drug);

    repeated hour / sub=patient(drug) type=ar(1);ods select Tests3;

  • 7/31/2019 Ordenes Sas Littell 2006

    7/10

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.20 ---*/

    proc mixed data=fev1uni;

    class drug hour patient;model fev1 = basefev1 drug|hour / ddfm=kr;random patient(drug);repeated / type=ar(1) subject=patient(drug);ods select Tests3;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Figure 5.6 ---*/

    ods html;ods graphics on;proc glimmix data=fev1uni;

    class drug hour patient;model fev1 = drug|hour basefev1 / ddfm=kr;random patient(drug);random _residual_ / type=ar(1) subject=patient(drug);lsmeans drug*hour / plot=meanplot(sliceby=drug join);nloptions tech=nrridg;

    run;ods graphics off;ods html close;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.21 ---*/

    proc mixed data=fev1uni;class drug hour patient;model fev1 = basefev1 drug|hour / ddfm=kr;random patient(drug);repeated / type=ar(1) subject=patient(drug);lsmeans drug*hour/ diff slice=hour;contrast 'hr=1 vs hr=8 x P vs TRT'

    drug*hour 1 0 0 0 0 0 0 -11 0 0 0 0 0 0 -1

    -2 0 0 0 0 0 0 2;contrast 'hr=1 vs hr=8 x A vs C'

    drug*hour 1 0 0 0 0 0 0 -1-1 0 0 0 0 0 0 1 0;

    ods select Contrasts Slices;run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Simple effect differences with MIXED ---*//*---Output not shown ---*/

    proc mixed data=fev1uni;class drug hour patient;model fev1 = basefev1 drug|hour / ddfm=kr;random patient(drug);repeated / type=ar(1) subject=patient(drug);lsmeans drug*hour/ diff slice=hour;

    ods exclude lsmeans diffs;ods output diffs=dhdiff;

  • 7/31/2019 Ordenes Sas Littell 2006

    8/10

    run;data smpleff;set dhdiff;if drug=_drug or hour=_hour;

    proc print data=smpleff;run;

    /*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.22 ---*/

    ods select SliceDiffs;proc glimmix data=fev1uni;

    class drug hour patient;model fev1 = drug|hour basefev1 / ddfm=kr;random patient(drug);random _residual_ / type=ar(1) subject=patient(drug);lsmeans drug*hour / slicediff=(hour);nloptions tech=nrridg;

    run;

    /*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.23 ---*/

    ods select LSMEstimates LSMFtest;proc glimmix data=fev1uni;

    class drug hour patient;model fev1 = drug|hour basefev1 / ddfm=kr;random patient(drug);random _residual_ / type=ar(1) subject=patient(drug);nloptions tech=nrridg;lsmestimate Drug*Hour

    1 -1,

    1 0 -1,1 0 0 -1,1 0 0 0 -1,1 0 0 0 0 -1,1 0 0 0 0 0 -1,1 0 0 0 0 0 0 -1 / Ftest;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*/data fev1regr;

    set fev1uni;h=hour;h2=hour*hour;

    run;

    proc mixed data=fev1regr;class drug hour patient;model fev1=basefev1 drug h h2 hour

    drug*h drug*h2 drug*hour/htype=1;random patient(drug);repeated / type=ar(1) subject=patient(drug);

    run;

    /*-------------------------------------------------------*//*---Output 5.24 ---*/

    proc mixed data=fev1regr noprofile;class drug hour patient;

  • 7/31/2019 Ordenes Sas Littell 2006

    9/10

    model fev1 = basefev1 drug h h2 hourdrug*h drug*h2 drug*hour/htype=1;

    random patient(drug);repeated / type=ar(1) subject=patient(drug);parms (0.1848) (0.08309) (0.5401) / noiter;ods select Tests1;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.25 ---*/

    proc mixed data=fev1regr;class drug patient;model fev1=basefev1 drug h(drug) / noint solution

    ddfm=kr htype=1;random patient(drug);repeated / type=ar(1) subject=patient(drug);ods select SolutionF;

    run;

    /*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.26 ---*/

    proc mixed data=fev1regr;class drug patient;model fev1=basefev1 drug h(drug) / noint solution

    ddfm=kr htype=1;random patient(drug);repeated / type=ar(1) subject=patient(drug);contrast 'drug a vs c intercept' drug 1 -1 0;contrast 'drug a vs c slope' h(drug) 1 -1 0;ods select Contrasts;

    run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Data Set 5.4, Heart Rates ---*/

    data hr;input patient drug$ basehr hr1 hr5 hr15 hr30 hr1h;array hra{5} hr1 hr5 hr15 hr30 hr1h;do i = 1 to 5;

    if (i = 1) then minute = 1/60;else if (i = 2) then minute = 5;else if (i = 3) then minute = 15;else if (i = 4) then minute = 30;else minute = 60;time = minute;hours = minute / 60;hours1 = hours;HR = hra{i};output;

    end;drop i hr1 hr5 hr15 hr30 hr1h;datalines;

    201 p 92 76 84 88 96 84202 b 54 58 60 60 60 64203 p 84 86 82 84 86 82204 a 72 72 68 68 78 72205 b 80 84 84 96 92 72

    206 p 68 72 68 68 64 62207 a 100 104 100 92 92 68

  • 7/31/2019 Ordenes Sas Littell 2006

    10/10

    208 a 60 60 58 56 50 56209 a 88 104 88 88 78 84210 b 92 82 82 76 82 80211 b 88 80 84 80 80 78212 p 102 86 86 96 86 88214 a 84 92 100 88 88 80

    215 b 104 100 96 88 92 84216 a 92 80 72 64 68 64217 p 92 88 84 76 88 84218 a 72 84 78 80 80 76219 b 72 100 92 84 88 80220 p 80 80 80 78 80 78221 p 72 68 76 72 72 68222 b 88 88 98 98 96 88223 b 88 88 96 88 88 80224 p 88 78 84 64 68 64232 a 78 72 72 78 80 68;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Figure 5.7 ---*/

    symbol i=join r=24 c=black v=none;proc gplot data=hr;

    plot hr*minute=patient / nolegend vminor=1 hminor=0;run;/*-------------------------------------------------------*/

    /*-------------------------------------------------------*//*---Output 5.27 ---*/

    proc mixed data=hr order=data;class drug hours patient;model hr = drug|hours basehr;repeated hours / type=sp(pow)(hours1) sub=patient r rcorr;random int / subject=patient v;

    run;/*-------------------------------------------------------*/