Title: | Bland-Altman Method Comparison |
---|---|
Description: | Carries out Bland Altman analyses (also known as a Tukey mean-difference plot) as described by JM Bland and DG Altman in 1986 <doi:10.1016/S0140-6736(86)90837-8>. This package was created in 2015 as existing Bland-Altman analysis functions did not calculate confidence intervals. This package was created to rectify this, and create reproducible plots. This package is also available as a module for the 'jamovi' statistical spreadsheet (see <https://www.jamovi.org> for more information). |
Authors: | Deepankar Datta [aut, cre], Jonathon Love [ctb] |
Maintainer: | Deepankar Datta <[email protected]> |
License: | GPL-3 |
Version: | 0.6.0 |
Built: | 2025-02-04 04:55:25 UTC |
Source: | https://github.com/deepankardatta/blandr |
This is the sample PEFR data set from the 1986 Lancet paper written by Bland and Altman. I do not claim any copyright on the data - this is meant to allow testing of the function. I encourage future package authors to use the .rda file if they so wish.
data("bland.altman.PEFR.1986")
data("bland.altman.PEFR.1986")
A data frame with 17 observations on the following 4 variables.
WrightFirst
a numeric vector
WrightSecond
a numeric vector
MiniWrightFirst
a numeric vector
MiniWrightSecond
a numeric vector
Bland, J. M., & Altman, D. (1986). Statistical methods for assessing agreement between two methods of clinical measurement. The Lancet, 327(8476), 307-310. PMID:2868172. http://dx.doi.org/10.1016/S0140-6736(86)90837-8
data(bland.altman.PEFR.1986)
data(bland.altman.PEFR.1986)
Prepares the data and runs error checks before the calling function runs whatever method analysis mode is wants.
blandr.data.preparation(method1, method2, sig.level)
blandr.data.preparation(method1, method2, sig.level)
method1 |
A list of numbers. |
method2 |
A list of numbers. |
sig.level |
Significance level. Is not optional in this function, as the calling package should have a default value to pass if needed |
method.comparison A data frame of paired values. These have been data checked, and empty rows omitted, from the originally supplied data.
Deepankar Datta [email protected]
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Calls the function - do note that this function was really # meant to be called from other functions and not a stand-alone funtion blandr.data.preparation( measurement1 , measurement2, sig.level=0.95 )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Calls the function - do note that this function was really # meant to be called from other functions and not a stand-alone funtion blandr.data.preparation( measurement1 , measurement2, sig.level=0.95 )
Loads the D'arbela mean velocity of circumferential fibre shortening dataset from Martin Bland's website.
blandr.dataset.fibre()
blandr.dataset.fibre()
converted.from.dct A data frame containing the dataset
The function converts the STATA DCT data format into a data frame that R can process.
Deepankar Datta [email protected]
https://www-users.york.ac.uk/~mb55/datasets/pefr.dct - The D'arbela mean velocity of circumferential fibre shortening dataset from Martin Bland's website
https://www-users.york.ac.uk/~mb55/datasets/datasets.htm - Martin Bland's example data-set webpage
Bland JM, Altman DG. (1986) Statistical methods for assessing agreement between two methods of clinical measurement. Lancet i, 307-310.
blandr.dataset.fibre() pefr.data <- blandr.dataset.fibre()
blandr.dataset.fibre() pefr.data <- blandr.dataset.fibre()
Loads example data sets from the internet.
blandr.dataset.load(dataset.name)
blandr.dataset.load(dataset.name)
dataset.name |
Loads the requisite data set. See the description for further details. |
example.dataset A data frame containing the requisite dataset
Dataset 1 ("1","PEFR","pefr") - Bland Altman PEFR dataset (from blandr.dataset.pefr
)
Dataset 2 ("2","o2sats","sealey") - Selaey oxygen saturations dataset (from blandr.dataset.o2sats
)
Dataset 3 ("3","fibre","darbela") - D'arbela mean velocity of circumferential fibre shortening dataset (from blandr.dataset.fibre
)
Dataset 4 ("4","sbp","close") - Close systolic blood pressure dataset (from blandr.dataset.sbp
)
Deepankar Datta [email protected]
blandr.dataset.load( "pefr" ) pefr.data <- blandr.dataset.load( "pefr" )
blandr.dataset.load( "pefr" ) pefr.data <- blandr.dataset.load( "pefr" )
Loads the Bland-Altman oxygen saturation dataset from Martin Bland's website.
blandr.dataset.o2sats()
blandr.dataset.o2sats()
converted.from.dct A data frame containing the dataset
The function converts the STATA DCT data format into a data frame that R can process.
Deepankar Datta [email protected]
https://www-users.york.ac.uk/~mb55/datasets/sealey.dct - The oxygen saturation dataset from Martin Bland's website
https://www-users.york.ac.uk/~mb55/datasets/datasets.htm - Martin Bland's example data-set webpage
Bland JM, Altman DG. (1986) Statistical methods for assessing agreement between two methods of clinical measurement. Lancet i, 307-310.
blandr.dataset.o2sats() pefr.data <- blandr.dataset.o2sats()
blandr.dataset.o2sats() pefr.data <- blandr.dataset.o2sats()
Loads the Bland-Altman PEFR dataset from Martin Bland's website.
blandr.dataset.pefr()
blandr.dataset.pefr()
converted.from.dct A data frame containing the dataset
The function converts the STATA DCT data format into a data frame that R can process.
Deepankar Datta [email protected]
https://www-users.york.ac.uk/~mb55/datasets/pefr.dct - The PEFR dataset from Martin Bland's website
https://www-users.york.ac.uk/~mb55/datasets/datasets.htm - Martin Bland's example data-set webpage
Bland JM, Altman DG. (1986) Statistical methods for assessing agreement between two methods of clinical measurement. Lancet i, 307-310.
blandr.dataset.pefr() pefr.data <- blandr.dataset.pefr()
blandr.dataset.pefr() pefr.data <- blandr.dataset.pefr()
Loads the Close systolic blood pressure dataset from Martin Bland's website.
blandr.dataset.sbp()
blandr.dataset.sbp()
converted.from.dct A data frame containing the dataset
The function converts the STATA DCT data format into a data frame that R can process.
Deepankar Datta [email protected]
https://www-users.york.ac.uk/~mb55/datasets/pefr.dct - The Close systolic blood pressure dataset from Martin Bland's website
https://www-users.york.ac.uk/~mb55/datasets/datasets.htm - Martin Bland's example data-set webpage
Bland JM, Altman DG. (1995) Comparing methods of measurement: why plotting difference against standard method is misleading. Lancet, 346, 1085-7.
blandr.dataset.sbp() pefr.data <- blandr.dataset.sbp()
blandr.dataset.sbp() pefr.data <- blandr.dataset.sbp()
Stub function: calls both the display and plots functions (in that order). Uses the same parameters as the plot and display functions to allow easy all-in-one use.
This function may be deprecated in future, as you really can use the functions easily separately.
blandr.display.and.draw( method1, method2, plotter = "ggplot", method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", sig.level = 0.95, annotate = FALSE, ciDisplay = TRUE, ciShading = FALSE, normalLow = FALSE, normalHigh = FALSE, lowest_y_axis = FALSE, highest_y_axis = FALSE, point_size = 0.8 )
blandr.display.and.draw( method1, method2, plotter = "ggplot", method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", sig.level = 0.95, annotate = FALSE, ciDisplay = TRUE, ciShading = FALSE, normalLow = FALSE, normalHigh = FALSE, lowest_y_axis = FALSE, highest_y_axis = FALSE, point_size = 0.8 )
method1 |
A list of numbers. |
method2 |
A list of numbers. |
plotter |
(Optional- default='ggplot') Selects which graphics engine to use to plot the Bland-Altman charts. 2 options are 'ggplot' or 'rplot'. If unknown parameter sent, will default to 'ggplot' |
method1name |
(Optional) Plotting name for 1st method, default 'Method 1' |
method2name |
(Optional) Plotting name for 2nd method, default 'Method 2' |
plotTitle |
(Optional) Title name, default 'Bland-Altman plot for comparison of 2 methods' |
sig.level |
(Optional) Two-tailed significance level. Expressed from 0 to 1. Defaults to 0.95. |
annotate |
(Optional) TRUE/FALSE switch to provides annotations to plot, default=FALSE |
ciDisplay |
(Optional) TRUE/FALSE switch to plot confidence intervals for bias and limits of agreement, default=TRUE |
ciShading |
(Optional) TRUE/FALSE switch to plot confidence interval shading to plot, default=TRUE |
normalLow |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its lower boundary |
normalHigh |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its higher boundary |
lowest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the lower boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
highest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the upper boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
point_size |
(Optional) Size of marker for each dot. Default is cex=0.8 |
Deepankar Datta [email protected]
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates a plot, with no optional arguments blandr.display.and.draw( measurement1 , measurement2 ) # Generates a plot, with title blandr.display.and.draw( measurement1 , measurement2 , plotTitle = 'Bland-Altman example plot' )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates a plot, with no optional arguments blandr.display.and.draw( measurement1 , measurement2 ) # Generates a plot, with title blandr.display.and.draw( measurement1 , measurement2 , plotTitle = 'Bland-Altman example plot' )
(DEPRECATED) Re-directs to blandr.display.and.draw
blandr.display.and.plot( method1, method2, method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", sig.level = 0.95, annotate = FALSE, ciDisplay = TRUE, ciShading = FALSE, normalLow = FALSE, normalHigh = FALSE, lowest_y_axis = FALSE, highest_y_axis = FALSE, point_size = 0.8 )
blandr.display.and.plot( method1, method2, method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", sig.level = 0.95, annotate = FALSE, ciDisplay = TRUE, ciShading = FALSE, normalLow = FALSE, normalHigh = FALSE, lowest_y_axis = FALSE, highest_y_axis = FALSE, point_size = 0.8 )
method1 |
A list of numbers. |
method2 |
A list of numbers. |
method1name |
(Optional) Plotting name for 1st method, default 'Method 1' |
method2name |
(Optional) Plotting name for 2nd method, default 'Method 2' |
plotTitle |
(Optional) Title name, default 'Bland-Altman plot for comparison of 2 methods' |
sig.level |
(Optional) Two-tailed significance level. Expressed from 0 to 1. Defaults to 0.95. |
annotate |
(Optional) TRUE/FALSE switch to provides annotations to plot, default=FALSE |
ciDisplay |
(Optional) TRUE/FALSE switch to plot confidence intervals for bias and limits of agreement, default=TRUE |
ciShading |
(Optional) TRUE/FALSE switch to plot confidence interval shading to plot, default=TRUE |
normalLow |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its lower boundary |
normalHigh |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its higher boundary |
lowest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the lower boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
highest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the upper boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
point_size |
(Optional) Size of marker for each dot. Default is cex=0.8 |
Deepankar Datta [email protected]
Bland-Altman drawing function. Depends on the blandr.statistics function in the package. Will generate a plot via the standard R plotting functions.
blandr.draw( method1, method2, method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", sig.level = 0.95, LoA.mode = 1, annotate = FALSE, ciDisplay = TRUE, ciShading = TRUE, normalLow = FALSE, normalHigh = FALSE, lowest_y_axis = FALSE, highest_y_axis = FALSE, point_size = 0.8, overlapping = FALSE, plotter = "ggplot", x.plot.mode = "means", y.plot.mode = "difference", plotProportionalBias = FALSE, plotProportionalBias.se = TRUE, assume.differences.are.normal = TRUE )
blandr.draw( method1, method2, method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", sig.level = 0.95, LoA.mode = 1, annotate = FALSE, ciDisplay = TRUE, ciShading = TRUE, normalLow = FALSE, normalHigh = FALSE, lowest_y_axis = FALSE, highest_y_axis = FALSE, point_size = 0.8, overlapping = FALSE, plotter = "ggplot", x.plot.mode = "means", y.plot.mode = "difference", plotProportionalBias = FALSE, plotProportionalBias.se = TRUE, assume.differences.are.normal = TRUE )
method1 |
A vector of numbers corresponding to the results from method 1. |
method2 |
A vector of numbers corresponding to the results from method 2. |
method1name |
(Optional) Plotting name for 1st method, default 'Method 1' |
method2name |
(Optional) Plotting name for 2nd method, default 'Method 2' |
plotTitle |
(Optional) Title name, default 'Bland-Altman plot for comparison of 2 methods' |
sig.level |
(Optional) Two-tailed significance level. Expressed from 0 to 1. Defaults to 0.95. |
LoA.mode |
(Optional) Switch to change how accurately the limits of agreement (LoA) are calculated from the bias and its standard deviation. The default is LoA.mode=1 which calculates LoA with the more accurate 1.96x multiplier. LoA.mode=2 uses the 2x multiplier which was used in the original papers. This should really be kept at default, except to double check calculations in older papers. |
annotate |
(Optional) TRUE/FALSE switch to provides annotations to plot, default=FALSE |
ciDisplay |
(Optional) TRUE/FALSE switch to plot confidence intervals for bias and limits of agreement, default=TRUE |
ciShading |
(Optional) TRUE/FALSE switch to plot confidence interval shading to plot, default=TRUE |
normalLow |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its lower boundary |
normalHigh |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its higher boundary |
lowest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the lower boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
highest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the upper boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
point_size |
(Optional) Size of marker for each dot. Default is cex=0.8 |
overlapping |
(Optional) TRUE/FALSE switch to increase size of plotted point if multiple values using ggplot's geom_count, default=FALSE. Not currently recommend until I can tweak the graphics to make them better |
plotter |
(Optional- default='ggplot') Selects which graphics engine to use to plot the Bland-Altman charts. 2 options are 'ggplot' or 'rplot'. If unknown parameter sent, will default to 'ggplot' |
x.plot.mode |
(Optional) Switch to change x-axis from being plotted by means (="means") or by either 1st method (="method1") or 2nd method (="method2"). Default is "means". Anything other than "means" will switch to default mode. |
y.plot.mode |
(Optional) Switch to change y-axis from being plotted by difference (="difference") or by proportion magnitude of measurements (="proportion"). Default is "difference". Anything other than "proportional" will switch to default mode. |
plotProportionalBias |
(Optional) TRUE/FALSE switch. Plots a proportional bias line. Default is FALSE. |
plotProportionalBias.se |
(Optional) TRUE/FALSE switch. If proportional bias line is drawn, switch to plot standard errors. See stat_smooth for details. Default is TRUE. |
assume.differences.are.normal |
(Optional, not operationally used currently) Assume the difference of means has a normal distribution. Will be used to build further analyses |
Started 2015-11-14
Last update 2015-11-19
Originally designed for LAVAS and CVLA
Deepankar Datta [email protected]
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates a plot, with no optional arguments blandr.draw( measurement1 , measurement2 ) # Generates a plot, using the in-built R graphics blandr.draw( measurement1 , measurement2 , plotter = 'rplot' ) # Generates a plot, with title changed blandr.draw( measurement1 , measurement2 , plotTitle = 'Bland-Altman example plot' ) # Generates a plot, with title changed, and confidence intervals off blandr.draw( measurement1 , measurement2 , plotTitle = 'Bland-Altman example plot' , ciDisplay = FALSE , ciShading = FALSE )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates a plot, with no optional arguments blandr.draw( measurement1 , measurement2 ) # Generates a plot, using the in-built R graphics blandr.draw( measurement1 , measurement2 , plotter = 'rplot' ) # Generates a plot, with title changed blandr.draw( measurement1 , measurement2 , plotTitle = 'Bland-Altman example plot' ) # Generates a plot, with title changed, and confidence intervals off blandr.draw( measurement1 , measurement2 , plotTitle = 'Bland-Altman example plot' , ciDisplay = FALSE , ciShading = FALSE )
Everyone likes graphs, lines and T-tests. This uses the data provided to generate simple tests whilst trying to explain why they should be treated with caution in method comparison studies. This is hopefully the first step in getting people to use the Bland-Altman functions as I suspect everyone will try to do these tests anyway.
blandr.method.comparison(method1, method2, sig.level = 0.95)
blandr.method.comparison(method1, method2, sig.level = 0.95)
method1 |
A list of numbers. |
method2 |
A list of numbers. |
sig.level |
(Optional) Two-tailed significance level. Expressed from 0 to 1. Defaults to 0.95. |
Deepankar Datta [email protected]
Based on: (1) Bland, J. M., & Altman, D. (1986). Statistical methods for assessing agreement between two methods of clinical measurement. The Lancet, 327(8476), 307-310. http://dx.doi.org/10.1016/S0140-6736(86)90837-8
Linnet K., Limitations of the paired t-test for evaluation of method comparison data. Clin Chem. 1999 Feb;45(2):314-5. PMID: 9931067
Zaki R, Bulgiba A, Ismail R, Ismail NA. Statistical Methods Used to Test for Agreement of Medical Instruments Measuring Continuous Variables in Method Comparison Studies: A Systematic Review PLoS ONE 2012 7(5): e37908. doi: 10.1371/journal.pone.0037908
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Call the function blandr.method.comparison( measurement1 , measurement2 )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Call the function blandr.method.comparison( measurement1 , measurement2 )
Generates a report for the Bland-Altman statistics using rMarkdown and Shiny.
blandr.output.report(method1, method2)
blandr.output.report(method1, method2)
method1 |
A list of numbers for the first method |
method2 |
A list of numbers for the second method |
Use the function to generate a report. You can also take the .Rmd file to customise it and create
your own report. Or use rMarkdown to save the contents. I couldn't add this to the function as it's
not allowed in CRAN. On the other hand a full Shiny app would take too long. So this is a stop-gap way
of creating this function. Hopefully I can improve it in the future
Deepankar Datta [email protected]
# NOT RUN # Generates two random measurements # measurement1 <- rnorm(100) # measurement2 <- rnorm(100) # blandr.output.report( measurement1 , measurement2 ) # # Use this to manually run the rmarkdown template # However specify where the template is # Also define your methods as method1 and method2 exactly # For a reason I can't fathom (or how the list of parameters is constructed) # not naming them method1 and method2 makes them invisible to the rMarkdown document # # rmarkdown::run( file = "blandr_report_template.Rmd" , # render_args = list( runtime = "shiny" , # params = list( method1 = method1 , # method2 = method2 ) ) ) # END OF NOT RUN
# NOT RUN # Generates two random measurements # measurement1 <- rnorm(100) # measurement2 <- rnorm(100) # blandr.output.report( measurement1 , measurement2 ) # # Use this to manually run the rmarkdown template # However specify where the template is # Also define your methods as method1 and method2 exactly # For a reason I can't fathom (or how the list of parameters is constructed) # not naming them method1 and method2 makes them invisible to the rMarkdown document # # rmarkdown::run( file = "blandr_report_template.Rmd" , # render_args = list( runtime = "shiny" , # params = list( method1 = method1 , # method2 = method2 ) ) ) # END OF NOT RUN
(DEPRECATED) Displays results of Bland-Altman analysis in a nicer text format. Relies on the blandr.statistics function in the package.
blandr.output.text(method1, method2, sig.level = 0.95)
blandr.output.text(method1, method2, sig.level = 0.95)
method1 |
A list of numbers. |
method2 |
A list of numbers. |
sig.level |
(Optional) Two-tailed significance level. Expressed from 0 to 1. Defaults to 0.95. |
Deepankar Datta [email protected]
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Displays basic statistics for the two measurements in a readable form blandr.output.text( measurement1 , measurement2 )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Displays basic statistics for the two measurements in a readable form blandr.output.text( measurement1 , measurement2 )
(DEPRECATED) Re-directs to blandr.draw.r
blandr.plot( method1, method2, plotter = "ggplot", method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", sig.level = 0.95, annotate = FALSE, ciDisplay = TRUE, ciShading = TRUE, normalLow = FALSE, normalHigh = FALSE, lowest_y_axis = FALSE, highest_y_axis = FALSE, point_size = 0.8 )
blandr.plot( method1, method2, plotter = "ggplot", method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", sig.level = 0.95, annotate = FALSE, ciDisplay = TRUE, ciShading = TRUE, normalLow = FALSE, normalHigh = FALSE, lowest_y_axis = FALSE, highest_y_axis = FALSE, point_size = 0.8 )
method1 |
A vector of numbers corresponding to the results from method 1. |
method2 |
A vector of numbers corresponding to the results from method 2. |
plotter |
(Optional- default='ggplot') Selects which graphics engine to use to plot the Bland-Altman charts. 2 options are 'ggplot' or 'rplot'. If unknown parameter sent, will default to 'ggplot' |
method1name |
(Optional) Plotting name for 1st method, default 'Method 1' |
method2name |
(Optional) Plotting name for 2nd method, default 'Method 2' |
plotTitle |
(Optional) Title name, default 'Bland-Altman plot for comparison of 2 methods' |
sig.level |
(Optional) Two-tailed significance level. Expressed from 0 to 1. Defaults to 0.95. |
annotate |
(Optional) TRUE/FALSE switch to provides annotations to plot, default=FALSE |
ciDisplay |
(Optional) TRUE/FALSE switch to plot confidence intervals for bias and limits of agreement, default=TRUE |
ciShading |
(Optional) TRUE/FALSE switch to plot confidence interval shading to plot, default=TRUE |
normalLow |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its lower boundary |
normalHigh |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its higher boundary |
lowest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the lower boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
highest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the upper boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
point_size |
(Optional) Size of marker for each dot. Default is cex=0.8 |
Deepankar Datta [email protected]
Draws a Bland-Altman plot using data calculated using the other functions, using ggplot2
blandr.plot.ggplot( statistics.results, method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", ciDisplay = TRUE, ciShading = TRUE, normalLow = FALSE, normalHigh = FALSE, overlapping = FALSE, x.plot.mode = "means", y.plot.mode = "difference", plotProportionalBias = FALSE, plotProportionalBias.se = TRUE, assume.differences.are.normal = TRUE )
blandr.plot.ggplot( statistics.results, method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", ciDisplay = TRUE, ciShading = TRUE, normalLow = FALSE, normalHigh = FALSE, overlapping = FALSE, x.plot.mode = "means", y.plot.mode = "difference", plotProportionalBias = FALSE, plotProportionalBias.se = TRUE, assume.differences.are.normal = TRUE )
statistics.results |
A list of statistics generated by the blandr.statistics function: see the function's return list to see what variables are passed to this function |
method1name |
(Optional) Plotting name for 1st method, default "Method 1" |
method2name |
(Optional) Plotting name for 2nd method, default "Method 2" |
plotTitle |
(Optional) Title name, default "Bland-Altman plot for comparison of 2 methods" |
ciDisplay |
(Optional) TRUE/FALSE switch to plot confidence intervals for bias and limits of agreement, default is TRUE |
ciShading |
(Optional) TRUE/FALSE switch to plot confidence interval shading to plot, default is TRUE |
normalLow |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its lower boundary |
normalHigh |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its higher boundary |
overlapping |
(Optional) TRUE/FALSE switch to increase size of plotted point if multiple values using ggplot's geom_count, default=FALSE. Not currently recommend until I can tweak the graphics to make them better |
x.plot.mode |
(Optional) Switch to change x-axis from being plotted by means (="means") or by either 1st method (="method1") or 2nd method (="method2"). Default is "means". Anything other than "means" will switch to default mode. |
y.plot.mode |
(Optional) Switch to change y-axis from being plotted by difference (="difference") or by proportion magnitude of measurements (="proportion"). Default is "difference". Anything other than "proportional" will switch to default mode. |
plotProportionalBias |
(Optional) TRUE/FALSE switch. Plots a proportional bias line. Default is FALSE. |
plotProportionalBias.se |
(Optional) TRUE/FALSE switch. If proportional bias line is drawn, switch to plot standard errors. See stat_smooth for details. Default is TRUE. |
assume.differences.are.normal |
(Optional, not operationally used currently) Assume the difference of means has a normal distribution. Will be used to build further analyses |
ba.plot Returns a ggplot data set that can then be plotted
Deepankar Datta [email protected]
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates a ggplot # Do note the ggplot function wasn't meant to be used on it's own # and is generally called via the bland.altman.display.and.draw function # Passes data to the blandr.statistics function to generate Bland-Altman statistics statistics.results <- blandr.statistics( measurement1 , measurement2 ) # Generates a ggplot, with no optional arguments blandr.plot.ggplot( statistics.results ) # Generates a ggplot, with title changed blandr.plot.ggplot( statistics.results , plotTitle = "Bland-Altman example plot" ) # Generates a ggplot, with title changed, and confidence intervals off blandr.plot.ggplot( statistics.results , plotTitle = "Bland-Altman example plot" , ciDisplay = FALSE , ciShading = FALSE )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates a ggplot # Do note the ggplot function wasn't meant to be used on it's own # and is generally called via the bland.altman.display.and.draw function # Passes data to the blandr.statistics function to generate Bland-Altman statistics statistics.results <- blandr.statistics( measurement1 , measurement2 ) # Generates a ggplot, with no optional arguments blandr.plot.ggplot( statistics.results ) # Generates a ggplot, with title changed blandr.plot.ggplot( statistics.results , plotTitle = "Bland-Altman example plot" ) # Generates a ggplot, with title changed, and confidence intervals off blandr.plot.ggplot( statistics.results , plotTitle = "Bland-Altman example plot" , ciDisplay = FALSE , ciShading = FALSE )
Works out plot limits for the Bland-Altman plots. Depends on the blandr.statistics function in the package.
blandr.plot.limits( statistics.results, lowest_y_axis = FALSE, highest_y_axis = FALSE )
blandr.plot.limits( statistics.results, lowest_y_axis = FALSE, highest_y_axis = FALSE )
statistics.results |
A list of statistics generated by the blandr.statistics function: see the function's return list to see what variables are passed to this function |
lowest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the lower boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
highest_y_axis |
(Optional) Defaults to NULL If given a continuous variable will use this as the upper boundary of the y axis. Useful if need multiple plots with equivalent y-axes. |
x_upper The upper limit of the X-axis
x_lower The lower limit of the X-axis
y_upper The upper limit of the Y-axis
y_lower The lower limit of the Y-axis
Deepankar Datta [email protected]
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Passes data to the blandr.statistics function to generate Bland-Altman statistics statistics.results <- blandr.statistics( measurement1 , measurement2 ) # Calls the function blandr.plot.limits( statistics.results )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Passes data to the blandr.statistics function to generate Bland-Altman statistics statistics.results <- blandr.statistics( measurement1 , measurement2 ) # Calls the function blandr.plot.limits( statistics.results )
Generates a combined histogram and density curve for Bland-Altman differences
blandr.plot.normality(statistics.results)
blandr.plot.normality(statistics.results)
statistics.results |
A list of statistics generated by the blandr.statistics function: see the function's return list to see what variables are passed to this function |
Deepankar Datta [email protected]
Generates a QQ plot for Bland-Altman differences
blandr.plot.qq(statistics.results)
blandr.plot.qq(statistics.results)
statistics.results |
A list of statistics generated by the blandr.statistics function: see the function's return list to see what variables are passed to this function |
Deepankar Datta [email protected]
Draws a Bland-Altman plot using data calculated using the other functions, using the in-built R graphics
blandr.plot.rplot( statistics.results, plot.limits, method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", annotate = FALSE, ciDisplay = TRUE, ciShading = TRUE, normalLow = FALSE, normalHigh = FALSE, point_size = 0.8 )
blandr.plot.rplot( statistics.results, plot.limits, method1name = "Method 1", method2name = "Method 2", plotTitle = "Bland-Altman plot for comparison of 2 methods", annotate = FALSE, ciDisplay = TRUE, ciShading = TRUE, normalLow = FALSE, normalHigh = FALSE, point_size = 0.8 )
statistics.results |
A list of statistics generated by the blandr.statistics function: see the function's return list to see what variables are passed to this function |
plot.limits |
A list of statistics generated by the blandr.plot.limits function to define the extent of the x- and y- axes: see the function's return list to see what variables are passed to this function |
method1name |
(Optional) Plotting name for 1st method, default 'Method 1' |
method2name |
(Optional) Plotting name for 2nd method, default 'Method 2' |
plotTitle |
(Optional) Title name, default 'Bland-Altman plot for comparison of 2 methods' |
annotate |
(Optional) TRUE/FALSE switch to provides annotations to plot, default=FALSE |
ciDisplay |
(Optional) TRUE/FALSE switch to plot confidence intervals for bias and limits of agreement, default=TRUE |
ciShading |
(Optional) TRUE/FALSE switch to plot confidence interval shading to plot, default=TRUE |
normalLow |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its lower boundary |
normalHigh |
(Optional) If there is a normal range, entering a continuous variable will plot a vertical line on the plot to indicate its higher boundary |
point_size |
(Optional) Size of marker for each dot. Default is cex=0.8 |
Deepankar Datta [email protected]
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates a basic plot # Do note the blandr.plot.rplot function wasn't meant to be used on it's own # and is generally called via the bland.altman.display.and.draw function # Passes data to the blandr.statistics function to generate Bland-Altman statistics statistics.results <- blandr.statistics( measurement1 , measurement2 ) # Passed data to the blandr.plot.limits function to generate plot limits plot.limits <- blandr.plot.limits( statistics.results ) # Generates a basic plot, with no optional arguments blandr.plot.rplot( statistics.results , plot.limits ) # Generates a basic plot, with title changed blandr.plot.rplot( statistics.results , plot.limits , plotTitle = 'Bland-Altman example plot' ) # Generates a basic plot, with title changed, and confidence intervals off blandr.plot.rplot( statistics.results , plot.limits , plotTitle = 'Bland-Altman example plot' , ciDisplay = FALSE , ciShading = FALSE )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates a basic plot # Do note the blandr.plot.rplot function wasn't meant to be used on it's own # and is generally called via the bland.altman.display.and.draw function # Passes data to the blandr.statistics function to generate Bland-Altman statistics statistics.results <- blandr.statistics( measurement1 , measurement2 ) # Passed data to the blandr.plot.limits function to generate plot limits plot.limits <- blandr.plot.limits( statistics.results ) # Generates a basic plot, with no optional arguments blandr.plot.rplot( statistics.results , plot.limits ) # Generates a basic plot, with title changed blandr.plot.rplot( statistics.results , plot.limits , plotTitle = 'Bland-Altman example plot' ) # Generates a basic plot, with title changed, and confidence intervals off blandr.plot.rplot( statistics.results , plot.limits , plotTitle = 'Bland-Altman example plot' , ciDisplay = FALSE , ciShading = FALSE )
Bland-Altman analysis function for R. Package created as existing
functions don't suit my needs, and don't generate 95\
for bias and limits of agreement. This base function calculates the basic
statistics, and generates return values which can be used in the related
blandr.display
and bland.altamn.plot
functions. However
the return results can be used to generate a custom chart if desired.
blandr.statistics(method1, method2, sig.level = 0.95, LoA.mode = 1)
blandr.statistics(method1, method2, sig.level = 0.95, LoA.mode = 1)
method1 |
Either a formula, or a vector of numbers corresponding to the results from method 1. |
method2 |
A vector of numbers corresponding to the results from method 2. Only needed if |
sig.level |
(Optional) Two-tailed significance level. Expressed from 0 to 1. Defaults to 0.95. |
LoA.mode |
(Optional) Switch to change how accurately the limits of agreement (LoA) are calculated from the bias and its standard deviation. The default is LoA.mode=1 which calculates LoA with the more accurate 1.96x multiplier. LoA.mode=2 uses the 2x multiplier which was used in the original papers. This should really be kept at default, except to double check calculations in older papers. |
An object of class 'blandr' is returned. This is a list with the following elements:
means |
List of arithmetic mean of the two methods |
differences |
List of differences of the two methods |
method1 |
Returns the 'method1' list in the data frame if further evaluation is needed |
method2 |
Returns the 'method2' list in the data frame if further evaluation is needed |
sig.level |
Significance level supplied to the function |
sig.level.convert.to.z |
Significance level convert to Z value |
bias |
Bias of the two methods |
biasUpperCI |
Upper confidence interval of the bias (based on significance level) |
biasLowerCI |
Lower confidence interval of the bias (based on significance level) |
biasStdDev |
Standard deviation for the bias |
biasSEM |
Standard error for the bias |
LOA_SEM |
Standard error for the limits of agreement |
upperLOA |
Upper limit of agreement |
upperLOA_upperCI |
Upper confidence interval of the upper limit of agreement |
upperLOA_lowerCI |
Lower confidence interval of the upper limit of agreement |
lowerLOA |
Lower limit of agreement |
lowerLOA_upperCI |
Upper confidence interval of the lower limit of agreement |
lowerLOA_lowerCI |
Lower confidence interval of the lower limit of agreement |
proportion |
Differences/means*100 |
no.of.observations |
Number of observations |
regression.equation |
A regression equation to help determine if there is any proportional bias |
regression.fixed.slope |
The slope value of the regression equation |
regression.fixed.intercept |
The intercept value of the regression equation |
The function will give similar answers when used on the original Bland-Altman PEFR data sets. They won't be exactly the same as (a) for 95\
The function depends on paired values.
It currently only can currently work out fixed bias.
Improvements for the future: proportional bias charts will need further work
Started 2015-11-14
Last update 2016-02-04
Originally designed for LAVAS and CVLA
Deepankar Datta [email protected]
Based on: (1) Bland, J. M., & Altman, D. (1986). Statistical methods for assessing agreement between two methods of clinical measurement. The Lancet, 327(8476), 307-310. http://dx.doi.org/10.1016/S0140-6736(86)90837-8
Confidence interval work based on follow-up paper: (2) Altman, D. G., & Bland, J. M. (2002). Commentary on quantifying agreement between two methods of measurement. Clinical chemistry, 48(5), 801-802. http://www.clinchem.org/content/48/5/801.full.pdf
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates Bland-Altman statistics data of the two measurements blandr.statistics( measurement1 , measurement2 )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates Bland-Altman statistics data of the two measurements blandr.statistics( measurement1 , measurement2 )
If data is supplied as a formula, the function interprets it and then passes it through to the main blandr.statistics function.
blandr.statistics.formula(formula, data = parent.frame(), ...)
blandr.statistics.formula(formula, data = parent.frame(), ...)
formula |
A formula, to be eventually passed to the blandr.statistics function |
data |
A data frame |
... |
other arguments. |
This was initially packaged in the same file as the blandr.statistics function. Changes to R package checks made it easier to separate it out, but functionally it has not changed.
Deepankar Datta [email protected]
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates Bland-Altman statistics data of the two measurements using the formula interface blandr.statistics.formula( measurement2 ~ measurement1 ) # Example with a real data set blandr.statistics.formula( Method.B ~ Method.A, data = giavarina.2015 )
# Generates two random measurements measurement1 <- rnorm(100) measurement2 <- rnorm(100) # Generates Bland-Altman statistics data of the two measurements using the formula interface blandr.statistics.formula( measurement2 ~ measurement1 ) # Example with a real data set blandr.statistics.formula( Method.B ~ Method.A, data = giavarina.2015 )
This is sample comparison data, taken from Giavarina's 2015 paper on Bland-Altman analysis. The data is from table 1 of the paper. I do not claim any copyright on the data - this is meant to allow testing of the function. I encourage future package authors to use the .rda file if they so wish.
data("giavarina.2015")
data("giavarina.2015")
A data frame with 30 observations on the following 5 variables.
Method.A
a numeric vector
Method.B
a numeric vector
Mean
a numeric vector
Difference
a numeric vector
Diff.Mean.Proportion
a factor with levels
Giavarina D. Understanding Bland Altman analysis. Biochemia Medica. 2015;25(2):141-151. doi:10.11613/BM.2015.015.
data(giavarina.2015)
data(giavarina.2015)
Bland-Altman Analysis
jamoviBAanalysis( data, method1, method2, ciDisplay = TRUE, ciShading = TRUE, plotProportionalBias = FALSE, plotProportionalBias.se = TRUE, overlapping = FALSE )
jamoviBAanalysis( data, method1, method2, ciDisplay = TRUE, ciShading = TRUE, plotProportionalBias = FALSE, plotProportionalBias.se = TRUE, overlapping = FALSE )
data |
. |
method1 |
. |
method2 |
. |
ciDisplay |
. |
ciShading |
. |
plotProportionalBias |
. |
plotProportionalBias.se |
. |
overlapping |
. |
A results object containing:
results$table |
a table | ||||
results$plot |
an image | ||||
Tables can be converted to data frames with asDF
or as.data.frame
. For example:
results$table$asDF
as.data.frame(results$table)
Differences Histogram and Density Curve
jamoviBAplotHistogram(data, method1, method2)
jamoviBAplotHistogram(data, method1, method2)
data |
. |
method1 |
. |
method2 |
. |
A results object containing:
results$plot |
an image | ||||
Differences Q-Q Plot
jamoviBAplotQQ(data, method1, method2)
jamoviBAplotQQ(data, method1, method2)
data |
. |
method1 |
. |
method2 |
. |
A results object containing:
results$plot |
an image | ||||
Bland-Altman Raw Statistics
jamoviBAstats(data, method1, method2)
jamoviBAstats(data, method1, method2)
data |
. |
method1 |
. |
method2 |
. |
A results object containing:
results$text |
a preformatted | ||||
blandr
objectsCompactly print the statistics used to construct a Bland-Altman plot
## S3 method for class 'blandr' print(x, digits = getOption("digits"), ...)
## S3 method for class 'blandr' print(x, digits = getOption("digits"), ...)
x |
the results from |
digits |
number of significant digits to be used. |
... |
other arguments. |
Deepankar Datta [email protected]
results = blandr.statistics.formula(Method.B ~ Method.A, data = giavarina.2015) results
results = blandr.statistics.formula(Method.B ~ Method.A, data = giavarina.2015) results