libname rus 'C:\1datalap\papers\walls_sork'; *%let workdir=C:\1datalap\papers\walls_sork; run; /*Derived from code Developed by Robert Weiss for Biostat 236: for forthcoming text on longitudinal data, from material and macros on Michael Friendly's web site, and from code from Singer and Willett's ALDA web site. Download these macros and place either your work folder that you call with a let statement %let workdir=C:\Documents and Settings\Leanne\DESKTOP\B236; To find your work folder location go to work library and right click, choose properties; or put them in a folder where you data is for this analysis. boxanno.sas gdispla.sas gensym.sas scatmat.sas 1. Profile plots: Overall and by covariate value 2. Repeated box plots over time 3. Empirical estimate plot (mean +/- 2sd or +/- 2se error bars); overall and by covariate 4. Correlation matrix 5. Scatterplot matrix*/ /*1. Profile plot of Adolescent Data*/ /* for whole sample*/ proc sort data=rus.ruswork1; by occasion; run; goptions cback=white; axis1 minor=none label=( angle=90 'Motivation' ); axis2 minor=none label=('Occasion'); *IT IS VERY IMPORTANT FOR CORRECTLY MAKING THE PROFILE PLOT TO SET r= (WHICH STANDS FOR REPEAT) TO A NUMBER AT LEAST AS LARGE AS THE NUMBER OF SUBJECTS; symbol1 i=join v=circle r=73 color=black; title 'Profile Plot'; proc gplot uniform data=rus.ruswork1; plot motiv*occasion=id /vaxis=axis1 haxis=axis2 nolegend; run; quit; /*set up by a covariate of interest*/ proc sort data=rus.ruswork1; by grade; run; goptions cback=white; axis1 minor=none label=( angle=90 'Motivation' ); axis2 minor=none label=('Occasion'); *IT IS VERY IMPORTANT FOR CORRECTLY MAKING THE PROFILE PLOT TO SET r= (WHICH STANDS FOR REPEAT) TO A NUMBER AT LEAST AS LARGE AS THE NUMBER OF SUBJECTS; symbol1 i=join v=circle r=73 color=black; title 'Profile Plot'; proc gplot uniform data=rus.ruswork1; plot motiv*occasion=id /vaxis=axis1 haxis=axis2 nolegend; by grade; run; quit; /*2. Repeated box plots*/ proc sort data=rus.ruswork1; by occasion; run; proc boxplot data=rus.ruswork1; plot motiv*occasion; title 'Box plots of Russian Adol. Motiv by Occasion'; run; proc sort data=rus.ruswork1; by lesson; run; proc boxplot data=rus.ruswork1; plot motiv*lesson; title 'Box plots of Russian Adol. Motiv by Lesson'; run; quit; /*3. Empirical summary plot (mean +/- /*2sd and also +/- 2se error bars)*/ proc sort data=rus.ruswork1; by occasion; run; axis1 minor=none label=( angle=90 'Average Motivation' ); *NOTE:IN THE I= part of the symbol statement, std=standard deviations 2=#ofSD's J=provide line throught means t=add tops and bottoms to each line; symbol1 i=std2jt v=none color=red r=1; title 'Average Motivation +/- 2 SD'; proc gplot data=rus.ruswork1; plot motiv*occasion / vaxis=axis1; run; quit; *WE MODIFY THE SYMBOL STATEMENT BY INSERTING M, SPECIFYING SE of MEAN, rather than SD; symbol1 i=std2mjt v=none color=red r=1; title 'Empirical Summary Plot +/- 2 SE'; proc gplot data=rus.ruswork1; plot motiv*occasion / vaxis=axis1; run; quit; /*4. Empirical correlation matrix and empirical variances by time. Plot variances over time, and plot correlations in a correlogram.*/ *PLOT STANDARD DEVIATIONS OVER TIME; proc means data=rus.ruswork1 noprint; class occasion; var motiv; output out=x mean=mean var=var std=std; run; symbol1 i=none v=circle color=red r=1; axis1 minor=none label=( angle=90 'SD of Motivation' ) order=(0 to 2 by .5); axis2 minor=none label=('Occasion') order=(0 to 20 by 1); proc gplot data=x; plot std*occasion/vaxis=axis1 haxis=axis2; title 'SD over time'; run; *CREATING CORRELOGRAM, MULTISTEP PROCESS; *FOR A BETTER EXPLANATION OF CORRELOGRAM, SEE pgs 68-70 in the text.; *TRANSPOSE DATASET FROM LONG FORMAT TO WIDE FORMAT; proc sort data = rus.ruswork1; by id; run; proc transpose data=rus.ruswork1 out=xx prefix=motiv; by id; id occasion; var motiv; run; *CORRELATION MATRIX; *ods trace on <-this is used is you want to find out in the log what output the proc gives you; ods select pearsoncorr; *only outputs the correlation table; ods output pearsoncorr=pearsoncorr; *creates an output dataset for the correlation table; title 'Correlation Matrix for Motivation Data'; proc corr data=xx; var motiv0--motiv18;run; *ods trace off <-turn off the "trace" from above; *page 62; *CREATE DATASET WITH ONLY UPPER TRIANGULAR VALUES, i.e. delete all values on diagnol or below; data temp (drop=i obsno variable); set pearsoncorr (drop=pmotiv0--pmotiv18); obsno=_N_; array w{*}motiv0--motiv18; do i=1 to 19; /*set equal to number of occasions*/ if i<=obsno then w{i}=.; end; occasion=input(substr(variable,6,2),best.); *This is used to create a time variable Count theses characters: motiv0 = 6 Go to the 6th position of the string and extract the last 2 positions (the number). Then using input, convert the number (which is a character string) into a number. best refers to the format for the number.; run; *RESTRUCTURE DATA FOR PLOTTING; data temp1 (keep = occasion motiv); set temp; array w{*} motiv0--motiv18; do i=1 to 19; motiv=w{i}; output; end; run; *DELETE MISSING OBSERVATIONS; data temp2; set temp1; if motiv=. then delete; run; *CREATE LAG VARIABLE; data temp3; set temp2; by occasion; if first.occasion then lags=1; else lags+1; run; *PLOT CORRELOGRAM; symbol i=join l=1 v=circle color=black r=10; axis1 minor=none label=( angle=90 'Correlation' ); axis2 minor=none label=('lag(occasions)'); proc gplot data=temp3; plot motiv*lags=occasion/vaxis=axis1 haxis=axis2 nolegend; title 'Correlogram of MOTIV DATA'; run; /*5. Scatterplot matrix using the Pain data. /*NEED TO DOWNLOAD THE 4 MACROS boxanno.sas, gdispla.sas. gensym.sas, scatmat.sas; These are available from course web site under lab 2. http://www.genetics.ucla.edu/courses/biostat236/*/ *SCATTERPLOT MATRIX USING PAIN DATA; *TRANSPOSE DATASET TO WIDE FORMAT; proc sort data=rus.ruswork1; by id; run; proc transpose data=rus.ruswork1 out=Rus_horiz(drop= _NAME_) prefix=Motiv; by id; id occasion; copy class1; var Motiv; run; *SINCE WE COPIED OVER CS AND TREATMENT WE HAVE EXTRA OBSERVATIONS... SO NEED TO DELETE; proc sort data=Rus_horiz; by id; run; data Rus_horiz1; set Rus_horiz; by id; if first.id; proc print data=Rus_horiz1;run; %include "&workdir\boxanno.sas"; %include "&workdir\gdispla.sas"; %include "&workdir\gensym.sas"; %include "&workdir\scatmat.sas"; options device=WIN; %scatmat(data=Rus_horiz1, var=motiv0-motiv9, anno=BOX); QUIT; %scatmat(data=Rus_horiz1, var=motiv10-motiv18, anno=BOX); QUIT; run; proc sort data=rus.ruswork1; by Class1; run; Proc gplot data = rus.ruswork1; Title 'Russian Data'; plot Motiv*occasion/nolegend; by class1; run; quit;