Data visualization with SAS programming

Error when trying to create correlation heat map with spearman

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Error when trying to create correlation heat map with spearman

Hi, I'm trying to create a heat map using spearman correlations, but am getting the following errors when running sgrender:

 

java.lang.ArrayIndexOutOfBoundsException: 3

ERROR: Physical file does not exist, /tmp/SAS_work50EB00006B2C_localhost.localdomain/_4D29A1B845FFE4BBCA177128127DE4A.bmp.

 

When I try to run the same code calling for pearson, it works perfectly. Does anyone know why this error occurs when trying to generate the map using spearman and not pearson?

 

Here is the code I am using:

 

proc template;
define statgraph corrHeatmap;
dynamic _Title;
begingraph;
entrytitle _Title;
rangeattrmap name='map';
range -1 - 1 / rangecolormodel=(cxfc8d59 cxffffbf cx91bfdb);
endrangeattrmap;
rangeattrvar var=r attrvar=r attrmap='map';
layout overlay /
xaxisopts=(display=(line ticks tickvalues))
yaxisopts=(display=(line ticks tickvalues));
heatmapparm x = x y = y colorresponse = r / xbinaxis=false ybinaxis=false
colormodel=THREECOLORRAMP name = "heatmap" display=all;
continuouslegend "heatmap" /
orient = vertical location = outside title="Spearman Correlation";
endlayout;
endgraph;
end;
run;


%macro prepCorrData(in=,out=);
proc corr data=&in. spearman nocorr
outs=work._tmpCorr
;
run;


data &out.;
keep x y r;
set work._tmpCorr(where=(_TYPE_="CORR"));
array v{*} _numeric_;
x = _NAME_;
do i = dim(v) to 1 by -1;
y = vname(v(i));
r = v(i);
/* creates a diagonally sparse matrix */
if (i<_n_) then
r=.;
output;
end;
run;

 

proc datasets lib=work nolist nowarn;
delete _tmpcorr;
quit;
%mend;

 

%prepCorrData(
in=work.one, out=one_heat);
proc sgrender data=one_heat template=corrheatmap;
dynamic _title="Correlation Matrix at 12 Months";
run;

 

Thank you!


Accepted Solutions
Solution
‎08-17-2016 08:56 AM
New Contributor
Posts: 3

Re: Error when trying to create correlation heat map with spearman

I have the solution in case anyone has this problem in the future (via: Chris Hemedinger of The SAS Dummy):

 

I found the issue. It's a precision issue with the Spearman output, which sometimes can be so close to 1.0 for self-correlations but can actually be just a tiny bit over 1. That value falls outside of the colormap range that is defined in the GTL code. We can work around with the ROUND function in preparing the matrix for plotting.

Change the DATA step in the "prep data" portion to:

 

data &out.;
keep x y r;
set work._tmpCorr(where=(_TYPE_="CORR"));
array v{*} _numeric_;
x = _NAME_;
do i = dim(v) to 1 by -1;
y = vname(v(i));
/* Round to account for precision differences */
r = round( v(i), 0.0000001 );
/* creates a diagonally sparse matrix */
if (i<_n_) then
r=.;
output;
end;
run;

View solution in original post


All Replies
Grand Advisor
Posts: 9,699

Re: Error when trying to create correlation heat map with spearman

Did the code work before introducing macro language?

New Contributor
Posts: 3

Re: Error when trying to create correlation heat map with spearman

I haven't tried the code without the macro, but it works for pearson with
the macro. For example, if I change the output in the proc corr statement
to outp=work._tmpCorr (of course removing nocorr), the heat maps generate
fine. It's only if I try outs= to call the spearman correlations, that I
get these errors.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Solution
‎08-17-2016 08:56 AM
New Contributor
Posts: 3

Re: Error when trying to create correlation heat map with spearman

I have the solution in case anyone has this problem in the future (via: Chris Hemedinger of The SAS Dummy):

 

I found the issue. It's a precision issue with the Spearman output, which sometimes can be so close to 1.0 for self-correlations but can actually be just a tiny bit over 1. That value falls outside of the colormap range that is defined in the GTL code. We can work around with the ROUND function in preparing the matrix for plotting.

Change the DATA step in the "prep data" portion to:

 

data &out.;
keep x y r;
set work._tmpCorr(where=(_TYPE_="CORR"));
array v{*} _numeric_;
x = _NAME_;
do i = dim(v) to 1 by -1;
y = vname(v(i));
/* Round to account for precision differences */
r = round( v(i), 0.0000001 );
/* creates a diagonally sparse matrix */
if (i<_n_) then
r=.;
output;
end;
run;

Post a Question
Discussion Stats
  • 3 replies
  • 195 views
  • 0 likes
  • 2 in conversation