## Perpendicular error bars

I work on an analysis of agreement between two independent measurements from the same subjects (errors-variables-model, Demming regression). I want show the deviations from the identity line (Y1=Y2) as needles perpendicular to the 45 degree line. I cannot use the standard error bars option in SGPLOT.

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Perpendicular error bars

If (x, y) is one of your data points, you can use calculus to show that the perpendicular distance to the identity line is the point

( (x+y)/2, (x+y)/2).  So just write a DATA step and use the VECTR statement:

``````data Have;
input x y;
datalines;
1 2
3 5
2 3
2 1
4 5
5 3
3 4
4 4
4 .
;

data Want;
set Have;
x1 = (x + y)/2;
run;

proc sgplot data=Want aspectratio=1;
scatter x=x y=y;
vector x=x y=y / xorigin=x1 yorigin=x1 noarrowheads;
lineparm x=0 y=0 slope=1;
run;``````
4 REPLIES 4

## Re: Perpendicular error bars

Since you didn't really tell us how you did the Deming regression, I will have to assume that you have the original data point, and the orthogonal projection onto the regression line.

If you have these, then you can use the SG annotation feature that works with PROC SGPLOT, specifically the LINE function or the %SGLINE macro. A brief example is here: https://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n0eben23mwnl3dn1cm95zbks0eea.htm&doc...

--
Paige Miller

## Re: Perpendicular error bars

Hi PaigeMiller,
I used Wicklin's IML code:

https://blogs.sas.com/content/iml/2019/01/07/deming-regression-sas.html,

## Re: Perpendicular error bars

Okay, but ... do you have the values of the perpendicular projections onto the line?

--
Paige Miller

## Re: Perpendicular error bars

If (x, y) is one of your data points, you can use calculus to show that the perpendicular distance to the identity line is the point

( (x+y)/2, (x+y)/2).  So just write a DATA step and use the VECTR statement:

``````data Have;
input x y;
datalines;
1 2
3 5
2 3
2 1
4 5
5 3
3 4
4 4
4 .
;

data Want;
set Have;
x1 = (x + y)/2;
run;

proc sgplot data=Want aspectratio=1;
scatter x=x y=y;
vector x=x y=y / xorigin=x1 yorigin=x1 noarrowheads;
lineparm x=0 y=0 slope=1;
run;``````
Discussion stats
• 4 replies
• 317 views
• 2 likes
• 3 in conversation