Hi,
I'm looking to create a scatter plot matrix with regression lines that also displays the r-squared and p value in an inset for each graph. I have tried using proc template with scatterplotmatrix, but I can only get a pearson correlation in the inset, and no regression line. I also tried proc sgscatter, but cannot get the inset to display the statistical information I need. Does anybody have any suggestions on how I can accomplish this?
Thanks
ods graphics on;
proc sgscatter data=work.query_for_stabsummarytablesfilte;
compare y=(FairnessIdxAvgTotal_Mean EqGiniVisibleTotal ) x=(GES1_SUM GES61_SUM COH4_SUM)
/ Legend=(Position=Bottom) reg=(clm nogroup) ;
Title "Group Variables";
label FairnessIdxAvgTotal_Mean="Group Fairness Idx"
EqGiniVisibleTotal = "Equality Barrier Reveals"
GES1_SUM = "GES:Unity"
GES61_SUM = "GES:Proud"
COH4_SUM = 'PCQ:Best Anywhere';
WHERE groupName = 'A' OR groupName = 'B' OR groupName = 'C' OR groupName = 'D' OR groupName = 'E';
run;
proc template;
define statgraph spminset;
begingraph;
entrytitle "Group TPT Metrics and Cohesion";
entrytitle 'Concordia 2013';
layout gridded;
scatterplotmatrix GES1_SUM GES61_SUM COH4_SUM/
rowvars=(FairnessIdxAvgTotal_Mean EqGiniVisibleTotal)
inset=(nobs pearson pearsonpval)
insetopts=( border=true opaque = true)
corropts=(nomiss=true vardef=df)
markerattrs=(size=4px)
ellipse=(alpha=.20 type=predicted);
endlayout;
endgraph;
end;
run;
proc sgrender data=work.query_for_stabsummarytablesfilte template=spminset;
WHERE groupName = 'A' OR groupName = 'B' OR groupName = 'C' OR groupName = 'D' OR groupName = 'E';
label FairnessIdxAvgTotal_Mean ="Group Fairness Idx"
EqGiniVisibleTotal = "Equality Barrier Reveals"
GES1_SUM = "GES:Unity"
GES61_SUM = "GES:Proud"
COH4_SUM = 'PCQ:Best Anywhere' ;
run;
ods graphics off;
Here's an example of the reg line using sgscatter, not sure about the inset part.
yes, i was able to use SGSCATTER to create the graphs, however I'd like to have p-value and r-squared listed for each plot. It seems that SGSCATTER has no options for this.
If the values are calculated outside, put them into macro variable and use a legend. Ive done similar for pvalues using the legend examples below
legenditem type=marker name="PValue" / LABEL="Log rank test: p=&PValue" lineattrs=GraphData1(color=black THICKNESS=10)
labelattrs=(size=8 family="Arial") markerattrs=(size=0);
discretelegend "PValue" / titleattrs=(size=9 family="Arial")
BORDER=false across=1 location=inside
halign=left valign=bottom pad=(bottom=35);
For a small 3x3 with custom labels using GTL, you could build the matrix yourself. That is what is happening in the background anyway. Use a LAYOUT LATTICE with a 3x3 row-column layout, and insert the necessary scatter, reg and insets into the cells yourself. Quite doable, especially for a small matrix.
If you want ROWVARS, you can create the appropriate combinations. The general idea is shown in this article, but you can see what needs to be done and customize to your needs. Compact Scatter Plot Matrix - Graphically Speaking
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.