{"id":547,"date":"2015-08-01T12:51:44","date_gmt":"2015-08-01T11:51:44","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=547"},"modified":"2025-07-01T11:50:52","modified_gmt":"2025-07-01T10:50:52","slug":"bland-altman-plot","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/bland-altman-plot\/","title":{"rendered":"Bland-Altman Plot"},"content":{"rendered":"\n<p>Bland-Altman plots<sup class='sup-ref-note' id='note-zotero-ref-p547-r1-o1'><a class='sup-ref-note' href='#zotero-ref-p547-r1'>1<\/a><\/sup> are used to display agreement between two investigations \/ tests in terms of <a href=\"https:\/\/pcool.dyndns.org\/index.php\/repeatability-and-reproducibility\/\" data-type=\"page\" data-id=\"835\">repeatability and reproducibility<\/a>. If one of the measures is a gold standard, the plot can be used to display <a href=\"https:\/\/pcool.dyndns.org\/index.php\/bias-and-accuracy\/\" data-type=\"page\" data-id=\"838\">bias<\/a> of the alternative test. Download the <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/plotba.rda\" target=\"_blank\" rel=\"noreferrer noopener\">plotba.rda<\/a> dataset for this example.<\/p>\n\n\n\n<p>The data set contains measurements of two ways of measuring the haemoglobin concentration, a non-invasive way and the &#8216;gold standard&#8217; laboratory test. The measurements are in g \/ L.<\/p>\n\n\n\n<p>The <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/R_functions\/BAplot.txt\" target=\"_blank\" rel=\"noreferrer noopener\">Bland-Altman function<\/a> can be used to create the plot. Copy the code to the clipboard, paste it into the console and hit return. The function is now available in R.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">baplot &lt;- function(m1, m2, ...) {\n  # m1 and m2 are the measurements and the input arguments\n  means &lt;- (m1 + m2) \/ 2\n  diffs &lt;- m1 - m2\n  mdiff &lt;- mean(diffs)\n  sddiff &lt;- sd(diffs)\n  # Compute the figure limits\n  ylimh &lt;- mdiff + 3 * sddiff\n  yliml &lt;- mdiff - 3 * sddiff\n  # Plot data\n  plot(diffs ~ means, <\/span><\/em>\n    <em><span style=\"color: #ff0000;\">xlab = \"Average measurement values\",pch=16,\n    ylab = \"Differences\", ylim = c(yliml, ylimh), ...)\n  abline(h = mdiff) # Center line\n  # Standard deviations lines\n  abline(h = mdiff + 1.96 * sddiff, lty = 2)\n  abline(h = mdiff - 1.96 * sddiff, lty = 2)\n  title(\"Bland-Altman plot\")\n}<\/span><\/em><\/code><\/pre>\n\n\n\n<p>The function can be called by entering baplot(variable1, variable2). In the plotba data frame, the variables are: noninvasive and lab. Therefore, the plot can be created by:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>baplot(plotba$noninvasive, plotba$lab)<\/em><\/span><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/blandaltmanplothb-1024x768.png\" alt=\"\" class=\"wp-image-2878\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/blandaltmanplothb-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/blandaltmanplothb-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/blandaltmanplothb-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/blandaltmanplothb.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>To obtain the mean measurement values:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>mean(plotba$noninvasive)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#091;1] 139.5<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>mean(plotba$lab)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#091;1] 141.1<\/em><\/span><\/code><\/pre>\n\n\n\n<p>Therefore, the non-invasive method underestimates the haemoglobin concentration as compared to the gold standard. This can also be seen in the plot, as the mean difference is below zero (solid horizontal line) and the non-invasive method is <strong>biased<\/strong> as compared to the gold standard; underestimating its value.<\/p>\n\n\n\n<p>A wide confidence interval (large difference between the dotted horizontal lines) indicates poor agreement between readings.<\/p>\n\n\n\n<p>When interpreting Bland-Altman plots, it is also important to look at patterns in the diagram. It may be that the agreement varies according to the magnitude of the measurement.<\/p>\n\n\n\n<p>Plot axes labels can be altered by editing the baplot function.<\/p>\n\n\n\n<p>More versatile plots can be created with the ggplot2 package<sup class='sup-ref-note' id='note-zotero-ref-p547-r2-o1'><a class='sup-ref-note' href='#zotero-ref-p547-r2'>2<\/a><\/sup>:<\/p>\n\n\n\n<p>Again, download the\u00a0<a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/plotba.rda\" target=\"_blank\" rel=\"noreferrer noopener\">plotba.rda<\/a>\u00a0dataset for this example. Calculate the mean of the two observations and the difference between the two observations:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f40202\" class=\"has-inline-color\">> head(plotba)\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0802f5\" class=\"has-inline-color\">  number noninvasive lab\n1      1         131 135\n2      2         125 127\n3      3         132 128\n4      4         146 149\n5      5         148 152\n6      6         115 119<\/mark><\/em>\n\n<span style=\"color: #ff0000;\"><em># calculated the mean between the two methods:<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>plotba$means &lt;- (plotba$noninvasive + plotba$lab) \/ 2<\/em><\/span>\n<span style=\"color: #ff0000;\"><em># calculate the difference between the two methods<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>plotba$diffs &lt;- plotba$noninvasive - plotba$lab<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>head(plotba)<\/em><\/span>\n<em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3b04f6\" class=\"has-inline-color\">  number noninvasive lab means diffs\n1      1         131 135 133.0    -4\n2      2         125 127 126.0    -2\n3      3         132 128 130.0     4\n4      4         146 149 147.5    -3\n5      5         148 152 150.0    -4\n6      6         115 119 117.0    -4<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Calculate the mean and standard deviation of the differences:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>mdiff &lt;- mean(plotba$diffs)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>sddiff &lt;- sd(plotba$diffs)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>mdiff<\/em><\/span>\n<em><span style=\"color: #0000ff;\">&#091;1] -1.6<\/span><\/em>\n<span style=\"color: #ff0000;\"><em>sddiff<\/em><\/span>\n<em><span style=\"color: #0000ff;\">&#091;1] 2.835861<\/span><\/em><\/code><\/pre>\n\n\n\n<p>Load the ggplot2 package and plot the data:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">library(ggplot2)<\/span><\/em>\n<em><span style=\"color: #ff0000;\">ggplot(plotba, aes(x = means, y = diffs)) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_point() +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_hline(yintercept = mdiff - 1.96*sddiff, colour = \"blue\", <\/span><\/em>\n  <em><span style=\"color: #ff0000;\">linetype = 3) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_hline(yintercept = mdiff + 1.96*sddiff, colour = \"blue\", <\/span><\/em>\n  <em><span style=\"color: #ff0000;\">linetype = 3) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_hline(yintercept = mdiff, colour = \"black\", linetype = 2) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">ggtitle(\"Bland-Altman plot\") +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">scale_x_continuous(\"Average Measurement Values\") +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">scale_y_continuous(\"Differences\", <\/span><\/em>\n  <em><span style=\"color: #ff0000;\">limit = c(mdiff - 3*sddiff, mdiff + 3*sddiff)) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">theme_bw(base_size= 16)<\/span><\/em><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1021\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/BAplot-1024x1021.png\" alt=\"\" class=\"wp-image-2807\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/BAplot-1024x1021.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/BAplot-300x300.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/BAplot-150x150.png 150w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/BAplot-768x766.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/BAplot-1536x1532.png 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/BAplot.png 1538w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Bland-Altman plots are used to display agreement between two investigations \/ tests in terms of repeatability and reproducibility. If one of the measures is a gold standard, the plot can be used to display bias of the alternative test. Download the plotba.rda dataset for this example. The data set contains measurements of two ways of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-547","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=547"}],"version-history":[{"count":1,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/547\/revisions"}],"predecessor-version":[{"id":4703,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/547\/revisions\/4703"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}