Content Disclaimer Copyright @2020. All Rights Reserved. |

**Links : **Home
Index (Subjects)
Contact StatsToDo

MacroPlot Resources
Orientation
Macroplot plotting is controlled by the macros in the text area provided.
Macros
Each macro must occupy its own line. If the first character of a macro is not A-Z, the line will be considered a comment and ignored The first macro, which is obligatory, initializes the plot. The macro is Bitmap Initialize width(in pixels), height(in pixels), red(0-255) blue(0-255), green(0-255) transparency(0-255)Example : Bitmap Initialize 700 500 255 255 255 255 which provides a landscape area 700 pixels wide, 500 pixel high, with white background
The following are default settings when the bitmap is initiated. - Lines are black (0 0 0 255) and 3 pixels in width
- Fill color for bars and dots are black (0 0 0 255), and the fill type is set to fill only (1) (see Fill Type)
- Dots (circl and square) are set to 5 pixels radius (diameter=11 pixels)
- Fonts are set as follows
- Font face is set to sans-serif. Serif, sans-serif, and monospace are available to all browsers, user can use any font available to his/her browser
- Font size is set to 16 pixels high
- Font color, both line and fill are set to black (0 0 0 255), and fill type to 1 (fill only) (see Font Type)
Bitmap, and the coordinates are x=number of pixels from the left border and y=number of pixels from the top border
A central plotting area is also defined - By default, at initialization, as 15% from the left and bottom, 5% from right and top
- defined by user as
**Plot Pixels left top right bottom**, these being number of pixels from the left and top border e.g.**Plot Pixels 105 25 665 425**would be the same as the default setting for a bitmap of 700 pixels wide and 500 pixels high
**Plot Values left top right bottom**, these being the extreme values used in the data e.g.**Plot Values 0 100 10 50**represents x values of 0 on the left to 10 to the right, and y values of 50 at the bottom to 100 to the top
Plot, and the coordinates are the values in the data
This panel lists and describes all macros used in this version of MacroPlot by Javascript. They are divided into the following sub-panels
Color Palettes
- Initialization and settings
- Plotting areas, coordinates used, and drawing of x and y axis
- Drawing lines, bars, dots, text, and other shapes
This sub-panel lists those macros that initialized the bitmap, and set the parametrs for drawing
Axis & Coordinates
## Initialize PlottingBitmap Initialize w h r g b t is the first and obligatory macro, which Initializes the bitmap
- w and h are width and height of the bitmap in number of pixels. The most common dimensions are
- w=700 and h= 500 for landscape orientation
- w=500 and h=700 for portrait orientation
- Both 500 for square bitmap
- r g b t represents red, green, blue and transparency values for the background, each value is 0 for non-existence to 255 for maximum intensity. The most commonly used background is white (255 255 255 255)
- For most plotting programs in StatsToDo the macro used is
**Bitmap Initialize 700 500 255 255 255 255**, a landscape orientation with white background
## Settings for linesThe settings provide parameters for all subsequent plotting until the parameter is reset
## Settings for fillsWhen bars, dots, arcs and wedges are plotted, the interior of these symbols are called fills, and they are set as follows
- t=0: only the outline, defined by the line parameters, are plotted. Fill is ignored
- t=1: only fill is carried out, outline is ignored
- t=2: both outline and fill are plotted
- When the plot is initialized, the default setting for fill type is t=1
## Settings for fontsThese set the font characteristics for text output.Please note: settings for lines and fills for fonts are separate and independent to those for general line and shape plottings
- t=0: only the outline of the font, defined by the thick and LColor parameter is drawn
- t=1: only the fill of the font is drawn
- t=2: both outline and fill are drawn
- When the plot is initialized, the default setting for Font type is t=1
Please Note: When the bitmap is initialized, the default settings, which are suitable for most situations, are automatically set, so users need not worry about these settings unless he/she has a different preference.
This sub-panel presents macros that define the plotting areas, and creating the x and y axis for plotting
Drawings
## Drawing on the bitmapWhen plotting on the initialized bitmap - the horizontal coordinate x is the number of pixels from the left border
- the vertical coordinate y is the number of pixels from the top border
- The macro used begins with the keyword
**Bitmap**
## Drawing on the plotting areaIn most cases, there is a need to draw and label the x and y axis, and drawing coordinates used are the actual values of the data. The macros used for these all begins with the keywordPlot, and are purposes are as follows
- lp defines the left border of the plotting area, in the number of pixels from the left border of the bitmap. In most cases this is 15% of the bitmap's width
- tp defines the top of the plotting area, in the number of pixels from the top border of the bitmap. In most cases this is 5% of the height
- rp defines the right border of the plotting area, in the number of pixels from the left border of the bitmap. In most cases this is 95% of the width (or 5% from the right border of the bitmap)
- bp defines the bottom border of the plotting area, in the number of pixels from the top border of the bitmap. In most cases this is 85% of the height (or 15% from the bottom)
- An example is that is that, in a landscape orientated bitmap of 700 pixels width and 500 pixel height,
**Plot Pixels 105 25 665 425**sets the central area for plotting that is 15% from the left and bottom, and 5% from the top and right. - This macro is usually not necessary if the 5%/15% setting suits the user, as this is the default setting when the bitmap is initialized
Plot Values lv tv rv bv defines the data values to be used in plotting
- lv is the extreme data value for the horizontal variable x on the left
- tv is the extreme data value for the vertical variable y at the top
- rv is the extreme data value for horizontal variable x on the right
- bv is the extreme data value for the vertical variable y at the bottom
Plot Logx 1 sets the horizontal x axis to the log scale. Normal scale is set on initialization, or reset by Plot Logx 0
- lable is a single word text string, using the underscore
**_**to represent spaces if necessary - space is the number of pixels between the bottom of the plot area and the label text string
- lable is a single word text string, using the underscore
**_**to represent spaces if necessary - space is the number of pixels between the left of the plot area and the label text string
## The quickest and easiest way to draw axisThe following 4 macros are sufficient to draw the x and y axis under most circumstances
- y is the y value on which the x axis lie
- nsIntv is the number of small intervals between the vertical line marks, 10 to 20 are recommended
- nbIntv is the number of big intervals between the numerical scales, 5 to 10 are recommended
- len is the length of the mark in pixels, +ve value downwards and negative value upwards. -10 is recommended
- gap is the number of pixels between the numerical scaling text and the y value of the axis, +ve values for text below axis and negative value for text above axis. 3 is recommended
- Line determines the axis line is drawn, 0 for no line, 1 for line
Plot YAxis x nsIntv nbIntv len gap line will mark out and numerate the vertical y axis
- x is the x value on which the y axis lie
- nsIntv is the number of small intervals between the horizontal line marks, 10 to 20 are recommended
- nbIntv is the number of big intervals between the numerical scales, 5 to 10 are recommended
- len is the length of the mark in pixels, +ve value to the right and negative value to the left. 10 is recommended
- gap is the number of pixels between the numerical scaling text and the y value of the axis, +ve values for text to the right of axis and negative value for text to the left of axis. -3 is recommended
- Line determines the axis line is drawn, 0 for no line, 1 for line
Plot AutoXLogScale y len gap line will mark and numerate the x axis if it is in log scale
- The x axis must be set to the log scale by
**Plot Logx 1**. If axis not set to log this macro will abort - y is the y value on which the x axis lie
- len is the length of the mark in pixels, +ve value downwards and negative value upwards. -10 is recommended
- gap is the number of pixels between the numerical scaling text and the y value of the axis, +ve values for text below axis and negative value for text above axis. 3 is recommended
- Line determines the axis line is drawn, 0 for no line, 1 for line
Plot AutoYLogScale x len gap line will mark and numerate the y axis if it is in log scale
- The y axis must be set to the log scale by
**Plot Logy 1**. If axis not set to log this macro will abort - x is the x value on which the x axis lie
- len is the length of the mark in pixels, +ve value downwards and negative value upwards. -10 is recommended
- gap is the number of pixels between the numerical scaling text and the y value of the axis, +ve values for text below axis and negative value for text above axis. 3 is recommended
- Line determines the axis line is drawn, 0 for no line, 1 for line
## Other methods of drawing axisUsers may wish to draw individual part of the axis, and the following macros can be used
- y is the y value where the axis is to be marked
- begin is the value for the first mark
- interval is the interval between marks
- len is the length of the mark line in pixels, +ve downwards, -ve upwards
- x is the x value where the axis is to be marked
- start is the value for the first mark
- interval is the interval between marks
- len is the length of the mark line in pixels, +ve to the right, -ve to the left
- y is the y value for the axis
- start is the first value to be written
- interval is the interval between numerical scales
- gap is the space in pixels between the scale text and the axis, +ve for text below axis, -ve for text above axis
- The number of decimal points in the scale is the same as that of the interval value
- x is the x value for the axis
- start is the first value to be written
- interval is the interval between numerical scales
- gap is the space in pixels between the scale text and the axis, +ve for text to the right of axis, -ve for text to the left of axis
- The number of decimal points in the scale is the same as that of the interval value
Plot XMarkIntv y interval len marks the horizontal x axis with a series of vertical marks
- y is the y value of the axis
- interval is the interval between the marks, beginning at 0 and while in range
- len is the length of the mark line in pixels, +ve downwards, -ve upwards
Plot YMarkIntv x interval len marks the vertical y axis with a series of horizontal marks
- x is the x value of the axis
- interval is the interval between the marks, beginning at 0 and while in range
- len is the length of the mark line in pixels, +ve to the right, -ve to the left
Plot XScaleIntv y interval gap writes the numerical scales for the horizontal x axis
- y is the y value of the axis
- interval is the interval between the numerical scales, beginning at 0 and while in range
- gap is the space in pixels between the scale text and the axis, +ve for text below axis, -ve for text above axis
- The number of decimal points in the scale is the same as that of the interval value
Plot YScaleIntv x interval gap writes the numerical scales for the vertical y axis
- x is the x value of the axis
- interval is the interval between the numerical scales, beginning at 0 and while in range
- gap is the space in pixels between the scale text and the axis, +ve for text to the right of axis, -ve for text to the left of axis
- The number of decimal points in the scale is the same as that of the interval value
This sub-panel describes those macros that draws the plotting objects. Drawing are performed in two environments
- Macros that begins with the keyword
**Bitmap**uses pixel values as coordinates, where x is the number of pixels from the left border, and y the number of pixels from the top border - Macros that begins with the keyword
**Plot**uses actual data values (as defined in the**Plot Values lv tv rv bv**macro, as coordinates
## Drawing linesThe thickness and color of any line drawn is set by theLine macros (see setting sub-panel). The default setting is black line 3 pixels in width
- x1 and x2 are number of pixels from the left border
- y1 and y2 are number of pixels from the top border
- x1 and x2 are data values for the horizontal variable x
- y1 and y2 are data variables for the vertical variable y
Plot PixLine x y hpix vpix draws a line
- x and y are data values for the horizonal x value and verticsl y value. This defines the coordinate at the origin of the line
- hpix is the number of pixels horizontally from the origin, +ve value to the right, -ve value to the left
- vpix is the number of pixels vertically from the origin, +ve value downwards, -ve value upwards
- The line is then drawn between the origin and that defined by hpix and vpix
## Drawing barsThe color and thickness of the outline are defined in theLine macro. The color of the fill is defined in the fill color and Fill Type macro. The default setting is black (0 0 0 255) for both line and fill color, and the Fill type is set to 1, only the fill and no outlines. These settings are suitable for most circumstances, but user can change them is so required.
- w is the half width of the bar, so a VBar is 2w+1 pixels in width, and HBar is 2w+1 pixels in height
- The default value for w is 7 pixels (making width/height of 15 pixels), unless the user changes it
- x is the data value for the horizontal x variable. The is the center of the vertical bar
- y1 and y2 are values for the vertical y variable. They define the vertical ends of the bar
- hshift is the number of pixels the whole bar is shefted horizontally, +ve value to the left and +ve value to the right. In most cases this is 0 (no shift). However, if there are more than 1 bar in the same position, shifting some of them will avoid the bars overlapping and obscuring each other
- The width of the vertical bar is set by default at 7, (width of bar=15 pixels)
- x1 and x2 are data values for the horizontal x variable. They define the horizontal ends of the bar
- y is the value for the vertical y variable, and defines and center of the horizontal bar
- vshift is the number of pixels the whole bar is shefted vertically, -ve value upwards and +ve value downwards. In most cases this is 0 (no shift). However, if there are more than 1 bar in the same position, shifting some of them will avoid the bars overlapping and obscuring each other
- Theheight of the horizontal bar is set by default at 7, (height of bar=15 pixels)
## Drawing dotsThere are only 2 dot types, circle and square. If more than 2 tyoes of dats are required, they can be distinguished by the colours of the outline and fill, and by their sizes. Settingsd for dot parameters are in the settings sub-panel
- x and y are the number of pixels from the left and top border
- Radius is in number of pixels. The diameter of the dot is 2Radius+1 pixels
- x and y are the data values of the horizontal x variable and vertical y variable, as defined by
**Plot Values lv tv rv bv** - Radius is in number of pixels. The diameter of the dot is 2Radius+1 pixels
- hshift is the number of pixels the dot is shifted horizontally, -ve value to the left, +ve value to the right
- vshift is the number of pixels the dot is shifted vertically, -ve value upwards, +ve value downwards
- In most cases there is no shift (0 0), but id there are more than 1 dot in the same position, shifting avoids the dots superimposing over and obscuring each other
Dot Radius r sets the radius of the dot in pixels. The diameter of the dot is 2radius+1 pixels. The default radius is 5
- x and y are the data values of the horizontal x variable and vertical y variable, as defined by
**Plot Values lv tv rv bv** - hshift is the number of pixels the dot is shifted horizontally, -ve value to the left, +ve value to the right
- vshift is the number of pixels the dot is shifted vertically, -ve value upwards, +ve value downwards
- In most cases there is no shift (0 0), but if there are more than 1 dot in the same position, shifting avoids the dots superimposing over and obscuring each other
## Drawing textThe color, outline, fill, font, and weight of text are preset (see settings). The default settinfs are sans-sherif, black fill only, and 16pxs high
- x and y are number of pixels fom the left and top borders, and together being the reference coordinate of the text
- ha is horizontal adjust
- ha=0: the left end of the text is at the x coordinate
- ha=1: the center of the text is at the x coordinate
- ha=2: the right end of the text is at the x coordinate
- va is vertical adjust
- va=0: the top of the text is at the y coordinate
- va=1: the center of the text is at the x coordinate
- va=2: the bottom end of the text is at the x coordinate
- txt is the text to be drawn. It must be a single word with no gaps. Spaces can be represented by the underscore _
- x and y are data values as defined by
**Plot Values lv tv rv bv**, and together being the reference coordinate of the text - ha is horizontal adjust
- ha=0: the left end of the text is at the x coordinate
- ha=1: the center of the text is at the x coordinate
- ha=2: the right end of the text is at the x coordinate
- va is vertical adjust
- va=0: the top of the text is at the y coordinate
- va=1: the center of the text is at the x coordinate
- va=2: the bottom end of the text is at the x coordinate
- txt is the text to be drawn. It must be a single word with no gaps. Spaces can be represented by the underscore _
- hshift is the number of pixels the text is shifted horizontally, -ve value to the left, +ve value to the right
- vshift is the number of pixels the text is shifted vertically, -ve value upwards, +ve value downwards
- In most cases there is no shift (0 0), but if there are other structures in the same position, shifting avoids the text and structures obscuring each other
- x and y are number of pixels fom the left and top borders, and together being the reference coordinate of the text
- ha is horizontal adjust
- ha=0: the left end of the text is at the x coordinate
- ha=1: the center of the text is at the x coordinate
- ha=2: the right end of the text is at the x coordinate
- va is vertical adjust
- va=0: the top of the text is at the y coordinate
- va=1: the center of the text is at the x coordinate
- va=2: the bottom end of the text is at the x coordinate
- txt is the text to be drawn. It must be a single word with no gaps. Spaces can be represented by the underscore _
- x and y are data values as defined by
**Plot Values lv tv rv bv**, and together being the reference coordinate of the text - ha is horizontal adjust
- ha=0: the left end of the text is at the x coordinate
- ha=1: the center of the text is at the x coordinate
- ha=2: the right end of the text is at the x coordinate
- va is vertical adjust
- va=0: the top of the text is at the y coordinate
- va=1: the center of the text is at the x coordinate
- va=2: the bottom end of the text is at the x coordinate
- hshift is the number of pixels the text is shifted horizontally, -ve value to the left, +ve value to the right
- vshift is the number of pixels the text is shifted vertically, -ve value upwards, +ve value downwards
- In most cases there is no shift (0 0), but if there are other structures in the same position, shifting avoids the text and structures obscuring each other
## Other miscellaneous drawingsBitmap Arc x y radius startDeg endDeg rotate draws an arc.
- x and y are number of pixels from the left and top border, and together form the center of the arc
- radius is the radius of the arc, in number of pixels
- startDeg and endDeg are the degrees (360 degrees in full circle) of the arc
- rotate defines the direction of the arc, 0 for clockwise, 1 for anti-clockwise
Bitmap Wedge x y radius startDeg endDeg shift rotate draws a wedge, essentially an arc with lines to the center
- x and y are number of pixels from the left and top border, and together form the center of the wedge
- radius is the radius of the edge, in number of pixels
- startDeg and endDeg are the degrees (360 degrees in full circle) of the wedge
- shift is the number of pixels that the wedge is moved centrifugally (away from the center). This is used in pie charts to separate the wedges of the pie
- rotate defines the direction of the wedge, 0 for clockwise, 1 for anti-clockwise
Plot Curve a b1 b2 b3 b4 b5 x1 x2 draws a polynomial curve
- The curve is y=a + b1x + b2x
^{2}+ b3x^{3}+ b4x^{4}+ b5x^{5}. Where higher power is not needed, 0 is used to represent the the coefficient b - The curve is drawn from data value x from x1 to x2
Plot Normal mean sd height draws a normal distribution curve
- mean and sd (Standard Deviation) are as in the data horizontal variable variable x
- height is the maximum height (where x=mean) of the curve as in the vertical variable y
Plain Colors
Table of colors used on this web site
Patterns of complementary colors
Explanations
Bland and Altman (1986) discussed in details how agreements between two methods of measuring the same thing can be evaluated in nuanced details. The details and terminology of the methods are described in 3 references in the reference section, and will not be repeated here.
Javascript Program
The rest of this panel will take users through the calculations presented in the Javascript program panel
The data is a matrix of 2 columns. Each row represents a case being measured. The two columns, separated by white space, are the paired measurements. If a gold standard is being compared, the gold standard is in the first (left) column. The default example data on this page are generated from the computer and not real. There are only 30 pairs, too few for proper evaluation, but easier to demonstrate in this example. The data are shown in the table to the right. It represents 30 paired measurements of blood pressure. The first column (v1) is the gold standard, intra-arterial catheter, and the right (v2) the measurement being compared, external electronic cuffed manometer.
The first step is to estimate the paired mean = (v1+v2)/2) and paired difference (v2-v1) of each pair. The original data and the estimates are presented as in the table to the right. The rest of the evaluations used the pair mean and pair difference
The first row is the mean and Standard Deviation of the paired difference (bias and distribution of bias), and the t test for significant departure from 0. The paired difference is named The second row is the results of linear regression analysis where paired difference = a + b(paired mean). The regression coefficient b representws changes to paired differences related to changing paired means, and is names The remainder of the table estimate the confidence intervals of bias. - In calculation bias, Bland & Altman use bias = v1 - v2, assuming that the reference column PEER is column 2. On this page bias = v2 - v1, assuming the first column to be PEER. The results will be numerically the same, but the signs (+ and -) would be reversed
- Bland & Altman offered a single confidence interval of bias ± 2 Standard Deviations.
- Hanneman offered an interval of bias ± 1.96 Standard Devistions.
- This table offers 3 choices, 90%, 95%, and 99% confidence intervals of bias ±t(Standard Deviations), and t are calculated as two tail p=0.1 for 90% CI, 0.05 for 95% CI, and p=0.01 for 99% CI, based on the sample size of the data. In the example from the Javascript program panel, the 95% confidence interval for the bias uses t=2.05 because the sample size of the example is 30. Bland & Altman used t=2 regardless of sample size (t=2 if p=0.05 and sample size=60), and Hanneman used 1.96 regardless of sample size (t=2 if p=0.05 and sample size=population or is infinitely large)
- This table also counts the number of cases included within the 3 levels of confidence intervals
The results of analysis using the algorithm described in the paper by Bland & Altman are shown in the table to the right. These are presented as the Bland and Altman plot is now commonly used to evaluate agreements between measurements Step 1, the 95% confidence, for all samples sizes, is calculated uses t=2, so that 95% CI = bias ±2SD. From the example used in the Javascript program panel - The mean is 0.7667
- The Standard Deviation is 4.7828
- The borders are 0.7667±2(4.7828) The bias is therefore 0.7667, and the 95% confidence interval borders -8.7988 and 10.3322
Step 2 is to calculate t, based on p=0.05 for 95% confidence interval, and the sample size of the data. In the example from the Javascript program panel, the sample size is 30, so t=2.0452. This t value is then used to calculate the precision of the mean and the 95% confidence interval borders Step 3 is to calculate the precision of the mean bias - The Standard Error of the mean bias is sqrt(SD
^{2}/sample size) = sqrt(4.7828^{2}/30) = 0.8732 - The 95% confidence interval for precision of bias is therefore 0.7667±2x0452(0.8732), -1.0192 to 2.5526
Step 4 is to calculate the precision of the confidence interval borders - The Standard Error of both borders are the same, being sqrt(3SD
^{2}/sample size) = sqrt(3*4.7828^{2}/30) = 1.5124 - The 95% confidence interval for precision of the borders are therefore
- For the upper border, 10.3322±2.0452(1.5124) = 7.2390 to 13.4254
- For the lower border, -8.7988±2.0452(1.5124) = -11.8920 to -5.7056
After numerical analysis, the Javascript program panel produces the Bland Altman plot, to assist the user to interpret the agreement parameters. The plot follows that described in the reference, specifically - The 3 horizontal lines are bias (mean paired difference), ± 2 x Standard Deviation of the paired difference
- The black round dots are paired mean and paird difference for each case
Not calculated in the Javascript program panel
Bland and Altman (see references) suggested the duplicate or multiple measurements be taken from each case, and the variations between measurements compared with that within measurements. As these analysis represent an additional level of complexity and precision, they are not presented. ## References- Hanneman S K. Design, Analysis and Interpretation of Method-Comparison Studies. AACN Adv Crit Care. 2008 Apr-Jun; 19(2): 223-234. [ https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2944826/]
- Altman DG, Bland JM (1983). "Measurement in medicine: the analysis of method comparison studies". The Statistician. 32 (3): 307-317. doi:10.2307/2987937. JSTOR 2987937. [https://www-users.york.ac.uk/~mb55/meas/ba.pdf]
- Bland JM, Altman DG (1986). "Statistical methods for assessing agreement between two methods of clinical measurement" (PDF). Lancet. 327 (8476): 307-10. https://www-users.york.ac.uk/~mb55/meas/ba.pdf
- [Wikipedia for Bland Altman Plot]
This panel presents R codes for Bland and Altman's Plot, as described in https://www-users.york.ac.uk/~mb55/meas/ba.pdf
The R Code is translated from the Javascript code on this same page, and was initially developed to double check the arithematics The first part are utility subroutines for formating numbers and calculate probability of t # Decimal point output DStr <- function (n) { if(is.numeric(n)) { if(n==round(n)) return (n) # integer no change n = sprintf("%.4f",n) # real 4 decimal points return (sub("0+$", "", n)) # remove trailing zeroes } return (n) # no a number no change } # probability of t TtoP<-function(t,degF,tail) #function to calculate probability from t and df { p = 1 - pt(t,df=degF) #probability 1 tail if(tail==1) return (p) return (p * 2) #orobability 2 tail } PtoT<-function(p,degF,tail) #function to calculate t from probability and df { #t = qt(1-p, df=degF) #t 1 tail if(tail==1) return (qt(1-p, df=degF)) #t 1 tail return (qt(1- p / 2, df=degF)) #t 2 tail }The main program is as follows # Main program dat = (" v1 v2 127 134 118 120 135 142 123 115 112 117 119 123 125 125 109 111 106 122 110 115 111 109 125 127 119 118 140 139 115 111 110 110 122 122 119 115 134 137 105 105 117 112 111 113 114 115 126 119 113 115 129 127 130 129 130 130 115 120 131 126 ") dfm <- read.table(textConnection(dat),header=TRUE) # conversion to data frame dfm$av <- (dfm$v1 + dfm$v2) / 2 #dfm$dif <- dfm$v1 - dfm$v2 # Bland and Altman dfm$dif <- dfm$v2 - dfm$v1 # makes different of v2 over v1 (reference) dfm n = nrow(dfm) df = n - 1 meanx = mean(dfm$av) sdx = sd(dfm$av) meany = mean(dfm$dif) sdy = sd(dfm$dif) sey = sdy / sqrt(n) t = meany / sey; p = TtoP(t, df, 2) * 2 # 2 tail reg <- lm(formula = dfm$dif ~ dfm$av) a = summary(reg)$coefficients[1,1] b = summary(reg)$coefficients[2,1] print(paste("n=",n,"df=",df)) print(paste("Average (x=(v1+v2)/n) mean=",DStr(meanx)," SD=", DStr(sdx))) print(paste("Difference (bias, y = v2-v1) mean=",DStr(meany), " SD=",DStr(sdy), " t=",DStr(t), " p=",DStr(p))) ssqx = sdx^2 * (n-1) ssqy = sdy^2 * (n-1) spr = b * ssqx rv = (ssqy-spr^2/ssqx)/(n - 2) # Residual mean Squares seB = sqrt(rv/ssqx) # SE of slope b tReg = b / seB pReg = TtoP(tReg, n-2, 2) # 2 tail print(paste("Regression y=a + bx constant a=", DStr(a))) print(paste("Regression coefficient b=", DStr(b), " t=",DStr(tReg), " p=",DStr(pReg))) t90 = PtoT(0.1,df,2); t95 = PtoT(0.05,df,2); t99 = PtoT(0.01,df,2); p90 = meany + t90 * sdy n90 = meany - t90 * sdy p95 = meany + t95 * sdy n95 = meany - t95 * sdy p99 = meany + t99 * sdy; n99 = meany - t99 * sdy # counts n00 = 0; np90 = 0; nn90 = 0; np95 = 0; nn95 = 0; np99 = 0; nn99 = 0; for(i in 1:n) { v = dfm$dif[i] if(v==0) { n00 = n00 + 1 } else if(v>0) { if(v<=p90) { np90 = np90 + 1 } if(v<=p95) { np95 = np95 + 1 } if(v<=p99) { np99 = np99 + 1 } } else if(v<0) { if(v>=n90) { nn90 = nn90 + 1 } if(v>=n95) { nn95 = nn95 + 1 } if(v>=n99) { nn99 = nn99 + 1 } } } print(paste("Number of cases with no difference=",n00)) nt90 = n00 + nn90 + np90 print(paste("90% CI difference = Bias +/-", DStr(t90), "SD =", DStr(n90), " to ", DStr(p90), " n>=0 = ", np90," n<=0 =", nn90, "n Within 90%CI=", nt90, "(", sprintf("%.1f",nt90/n*100),"%)")) nt95 = n00 + nn95 + np95 print(paste("95% CI difference = Bias +/-", DStr(t95), "SD =", DStr(n95), " to ", DStr(p95), " n>=0 = ", np95," n<=0 =", nn95, "n Within 95%CI=", nt95, "(", sprintf("%.1f",nt95/n*100),"%)")) nt99 = n00 + nn99 + np99 print(paste("99% CI difference = Bias +/-", DStr(t99), "SD =", DStr(n99), " to ", DStr(p99), " n>=0 = ", np99," n<=0 =", nn99, "n Within 95%CI=", nt95, "(", sprintf("%.1f",nt99/n*100),"%)")) t = PtoT(0.05,df,2); sey = sdy / sqrt(n) ll = meany - t * sey; ul = meany + t * sey; print(paste("Precision Estimates: mean=",DStr(meany), " SE=", DStr(sey), " 95% Confidence interval=", DStr(ll), " to ",DStr(ul))) se = sqrt(3 * sdy^2 / n) upper = meany + 2 * sdy ll = upper - t * se; ul = upper + t * se; print(paste("Upper Limit (Bias+2SD)=",DStr(upper), " SE=", DStr(se), " 95% Confidence interval=", DStr(ll), " to ",DStr(ul))) lower = meany - 2 * sdy ll = lower - t * se; ul = lower + t * se; print(paste("Lower Limit (Bias-2SD)=",DStr(lower), " SE=", DStr(se), " 95% Confidence interval=", DStr(ll), " to ",DStr(ul))) # Bland Altman Plot plot( # Command 1: Draw dots x = dfm$av, # x variable = average y = dfm$dif, # y variable = difference pch = 16, # size of dot xlab = "Mean=(v1+v2)/2", # x label ylab = "Diff=(v2-v1)" # y lable ) # draw horizontal lines for mean +/- 2SD for difference = v1 - v2 abline(h=meany) # horizontal line at mean difference abline(h=upper) # horizontal line at mean difference + 2SE abline(h=lower) # horizontal line at mean difference - 2SEThe results are as follows > dfm v1 v2 av dif 1 127 134 130.5 7 2 118 120 119.0 2 3 135 142 138.5 7 4 123 115 119.0 -8 5 112 117 114.5 5 6 119 123 121.0 4 7 125 125 125.0 0 8 109 111 110.0 2 9 106 122 114.0 16 10 110 115 112.5 5 11 111 109 110.0 -2 12 125 127 126.0 2 13 119 118 118.5 -1 14 140 139 139.5 -1 15 115 111 113.0 -4 16 110 110 110.0 0 17 122 122 122.0 0 18 119 115 117.0 -4 19 134 137 135.5 3 20 105 105 105.0 0 21 117 112 114.5 -5 22 111 113 112.0 2 23 114 115 114.5 1 24 126 119 122.5 -7 25 113 115 114.0 2 26 129 127 128.0 -2 27 130 129 129.5 -1 28 130 130 130.0 0 29 115 120 117.5 5 30 131 126 128.5 -5 [1] "n= 30 df= 29" [1] "Average (x=(v1+v2)/n) mean= 120.3833 SD= 8.9901" [1] "Difference (bias, y = v2-v1) mean= 0.7667 SD= 4.7828 t= 0.878 p= 0.7743" [1] "Regression y=a + bx constant a= -0.2443" [1] "Regression coefficient b= 0.0084 t= 0.0835 p= 0.934" [1] "Number of cases with no difference= 5" [1] "90% CI difference = Bias +/- 1.6991 SD = -7.3598 to 8.8932 n>=0 = 13 n<=0 = 10 n Within 90%CI= 28 ( 93.3 %)" [1] "95% CI difference = Bias +/- 2.0452 SD = -9.0152 to 10.5485 n>=0 = 13 n<=0 = 11 n Within 95%CI= 29 ( 96.7 %)" [1] "99% CI difference = Bias +/- 2.7564 SD = -12.4164 to 13.9498 n>=0 = 13 n<=0 = 11 n Within 95%CI= 29 ( 96.7 %)" [1] "Precision Estimates: mean= 0.7667 SE= 0.8732 95% Confidence interval= -1.0192 to 2.5526" [1] "Upper Limit (Bias+2SD)= 10.3322 SE= 1.5124 95% Confidence interval= 7.2389 to 13.4255" [1] "Lower Limit (Bias-2SD)= -8.7988 SE= 1.5124 95% Confidence interval= -11.8921 to -5.7056"The result plot is as shown |