Solved
Contributor
Posts: 23

# example of creating Bland-altman plots

Hi All,

Would someone please provide examples to creating Bland-altman
plots ?

Thanks!

Accepted Solutions
Solution
‎09-10-2012 11:25 AM
Valued Guide
Posts: 765

## Re: example of creating Bland-altman plots

hi ... from what I know about Bland-Altman plots ...

* some fake data;

data test;

do _n_ = 1 to 50;

m1 = ceil(100*ranuni(999));

m2 = ceil(100*ranuni(999));

output;

end;

run;

* compute means (x), difference (y);

data bla_alt;

set test;

x = mean(of m;

y = m1 - m2;

run;

* compute mean +/- 1.96 standard deviation to add reference lines to the plot;

proc sql;

select mean(y)-1.96*std(y), mean(y)+1.96*std(y) into :lo, :hi from bla_alt;

quit;

* reset graphics options;

goptions reset=all ftext='calibri' htext=2 gunit=pct;

title1 h=4 'I THINK THIS IS A BLAND-ALTMAN PLOT' ls=2;

* whitespace around plot (if desired);

title2 a=90 ls=2;

title3 a=-90 ls=2;

footnote1 ls=1;

* a blue dot for the symbol;

symbol1 f='wingdings' v='6c'x c=blue h=2;

axis1 offset=(2,2)pct label=('MEAN');

axis2 label=(a=90 'DIFFERENCE');

* plot with dashed reference lines;

proc gplot bla_alt;

plot y*x / haxis=axis1 vaxis=axis2 vref=&lo,0,&hi lvref=3;

run;

quit;

ps attached plot looks like ... Bland–Altman plot - Wikipedia, the free encyclopedia

All Replies
Solution
‎09-10-2012 11:25 AM
Valued Guide
Posts: 765

## Re: example of creating Bland-altman plots

hi ... from what I know about Bland-Altman plots ...

* some fake data;

data test;

do _n_ = 1 to 50;

m1 = ceil(100*ranuni(999));

m2 = ceil(100*ranuni(999));

output;

end;

run;

* compute means (x), difference (y);

data bla_alt;

set test;

x = mean(of m;

y = m1 - m2;

run;

* compute mean +/- 1.96 standard deviation to add reference lines to the plot;

proc sql;

select mean(y)-1.96*std(y), mean(y)+1.96*std(y) into :lo, :hi from bla_alt;

quit;

* reset graphics options;

goptions reset=all ftext='calibri' htext=2 gunit=pct;

title1 h=4 'I THINK THIS IS A BLAND-ALTMAN PLOT' ls=2;

* whitespace around plot (if desired);

title2 a=90 ls=2;

title3 a=-90 ls=2;

footnote1 ls=1;

* a blue dot for the symbol;

symbol1 f='wingdings' v='6c'x c=blue h=2;

axis1 offset=(2,2)pct label=('MEAN');

axis2 label=(a=90 'DIFFERENCE');

* plot with dashed reference lines;

proc gplot bla_alt;

plot y*x / haxis=axis1 vaxis=axis2 vref=&lo,0,&hi lvref=3;

run;

quit;

ps attached plot looks like ... Bland–Altman plot - Wikipedia, the free encyclopedia

Contributor
Posts: 23

## Re: example of creating Bland-altman plots

Hi Mike,

Thank you very much for your help!  When I use my real data I got a warning:

WARNING: The reference line at 0.134745 on the vertical axis labeled __lvedd_diff is out of range.

How should I modify your code?

Valued Guide
Posts: 765

## Re: example of creating Bland-altman plots

hi ... GPLOT chooses the min and max for the Y-axis based on a look at your data values

the calculated value for the reference line must be outside the values chosen for the bounds of the y-axis

you can use an ORDER option on an AXIS statement to control the min and max

here's an example with measurement values between 0 and 1 where the min and max on the y-axis will always be outside the ref lines

the level of ROUNDING in PROC SQL would have to be dictated by the range of your data values (I chose round to hundreths but that might not always be apppropriate)

data test;

do _n_ = 1 to 50;

m1 = ranuni(999);

m2 = ranuni(999);

output;

end;

run;

data bla_alt;

set test;

x = mean(of m;

y = m1 - m2;

run;

proc sql noprint;

select mean(y)-1.96*std(y), mean(y)+1.96*std(y),

round(mean(y)-2.5*std(y),0.01), round(mean(y)+2.5*std(y),0.01)

into :lo, :hi , :min , :max from bla_alt;

quit;

goptions reset=all ftext='calibri' htext=2 gunit=pct;

title1 h=4 'BLAND-ALTMAN PLOT WITH AN ORDER OPTION FOR Y-AXIS' ls=2;

* whitespace;

title2 a=90 ls=2;

title3 a=-90 ls=2;

footnote1 ls=1;

symbol1 f='wingdings' v='6c'x c=blue h=2;

axis1 offset=(2,2)pct label=('MEAN');

* min and max macro variables used for range of y-axis;

axis2 label=(a=90 'DIFFERENCE') order=&min to &max;

proc gplot data=bla_alt;

plot y*x / haxis=axis1 vaxis=axis2 vref=&lo,0,&hi lvref=3;

run;

quit;

Contributor
Posts: 23

## Re: example of creating Bland-altman plots

Hi Mike,

It works great! Thank you very much!!!

New Contributor
Posts: 2

## Re: example of creating Bland-altman plots

The result shows a Bland-Altman plot as a scatter plot.

data mydata;
input new old;
datalines;
31 45
27 12
11 37
36 25
14 8
27 15
3 11
62 42
38 35
20 9
35 54
62 67
48 25
77 64
45 53
32 42
16 19
15 27
22 9
8 38
24 16
59 25
;

data diffs ;
set mydata ;
/* calculate the difference */
diff=new-old ;
/* calculate the average */
mean=(new+old)/2 ;
run ;
proc print data=diffs;
run;

proc sql noprint ;
select mean(diff)-2*std(diff), mean(diff)+2*std(diff)
into :lower, :upper
from diffs ;
quit;

proc sgplot data=diffs ;
scatter x=mean y=diff;
refline 0 &upper &lower / LABEL = (“zero bias line” “95% upper limit” “95%
lower limit”) ;
TITLE ‘Bland-Altman Plot’;
footnote ‘Accurate prediction with 10% homogeneous error’;
run ;
quit ;

When the above code is executed, we get the following result:

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 5 replies
• 2652 views
• 5 likes
• 3 in conversation