/******************************************************************************************************************** /*** *** /*** BEGIN MACRO FILE *** /*** INTERACTION AND SIMPLE SLOPES TESTS WITH ONE CONTINUOUS AND *** /*** ONE DICHOTOMOUS VARIABLE *** /*** *** /*** Programmed by Jason T. Newsom *** /*** Institute on Aging, Portland State University *** /*** *** /*** (c) 2002-2006 Jason T. Newsom. All rights reserved. *** /*** *** /********************************************************************************************************************. /******************************************************************************************************************** /*** This program tests the two-way interaction between a continuous and a dichotomous (binary) /*** variable (a separate macro is available for the interaction between two continuous variables at /*** http://www.ioa.pdx.edu/newsom). *This program calculates the correct standardized coefficient /*** for the interaction variable, calculates standardized and unstandardized simple slopes for /*** Y on X at the two values of the dichotomous variable, Z, tests them for significance, and plots /*** them; *Naturally, if the interaction is nonsignificant, you should ignore the simple slopes and plot; /*** /*** First, store this syntax file (ie, the macro) on your computer (I recommend you store it in C:\ /*** because using many subfolders will invite errors when you give the file location); *This program /*** requires no modification before using; /*** /*** The next step is to create three new variable names in your data set, one for your continuous predictor, X, /*** one for your dichtomous moderator, Z;, and one for your dependent variable, Y; *The dichotomous variable, /*** Z, must be coded 0 and 1; *The program automatically centers the continous predictor, X; /*** RENAME and the COMPUTE commands are two ways to create X, Y, and Z; *For example, three *** simple compute statements in syntax can be used to produce these variables (omit /* and */ ): /*** /*** /* COMPUTE X=indvar. */ /*** /* COMPUTE Z=modvar. */ /*** /* COMPUTE Y=depvar. */ /*** /*** Next, add the following two lines to any syntax file to call the macro: /*** /*** /* INCLUDE 'filename'. */ /*** /* SIMPLE2 VARS=covariate list. */ /*** /*** The INCLUDE statement gives the location of the macro file on your hard drive; /*** The SIMPLE2 VARS= statements names the variables to be used in the analysis; /*** Please note that the list of variables on the SIMPLE2 VARS= command should not /*** include x y z; *It should only includd the covariates you wish to add; *If no covariates are desired, *** you will need a VARS= statement with at least one blank space (ie, VARS= .) /*** /*** Then, highlight the syntax, and run the analysis; /*** /*** /*******************************************************************************************************************. define simple2(vars=!charend('/')). compute x=x. compute y=y. compute z=z. count miss=!vars x y z (missing). select if miss eq 0. save outfile='c:\datatemp.sav' /keep=!vars x y z. matrix. get m /variables=x y z /names=varnames /missing=omit. compute n=nrow(m). compute sums=csum(m). compute means=sums/n. compute j=make(n,1,1). compute devs=m-j*means. compute sqdevs=csum(devs&*devs). compute ss=csum(devs&*devs). compute var=ss/(n-1). compute sd=sqrt(var). compute z=devs/(j*sd). release m. * print {z} /title "z" /format=f10.3. save {devs,z} /outfile='c:\mtrxtemp.sav' /variables=devx,devy,devz,zx,zy,zz. end matrix. get file='c:\datatemp.sav'. match files /file='c:\mtrxtemp.sav' /file=*. compute x=devx. compute xz=devx*z. compute stanxz=zx*zz. save outfile='c:\regdata.sav' /keep=!vars x y z xz stanxz. get file='c:\regdata.sav'. regression /matrix out ('c:\regout.sav') /vars= !vars x y z xz stanxz /descriptives=mean stdev /statistics= r coeff ses anova bcov /dependent=y /method=enter !vars x z xz /outfile=covb ('c:\covb.sav'). get file='c:\regout.sav'. select if rowtype_='MEAN'. rename variables (x=meanx) (z=meanz). save outfile='c:\means.sav' /keep=meanx meanz. execute. get file='c:\regout.sav'. select if rowtype_='N'. rename variables (y=n). save outfile='c:\n.sav' /keep=n. execute. get file='c:\regout.sav'. select if rowtype_='STDDEV'. rename variables (x=sdx) (z=sdz) (y=sdy) (xz=sdxz) (stanxz=sdstanxz). save outfile='c:\stddevs.sav' /keep=sdx sdz sdy sdxz sdstanxz. execute. get file='c:\covb.sav'. select if rowtype_='DFE'. rename variables (xz=df). save outfile='c:\df.sav' /keep=df. execute. get file='c:\covb.sav'. select if rowtype_='EST'. rename variables (const_=constant) (x=bx) (z=bz) (xz=bxz). save outfile='c:\coeffs.sav' /keep=constant bx bz bxz. execute. get file='c:\covb.sav'. select if varname_='x'. rename variables (x=varxx) (xz=covxxz). save outfile='c:\bcovs1.sav' /keep=varxx covxxz. execute. get file='c:\covb.sav'. select if varname_='xz'. rename variables (xz=covxzxz). save outfile='c:\bcovs2.sav' /keep=covxzxz. execute. get file='c:\means.sav'. match files /file='c:\n.sav' /file='c:\stddevs.sav' /file='c:\df.sav' /file='c:\coeffs.sav' /file='c:\bcovs1.sav' /file='c:\bcovs2.sav' /file=*. execute. compute stanbxz=(bxz*(sdxz/sdy))/sdstanxz. print / ' '. print / 'Correct Standardized Slope for XZ'. print / ' ' stanbxz (f7.3). print space. execute. COMPUTE LOWZLOWX=(bx+(bxZ*0))*(-SDX)+((bz*0)+CONSTANT). COMPUTE LOWZMEDX=(bx+(bxZ*0))*(MEANX)+((bz*0)+CONSTANT). COMPUTE LOWZHIX=(bx+(bxZ*0))*(SDX)+((bz*0)+CONSTANT). COMPUTE HIZLOWX=(bx+(bxZ*1))*(-SDX)+((bz*1)+CONSTANT). COMPUTE HIZMEDX=(bx+(bxZ*1))*(MEANX)+((bz*1)+CONSTANT). COMPUTE HIZHIX=(bx+(bxZ*1))*(SDX)+((bz*1)+CONSTANT). COMPUTE LOWZSLOP=bx+(bxZ*0). COMPUTE HIZSLOP=bx+(bxZ*1). COMPUTE ERRSLP1=SQRT(VARXX+(2*(0)*(COVXXZ))+(0*0)*COVXZXZ). COMPUTE ERRSLP2=SQRT(VARXX+(2*(1)*(COVXXZ))+(1*1)*COVXZXZ). compute stanslp1=lowzslop*(sdx/sdy). compute stanslp2=hizslop*(sdx/sdy). COMPUTE TSLOPE1=LOWZSLOP/ERRSLP1. COMPUTE TSLOPE2=HIZSLOP/ERRSLP2. compute abs_t1=abs(tslope1). compute cump1=cdf.t (abs_t1,df). compute p1=(1-cump1)*2. compute abs_t2=abs(tslope2). compute cump2=cdf.t (abs_t2,df). compute p2=(1-cump2)*2. print / ' '. print / 'Unstandardized Simple Slopes for X' . print / ' b'. print / ' at Z = 0: ' lowzslop (f6.2). print / ' at Z = 1: ' hizslop (f6.2). print / ' '. print / 'Standardized Simple Slopes for X' . print / ' beta'. print / ' at Z = 0: ' stanslp1 (f6.2). print / ' at Z = 1: ' stanslp2 (f6.2). print / ' '. print / 'Significance'. print / ' SE t-value p-value'. print / ' at Z = 0: ' errslp1 (f6.2) ' ' tslope1 (f6.2) ' ' p1 (f4.3). print / ' at Z = 1: ' errslp2 (f6.2) ' ' tslope2 (f6.2)' ' p2 (f4.3). execute. compute lowx=meanx - sdx. compute hix=meanx + sdx. formats lowzlowx lowzmedx lowzhix hizlowx hizmedx hizhix (f10.3). formats lowx meanx hix (f8.1). write outfile='c:\plotdata.dat' /lowzlowx hizlowx lowx /lowzmedx hizmedx meanx /lowzhix hizhix hix. execute. data list file='c:\plotdata.dat' notable /lowz 1-10 highz 11-20 x 21-28. graph title = 'Simple Slopes for Y on X at Values of Z' /footnote = 'LOWZ is Z= 0 group, HIGHZ is Z = 1 group' / line = value(lowz highz) by x. /******************Compute Deshon & Alexander's variance ratio********************. get file='c:\datatemp.sav'. /* COMPUTE ERROR VARIANCE FOR GROUP 0. select if z=0. matrix. get m0 /variables=x y z /names=varnames /missing=omit. compute x=m0(:,1). /* converts the first row of the data set to col vector of x */. compute y=m0(:,2). /* converts the second row of the data set to col vector of y */. compute n=nrow(x). compute one=make(1,n,1). compute colone=transpos(one). compute xaug={colone,x}. compute x=xaug. compute transx=transpos(x). compute xtx=transx*x. compute invxtx=inv(xtx). compute xty=transx*y. compute b=invxtx*xty. compute transy=transpos(y). compute yty=transy*y. compute transb=transpos(b). compute sse0=yty - (transb*xty). compute j=colone*one. compute sstot=yty - ((1/n)*transy*j*y). compute ssr=sstot - sse0. compute rsq0=ssr/sstot. compute sumy=csum(y). compute sumysq=sumy**2. compute nminus1=n-1. compute ndiv=1/nminus1. compute vary=ndiv*(yty - (sumysq/n)). compute vare0=(vary*(n-1)*(1-rsq0))/(n-2). save {vare0} /outfile='c:\sse0.sav' /variables=vare0. end matrix. get file='c:\datatemp.sav'. /* COMPUTE ERROR VARIANCE FOR GROUP 1. select if z=1. matrix. get m1 /variables=x y z /names=varnames /missing=omit. compute x=m1(:,1). /* converts the first row of the data set to col vector of x */. compute y=m1(:,2). /* converts the second row of the data set to col vector of y */. compute n=nrow(x). compute one=make(1,n,1). compute colone=transpos(one). compute xaug={colone,x}. compute x=xaug. compute transx=transpos(x). compute xtx=transx*x. compute invxtx=inv(xtx). compute xty=transx*y. compute b=invxtx*xty. compute transy=transpos(y). compute yty=transy*y. compute transb=transpos(b). compute sse1=yty - (transb*xty). compute j=colone*one. compute sstot=yty - ((1/n)*transy*j*y). compute ssr=sstot - sse1. compute rsq1=ssr/sstot. compute sumy=csum(y). compute sumysq=sumy**2. compute nminus1=n-1. compute ndiv=1/nminus1. compute vary=ndiv*(yty - (sumysq/n)). compute vare1=(vary*(n-1)*(1-rsq1))/(n-2). save {vare1} /outfile='c:\sse1.sav' /variables=vare1. end matrix. get file='c:\sse0.sav'. match files /file='c:\sse1.sav' /file=*. execute. compute ratio=vare0/vare1. execute. print / ' '. print / ' '. print / ' '. print / ' '. print / ' '. print / ' '. print / 'Ratio of Residual Variances in the Two Groups' . print / ' ' ratio . print / ' '. print / 'According to DeShon and Alexander (1996), a ratio value '. print / 'between .67 and 1.5 does not violate homogeneity assumptions'. execute. !enddefine. *************************************************************************************************************. *** *** *** END OF MACRO FILE *** *** *** *************************************************************************************************************.