/* ================================================================================= */ /* logistic regression Collinearity diagnostics using the information matrix */ /* ================================================================================= */ %macro collin(covdsn=); /* Macro to calculate collinearity diagnostics from the variance-covariance matrix in nonlinear regression. in the nonlinear regression program (PROC LOGISTIC or PROC PHREG), specify the COVOUT and the OUTEST = SASdsn options in the PROC statement. Then, specify the SAS data set (SASdsn) in the macro variable, COVDSN, when you invoke this macro. This macro does not work with PROC GENMOD. */ %if (&covdsn ne ) %then %do; /* start of [ %if (&covdsn ne ) %then %do loop ] */ /* option mprint */ %let __stop = 0; proc iml; /* read the variance – covariance matrix from proc logistic */ use &covdsn; read all var {_name_} into _varname; _nrvname = nrow(_varname); if (_nrvname>1) then do; _varnam2 = _varname(|2:_nrvname, |); nmissing = j(nrow(_varnam2),1,.); labels = {"Eigenval","CondIndx"," "}; _varnam2 = labels//_varnam2; free _varname labels; read all var _num_ into varcov(|colname=_nvname|); _nrcvc = ncol(varcov); lastvnam = _nvname(|1,_nrcvc|); if (lastvnam = "_LNLIKE_") then varcov2 = varcov(|2:_nrvname,1:_nrcvc-1|); if (lastvnam^ = "_LNLIKE_") then varcov2 = varcov(|2:_nrvname,|); free varcov _nrcvc lastvnam; covbinv = inv(varcov2); scale = inv(sqrt(diag(covbinv))); r = scale*covbinv*scale; free covbinv scale; call eigen(musqr,v,r); free r; srootmus = sqrt(musqr); ci = 1/(srootmus/max(srootmus)); phi = (v##2)*diag(musqr##(-1)); sumphi = phi(|,+|); pi = phi#(sumphi##(-1)); free phi sumphi srootmus v; final = (musqr||ci||nmissing||pi`)`; free pi musqr ci nmissing; _ncfinal = ncol(final); _nrfinal = nrow(final); final2=j(_nrfinal,_ncfinal,0); _ncfp1=_ncfinal+1; __vdp="VDP"; do i=1 to _ncfinal; final2(|,_ncfp1-i|)=final(|,i|); x=char(i,3); y=compress(concat(__vdp,x)); if i=1 then _vdpname=y; else _vdpname=_vdpname||y; end; free final _nrfinal _ncfinal i x y; create final2 from final2(|rowname=_varnam2 colname=_vdpname|); append from final2(|rowname=_varnam2 colname=_vdpname|); free _varnam2 _vdpname final2; end; if (_nrvname=1) then do; x="1"; call symput("__stop",left(x)); print " "; print "**********************************************************"; print "You need to specify the COVOUT option"; print " in either PROC LOGISTIC or PROC PHREG."; print " This program will not calculate collinearity diagnostics."; print "**********************************************************"; print " "; end; quit; run; %if (&__stop eq 0) %then %do; proc print data=final2 label noobs; id _varnam2; title8 "Collinearity diagnostics for nonlinear models using"; title9 "the information matrix: Eigenvalues, condition indexes,"; title10 "and variance decomposition proportions (VDP's)"; label _varnam2="Variable"; run; %end; /* end of proc print do loop */ %end; /* end of [ %if (&covdsn ne ) %then %do loop ] */ %else %do; /* start of [ %if (&covdsn ne ) %else %do loop ] */ %put; %put "*******************************************************"; %put " When you invoke this macro, you have to specify the name"; %put " of a SAS data set that contains the variance-covariance"; %put " matrix from either PROC LOGISTIC or PROC PHREG."; %put; %put " You can create this matrix by including the following options"; %put " on the PROC statement: COVOUT and OUTEST=SASdsn,"; %put " where SASdsn is the name of the SAS data set containing"; %put " the variance-covariance matrix."; %put "*******************************************************"; %put; %end; /* end of [ %if (&covdsn ne ) else %do loop ] */ %mend collin; /* end of macro collin definition */ %collin(covdsn = ); /* call macro collin with variance-covariance data set name */ ##- Please type your reply above this line. Simple formatting, no attachments. -##
... View more