* y is the dependent and x1 TO xp the predictors. * MACRO CALL. * BPKTEST Y p x1 to xp. * replace Y with your dependent - replace p with the number of independents - replace x1 to xp with names of independents and remove *. BPKTEST speed 7 p2 to p8. * Modified by fms on 8/29/02. * BREUSCH-PAGAN & KOENKER TEST MACRO * * See 'Heteroscedasticity: Testing and correcting in SPSS' * by Gwilym Pryce, for technical details. * The MACRO is based in his paper. * Code by Marta Garcia-Granero 2002/03/21. * The MACRO needs 3 arguments: * the dependent, the number of predictors and the list of predictors * (if they are consecutive, the keyword TO can be used) . * (1) MACRO definition. DEFINE bpktest(!POSITIONAL !TOKENS(1) /!POSITIONAL !TOKENS(1) /!POSITIONAL !CMDEND). * Regression to get the residuals and residual plots. REGRESSION /STATISTICS R ANOVA /DEPENDENT !1 /METHOD=ENTER !3 /SCATTERPLOT=(*ZRESID,*ZPRED) /RESIDUALS HIST(ZRESID) NORM(ZRESID) /SAVE RESID(residual) . * New dependent variable (g) creation. COMPUTE sq_res=residual**2. compute constant=1. erase file = 'tempdata.sav'. AGGREGATE /OUTFILE='tempdata.sav' /BREAK=constant /rss = SUM(sq_res) /N=N. MATCH FILES /FILE=* /FILE='tempdata.sav'. EXECUTE. if missing(rss) rss=lag(rss,1). if missing(n) n=lag(n,1). compute g=sq_res/(rss/n). execute. * Regression of g on the predictors. REGRESSION /STATISTICS R ANOVA /DEPENDENT g /METHOD=ENTER !3 /SAVE RESID(resid) . * Checking normality of residuals. EXAMINE VARIABLES=residual /PLOT BOXPLOT HISTOGRAM NPPLOT /COMPARE GROUP /STATISTICS NONE /CINTERVAL 95 /MISSING LISTWISE /NOTOTAL. * Routine adapted from Gwilym Pryce. matrix. get bigx /variables = !3/missing = omit. compute bt_b = T(bigx)*bigx. compute p1 = trace(ginv(bt_b)*bt_b). compute p=p1. get g /variables=g / missing = omit. get resid /variables=resid / missing = omit. compute sq_res2=resid&**2. compute n=nrow(g). compute rss=msum(sq_res2). compute ii_1=make(n,n,1). compute i=ident(n). compute m0=i-((1/n)*ii_1). compute tss=transpos(g)*m0*g. compute regss=tss-rss. print regss /format="f8.4" /title="Regression SS". print rss /format="f8.4" /title="Residual SS". print tss /format="f8.4" /title="Total SS". compute r_sq=1-(rss/tss). print r_sq /format="f8.4" /title="R-squared". print n /format="f4.0" /title="Sample size (N)". print p /format="f4.0" /title="Number of predictors (P)". compute bp_test=0.5*regss. print bp_test /format="f8.3" /title="Breusch-Pagan test for Heteroscedasticity" + " (CHI-SQUARE df=P)". compute sig=1-chicdf(bp_test,p). print sig /format="f8.4" /title="Significance level of Chi-square df=P (H0:" + "homoscedasticity)". compute k_test=n*r_sq. print k_test /format="f8.3" /title="Koenker test for Heteroscedasticity" + " (CHI-SQUARE df=P)". compute sig=1-chicdf(k_test,p). print sig /format="f8.4" /title="Significance level of Chi-square df=P(H0:" + "homoscedasticity)". end matrix. !ENDDEFINE.