BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
catch18
Obsidian | Level 7

I include the proc iml code as follows:

ODS graphics on;

proc pls data=Target.e_diet_bf_scores_morph method=PCR varss details plot=corrload(nfac=3 trace=on);

model exclbf PBf6mth exclFf6mth Sol = &xlist;

output out=pattern_morph1(rename=(scorePred1=Health scorePred2=Junk scorePred3=Mixed)) xscore=scorePred yscore=scoreResp;

run;

 

ods exclude all;

proc corr data=pattern_morph1; /* pairwise correlation */

var Health Junk Mixed;

with scoreResp1 scoreResp2 scoreResp3;

ods output PearsonCorr = Corr; /* write correlations, p-values, and sample sizes to data set */

run;

ods exclude none

 

proc iml;

use Corr;

read all var "Variable" into ColNames; /* get names of variables */

read all var (ColNames) into mCorr; /* matrix of correlations */

ProbNames = "P"+ColNames; /* variables for p-values are named PX, PY, PZ, etc */

read all var (ProbNames) into mProb; /* matrix of p-values */

close Corr;

call HeatmapCont(mCorr) xvalues=ColNames yvalues=ColNames

colorramp="ThreeColor" range={-1 1} title="Pairwise Correlation Matrix";

numCols = ncol(mCorr); /* number of variables */

numPairs = numCols*(numCols-1) / 2;

length = 2*nleng(ColNames) + 5; /* max length of new ID variable */

PairNames = j(NumPairs, 1, BlankStr(length));

i = 1;

do row= 2 to numCols; /* construct the pairwise names */

do col = 1 to row-1;

PairNames[i] = strip(ColNames[col]) + " vs. " + strip(ColNames[row]);

i = i + 1;

end;

end;

 

 

lowerIdx = loc(row(mCorr) > col(mCorr)); /* indices of lower-triangular elements */

 

Corr = mCorr[ lowerIdx ];

Prob = mProb[ lowerIdx ];

Significant = choose(Prob > 0.05, "No ", "Yes"); /* use alpha=0.05 signif level */

 

 

create CorrPairs var {"PairNames" "Corr" "Prob" "Significant"};

append;

close;

QUIT;

 

 

I get a long error message that I can't seem to paste here, but it begins to state that -scoreResp 1 is not in the scope of variables for the dataset? Even though I want to look at correlations between the derived factors and the response variables. Here, I'm not sure if I should use values for the original response or the Y scores?

Rick_SAS
SAS Super FREQ

The reason for the error is that the blog post analyzes a square correlation matrix. That is, looking at the pairs of correlations between the set of variables X1, X2, ..., Xp.  Because you are using the VAR and WITH statements in PROC CORR, you are trying to analyze the correlations between pairs of variables X1, X2, X3, ..., and Y1, Y3, Y3 ,....

 

I've tried to quickly modify the program to work for the WITH statement, but I didn't test it. The data for the example are from the Getting Started example for PROC PLS.  Hopefully, you can modify this example to suit your needs.

 

/* Getting Started Example: Predicting Biological Activity */

data Sample;
   input obsnam $ v1-v27 ls ha dt @@;
ETC ... DOWLONAD THE EXAMPLE
;

/* Fitting a PLS Model */
%let YVars = ls ha dt;
proc pls data=sample  method=PCR varss details plot=corrload(nfac=3 trace=on);
   model &YVars = v1-v27;
   output out=pattern_morph1 xscore=scorePred yscore=scoreResp;
run;

 proc corr data=pattern_morph1; /* pairwise correlation */
var &YVars;
with scorePred1-scorePred3;
ods output PearsonCorr = Corr; /* write correlations, p-values, and sample sizes to data set */
run;

proc iml;
ColNames = {&YVars};
use Corr;
read all var "Variable" into RowNames;
read all var {&YVars} into mCorr; /* matrix of correlations */
ProbNames = "P"+ColNames; /* variables for p-values are named PX, PY, PZ, etc */
read all var (ProbNames) into mProb; /* matrix of p-values */
close Corr;

numCols = ncol(mCorr); /* number of variables */
numRows = nrow(mCorr); /* number of variables */
numPairs = numCols*numRows;
length = nleng(ColNames) + nleng(RowNames) + 5; /* max length of new ID variable */
PairNames = j(NumPairs, 1, BlankStr(length));
i = 1;
do row= 1 to numCols; /* construct the pairwise names */
   do col = 1 to numCols;
      PairNames[i] = strip(ColNames[col]) + " vs. " + strip(RowNames[row]);
      i = i + 1;
   end;
end;
print PairNames;


Corr = mCorr[ 1:numPairs ];
Prob = mProb[ 1:numPairs ];
Significant = choose(Prob > 0.05, "No ", "Yes"); /* use alpha=0.05 signif level */

create CorrPairs var {"PairNames" "Corr" "Prob" "Significant"};
append;
close;
 
proc sort data=CorrPairs;  by Corr;  run;

title "Pairwise Correlations";
proc sgplot data=CorrPairs;
hbar PairNames / response=Corr group=Significant;
refline 0 / axis=x;
yaxis discreteorder=data display=(nolabel) 
      labelattrs=(size=6pt) fitpolicy=none 
      offsetmin=0.012 offsetmax=0.012  /* half of 1/k, where k=number of catgories */
      colorbands=even colorbandsattrs=(color=gray transparency=0.9);
xaxis grid display=(nolabel);
keylegend / position=topright location=inside across=1;
run;
catch18
Obsidian | Level 7

It has worked beautifully, thank you so much!!

I finally have a solution.

Thanks

catch18
Obsidian | Level 7

@Rick_SAS 

I have just noticed one of my yvars did not show up in the pairwise correlation plot. I have gone through the code carefully and it shows up in the Corr data set.  I'm not sure how to fix this, could you please advise?

 

Thanks

catch18
Obsidian | Level 7

Please ignore - problem solved!

 

Thanks

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 19 replies
  • 1440 views
  • 0 likes
  • 4 in conversation