Data visualization with SAS programming

Cook's Distance Plot: Label and Lines are not aligned

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Cook's Distance Plot: Label and Lines are not aligned

Hi all,

I have this code:

 

proc reg data=eingabe3 plots(label)=(CooksD);
id serialno;
model sdnn_ms=age age2;
run;

 

producing the attached graphic.

I want to know how to align the labels to the data spikes. Now they are shifted to right.

Thank you.

 

Regards

Frank

Attachment

Accepted Solutions
Solution
‎07-10-2016 10:03 AM
SAS Super FREQ
Posts: 3,236

Re: Cook's Distance Plot: Label and Lines are not aligned

Try adding:

format serialno 4.;

as the first line of the procedure.  I assume that the ID variable is numeric and has a format with a large width field (maybe 12?).

View solution in original post


All Replies
Solution
‎07-10-2016 10:03 AM
SAS Super FREQ
Posts: 3,236

Re: Cook's Distance Plot: Label and Lines are not aligned

Try adding:

format serialno 4.;

as the first line of the procedure.  I assume that the ID variable is numeric and has a format with a large width field (maybe 12?).

Contributor
Posts: 30

Re: Cook's Distance Plot: Label and Lines are not aligned

Hi Rick,

yes, this was the idea! I had "serialno 5." - this is quiet a difference.

Is there a chance to avoid the labels in the lower part of the diagram?

 

Thanks

Frank

SAS Super FREQ
Posts: 3,236

Re: Cook's Distance Plot: Label and Lines are not aligned

The cutoff value is (I think) 4/n where n is the number of nonmissing obs. Points with Cook's D greater than that value are labeled. 

 

Probably the easiest way control the labeling is to output the Cook's D statistic in the OUTPUT statement and then use PROC SGPLOT to create the plot manually. 

 

ods select CooksDPlot;
proc reg data = sashelp.cars plots(label)=(CooksD);
  model mpg_city = weight wheelbase;
  output out=RegOut cookd=cookd;
quit;
%let cutoff = 0.05;  /* create new cutoff value */
data RegOut;
format MyLabel $8.;
set RegOut;
ObsNum = _N_;
if cookD > &cutoff then 
   MyLabel = Model;
else 
   MyLabel = " ";
run;

proc sgplot data=RegOut;
  needle x=ObsNum y=CookD / datalabel = MyLabel;
  refline &cutoff / axis=y;
run;
Contributor
Posts: 30

Re: Cook's Distance Plot: Label and Lines are not aligned

Thank you very much. That works very fine Smiley Happy

Post a Question
Discussion Stats
  • 4 replies
  • 288 views
  • 2 likes
  • 2 in conversation