* Encoding: windows-1252. /******************************************************************************************************************** /*** *** /*** BEGIN MACRO FILE *** /*** INTERACTION AND SIMPLE SLOPES TESTS WITH ONE CONTINUOUS AND *** /*** ONE DICHOTOMOUS VARIABLE *** /*** *** /*** Programmed by Jason T. Newsom *** /*** Portland State University *** /*** *** /*** (c) 2002-2021 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 /*** 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 named x, y, and z. x is the predictor, /*** z is the moderator, and y is the dependent variable. The program centers x and z /*** and forms a product variable for the interaction, named xz. For example, three /*** simple compute statements can be used to produce these variables (omit *** ): /*** /*** COMPUTE X=independent variable. /*** COMPUTE Z=moderatore variable. /*** COMPUTE Y=dependent variable. /*** /*** Add the following three lines to any syntax file to call the macro: /*** /*** CD 'file path for saving temporary files/'. /*** INCLUDE 'file path for macro/simple1.sps'. /*** SIMPLE2 VARS=covariate variable names if desired. /*** /*** Important: The list of variables should not include x y z--only the covariates. If no /*** covariates are desired, include the VARS statement but leave the covariate /*** list blank (i.e., VARS= .) /*** /*** Then, highlight the syntax in your syntax file (not this one), and run the analysis; /*** /*** Note: on Mac, directly location usually looks like location like this /Users/yourusername/spssfiles/. /*** /*******************************************************************************************************************. 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='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='mtrxtemp.sav' /variables=devx,devy,devz,zx,zy,zz. end matrix. get file='datatemp.sav'. match files /file='mtrxtemp.sav' /file=*. compute x=devx. compute xz=devx*z. compute stanxz=zx*zz. save outfile='regdata.sav' /keep=!vars x y z xz stanxz. get file='regdata.sav'. regression /matrix out ('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 ('covb.sav'). get file='regout.sav'. select if rowtype_='MEAN'. rename variables (x=meanx) (z=meanz). save outfile='means.sav' /keep=meanx meanz. execute. get file='regout.sav'. select if rowtype_='N'. rename variables (y=n). save outfile='n.sav' /keep=n. execute. get file='regout.sav'. select if rowtype_='STDDEV'. rename variables (x=sdx) (z=sdz) (y=sdy) (xz=sdxz) (stanxz=sdstanxz). save outfile='stddevs.sav' /keep=sdx sdz sdy sdxz sdstanxz. execute. get file='covb.sav'. select if rowtype_='DFE'. rename variables (xz=df). save outfile='df.sav' /keep=df. execute. get file='covb.sav'. select if rowtype_='EST'. rename variables (const_=constant) (x=bx) (z=bz) (xz=bxz). save outfile='coeffs.sav' /keep=constant bx bz bxz. execute. get file='covb.sav'. select if varname_='x'. rename variables (X=varxx) (XZ=covxxz). save outfile='bcovs1.sav' /keep=varxx covxxz. execute. get file='covb.sav'. select if varname_='xz'. rename variables (xz=covxzxz). save outfile='bcovs2.sav' /keep=covxzxz. execute. get file='means.sav'. match files /file=n.sav /file=stddevs.sav /file=df.sav /file=coeffs.sav /file=bcovs1.sav /file=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='plotdata.dat' /lowzlowx hizlowx lowx /lowzmedx hizmedx meanx /lowzhix hizhix hix. execute. data list file='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='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='sse0.sav' /variables=vare0. end matrix. get file='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='sse1.sav' /variables=vare1. end matrix. get file='sse0.sav'. match files /file=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 *** *** *** *************************************************************************************************************.