Hello
I want to run a code that calculate Kramer correlation matrix between categorical variables.
I have a question please about improving the code.
My code check correlation between any pair of variables
In my example there are 4 variables X Y Z R so it calculate correlation between:
X,X X,Y X,Z X,R
Y,Y Y,X Y,Z Y,R
Z,Z Z,X Z,Y Z,R
R,R R,X R,Y R,Z
So it calculate 16 correlations
However, correlation of X,Y is same as correlation of Y,X (and so on)
How can we improve the code that it will calculate the correlation matrix quicker?
Another question-
I have a warning message -
WARNING: 31% of the cells have expected counts less than 5, for the table of X by _X Chi-Square may not be a valid test.
What is the way to solve it?
/****categorical Variables list****/
%let list1var=X Y Z R;
%let list2var=&list1var.;
/**Number of varaibles***/
%let n =%sysfunc(countw(&list1var));
%put n=&n;
%macro CRAMV;
%do i = 1 %to &n.;
%let var1=%scan(&list1var.,&i.,+);
%do j = 1 %to &n.;
%let var2=%scan(&list2var.,&j.,+);
ods select none;
PROC FREQ DATA=Raw_Data_tbl;
TABLES &VAR1.* (&VAR2.)/CHISQ MISSING NOPERCENT NOCOL;
OUTPUT OUT=ttt CRAMV ;
RUN;
DATA want;
RETAIN VAR1 VAR2;
SET ttt;
LENGTH VAR1 VAR2 $32.;
VAR1 ="&VAR1";
VAR2 ="&VAR2";
RUN;
PROC APPEND DATA=want BASE=Kramer_All force;quit;
%end;
%end;
%mend;
%CRAMV;
/***Create matrix***/
title;
ods select all;
proc tabulate data=Kramer_All;
class VAR1 VAR2;
var _CRAMV_;
table (VAR1=''),VAR2=''*(_CRAMV_=''*min=''*f=6.5 );
run;
but it also calculate correlation between:
... View more