/* --------------------------------------------------------- file: detroit.path.analysis.sas PROBLEM: Is the correlation between the homicide rate (hom) and assault rate (asr) simply due to the fact that both are increasing over time? SOLUTION: Predict both the homicide rate and the assault rate by year and test whether the correlation between the two disappears. NOTE: One could also test this hypothesis by predicting, say, assault by both year and homocide and testing whether the coefficient for homicide is not significant --------------------------------------------------------- */ OPTIONS NOCENTER NODATE PAGENO=1; * --- set the LIBNAME statement to the directory/folder containing the detroit data set; *LIBNAME p7291 ''; DATA temp; SET p7291.detroit; RUN; TITLE Effect of year on homicide and assault; * - first examine the correlation matrix among the variables; PROC CORR DATA=temp; VAR year hom asr; RUN; * - perform the multivariate regression. from inspection of the correlations, we know that the results will be significant. the purpose here is to examine the "error" correlation matrix printed by the PRINTE command to see if the correlation between hom and asr goes to 0 when controlling fro year; PROC GLM DATA = temp; * - NOUNI suppresses prinout of the univariate regressions; MODEL hom asr = year / NOUNI; * - PRINTE prints the error SSCP and correlation matrix; MANOVA / PRINTE; RUN; QUIT; * - performing the same test with PROC CALIS. we will fit two models, a general model and then a model that sets the covariance between the error terms to 0. the first model will give a chi square of 0 (do you know why?). the second will give a positive chi square with 1 df (why?). the different between the second chi square and the first is called a "likelihood ratio chi square" and, if significant, suggests that the second model fits worse than the first PS: this is really a clunky way of doing it, but we are only using it tp introduce the CALIS procedure; TITLE2 SEM: General MOdel; PROC CALIS DATA=TEMP CORR; VAR year hom asr; LINEQS hom = b_hom year + e_hom, asr = b_asr year + e_asr; STD e_hom = ve_hom, e_asr = ve_asr; COV e_hom e_asr = Cov_Error; RUN; TITLE2 SEM: Constrained MOdel; * - note that this code is the same as that above, but without the COV statement; PROC CALIS DATA=TEMP CORR; VAR year hom asr; LINEQS hom = b_hom year + e_hom, asr = b_asr year + e_asr; STD e_hom = ve_hom, e_asr = ve_asr; RUN;