Macroplot plotting is controlled by the macros in the text area provided.
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)
Macros for plotting on the bitmap begin with the keyword 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
The values of the data used in plotting in this central area can be defined as follows
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
After the values are declared, all plotting in the central area uses macros beginning with the keyword Plot, and the coordinates are the values in the data
Macros
This panel lists and describes all macros used in this version of MacroPlot by Javascript. They are divided into the following sub-panels
Initialization and settings
Plotting areas, coordinates used, and drawing of x and y axis
Drawing lines, bars, dots, text, and other shapes
Initialization
This sub-panel lists those macros that initialized the bitmap, and set the parametrs for drawing
Initialize Plotting
Bitmap 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 lines
The settings provide parameters for all subsequent plotting until the parameter is reset
Line Color r g b t sets the line color of red, green, blue and transparency values, each value is 0 for non-existence to 255 for maximum intensity. On initialization of the bitmap, line color is lines is set by default to black (0 0 0 255)
Line Thick p sets the thickness of lines to p pixels. On initialiszation, the default setting is 3 pixels for line thickness
Settings for fills
When bars, dots, arcs and wedges are plotted, the interior of these symbols are called fills, and they are set as follows
Fill Color r g b t sets the filling color of red, green, blue and transparency values, each value is 0 for non-existence to 255 for maximum intensity. On initialization of the bitmap, fill color is lines is set by default to black (0 0 0 255).
Fill Type t sets how the fills are to be used, t can be one of the following
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 fonts
These 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
Font Face name sets the font face. The program will accept all fonts supported by the user's border. The 3 fonts accepted by all browsers are serif, sans-serif, and monospace. On initialization, sans-serif is set by default
Font Style s where s can be either normal or bold. On initialization the default setting is bold
Font Size h where h is the height of the text in pixels. On initialization, the default font size is set to 16
Font Thick p where p is the thickness of the outline of the font. On initialization, this is set to p=1
Font LColor r g b t sets the color of the outline of the font. On initialization this is set to black (0 0 0 255)
Font FColor r g b t sets the fill color of the of the font. On initialization this is set to black (0 0 0 255)
Font Color r g b t sets both LColor and FColor to the same color. On initialization this is set to black (0 0 0 255)
Font Type t where t determines which part of the font is drawn, and can be one of the following
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.
Axis & Coordinates
This sub-panel presents macros that define the plotting areas, and creating the x and y axis for plotting
Drawing on the bitmap
When 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 area
In 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 keyword Plot, and are purposes are as follows
Plot Pixels lp tp rp bp defines an area for plotting
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
Plot Logy 1 sets the vertical y axis to the log scale. Normal scale is set on initialization, or reset by Plot Logy 0
Plot XLabel label distance places the label for the horizontal x axis, below the bottom of the plotting area
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
Plot YLabel label distance places the label for the vertical y axis, on the left of plotting area
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 axis
The following 4 macros are sufficient to draw the x and y axis under most circumstances
Plot XAxis y nsIntv nbIntv len gap line will mark out and numerate the horizontal x axis
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 axis
Users may wish to draw individual part of the axis, and the following macros can be used
Plot XLine y Draws the horizontal x axis line at the y value y
Plot YLine x Draws the vertical y axis line at the x value y
Plot XMark y begin interval len marks the horizontal x axis with a series of vertical marks
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
Plot YMark x start interval len marks the vertical y axis with a series of horizontal marks
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
Plot XScale y start interval gap writes the numerical scales for the horizontal x axis
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
Plot YScale x start interval gap writes the numerical scales for the vertical y axis
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
Drawings
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 lines
The thickness and color of any line drawn is set by the Line macros (see setting sub-panel). The default setting is black line 3 pixels in width
Bitmap Line x1 y1 x2 y2 draws the line from x1y1 to x2y2
x1 and x2 are number of pixels from the left border
y1 and y2 are number of pixels from the top border
Plot Line x1 y1 x2 y2 draws the line from x1y1 to x2y2
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 bars
The color and thickness of the outline are defined in the Line 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.
Bitmap Bar x1 y1 x2 y2 draws a bar the corner of which are x1y1 and x2y2. X and y are number of pixels from the left and top border of the bitmap
Plot Bar x1 y1 x2 y2 draws a bar the corner of which are x1y1 and x2y2. X and y are data values as defined in Plot Values lv tv rv bv
Bar Wide w sets the width / height of bars for Plot VBar and Plot HBar
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
Plot VBar x y1 y2 hshift draws a vertical bar
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)
Plot HBar x1 x2 y vshift draws a horizontal bar
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 dots
There 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
Bitmap Circle x y radius and Bitmap Square x y radius draws a circle or a square dot
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
Plot Circle x y radius hshift vshift and Plot Square x y radius hshift vshift draws a circle or a square dot
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
Dot Type t where t is either circle or square. The default setting is circle
Plot Dot x y hshift vshift draws the dot, with its parameters (shape size color outline fill) already pre-set
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 text
The color, outline, fill, font, and weight of text are preset (see settings). The default settinfs are sans-sherif, black fill only, and 16pxs high
Bitmap HText x y ha va txt draws text horizontally on the bitmap
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 _
Plot HText x y ha va txt hshift vshift draws text horizontally on the bitmap
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
Bitmap VText x y ha va txt draws text vertically (90 degrees anticlockwise from horizontal) on the bitmap
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 _
Plot VText x y ha va txt hshift vshift draws text vertically (90 degrees anticlockwise from horizontal) on the bitmap
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
Other miscellaneous drawings
Bitmap 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 + b2x2 + b3x3 + b4x4 + b5x5. 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
Color Palettes
Plain Colors
0 0 0 #000000
0 0 63 #00003f
0 0 127 #00007f
0 0 191 #0000bf
0 0 255 #0000ff
0 63 0 #003f00
0 63 63 #003f3f
0 63 127 #003f7f
0 63 191 #003fbf
0 63 255 #003fff
0 127 0 #007f00
0 127 63 #007f3f
0 127 127 #007f7f
0 127 191 #007fbf
0 127 255 #007fff
0 191 0 #00bf00
0 191 63 #00bf3f
0 191 127 #00bf7f
0 191 191 #00bfbf
0 191 255 #00bfff
0 255 0 #00ff00
0 255 63 #00ff3f
0 255 127 #00ff7f
0 255 191 #00ffbf
0 255 255 #00ffff
63 0 0 #3f0000
63 0 63 #3f003f
63 0 127 #3f007f
63 0 191 #3f00bf
63 0 255 #3f00ff
63 63 0 #3f3f00
63 63 63 #3f3f3f
63 63 127 #3f3f7f
63 63 191 #3f3fbf
63 63 255 #3f3fff
63 127 0 #3f7f00
63 127 63 #3f7f3f
63 127 127 #3f7f7f
63 127 191 #3f7fbf
63 127 255 #3f7fff
63 191 0 #3fbf00
63 191 63 #3fbf3f
63 191 127 #3fbf7f
63 191 191 #3fbfbf
63 191 255 #3fbfff
63 255 0 #3fff00
63 255 63 #3fff3f
63 255 127 #3fff7f
63 255 191 #3fffbf
63 255 255 #3fffff
127 0 0 #7f0000
127 0 63 #7f003f
127 0 127 #7f007f
127 0 191 #7f00bf
127 0 255 #7f00ff
127 63 0 #7f3f00
127 63 63 #7f3f3f
127 63 127 #7f3f7f
127 63 191 #7f3fbf
127 63 255 #7f3fff
127 127 0 #7f7f00
127 127 63 #7f7f3f
127 127 127 #7f7f7f
127 127 191 #7f7fbf
127 127 255 #7f7fff
127 191 0 #7fbf00
127 191 63 #7fbf3f
127 191 127 #7fbf7f
127 191 191 #7fbfbf
127 191 255 #7fbfff
127 255 0 #7fff00
127 255 63 #7fff3f
127 255 127 #7fff7f
127 255 191 #7fffbf
127 255 255 #7fffff
191 0 0 #bf0000
191 0 63 #bf003f
191 0 127 #bf007f
191 0 191 #bf00bf
191 0 255 #bf00ff
191 63 0 #bf3f00
191 63 63 #bf3f3f
191 63 127 #bf3f7f
191 63 191 #bf3fbf
191 63 255 #bf3fff
191 127 0 #bf7f00
191 127 63 #bf7f3f
191 127 127 #bf7f7f
191 127 191 #bf7fbf
191 127 255 #bf7fff
191 191 0 #bfbf00
191 191 63 #bfbf3f
191 191 127 #bfbf7f
191 191 191 #bfbfbf
191 191 255 #bfbfff
191 255 0 #bfff00
191 255 63 #bfff3f
191 255 127 #bfff7f
191 255 191 #bfffbf
191 255 255 #bfffff
255 0 0 #ff0000
255 0 63 #ff003f
255 0 127 #ff007f
255 0 191 #ff00bf
255 0 255 #ff00ff
255 63 0 #ff3f00
255 63 63 #ff3f3f
255 63 127 #ff3f7f
255 63 191 #ff3fbf
255 63 255 #ff3fff
255 127 0 #ff7f00
255 127 63 #ff7f3f
255 127 127 #ff7f7f
255 127 191 #ff7fbf
255 127 255 #ff7fff
255 191 0 #ffbf00
255 191 63 #ffbf3f
255 191 127 #ffbf7f
255 191 191 #ffbfbf
255 191 255 #ffbfff
255 255 0 #ffff00
255 255 63 #ffff3f
255 255 127 #ffff7f
255 255 191 #ffffbf
255 255 255 #ffffff
Color Palletes
Table of colors used on this web site
255 255 255 #ffffff
224 224 224 #e0e0e0
128 128 128 #808080
128 0 0 #800000
255 0 0 #ff0000
96 48 96 #603060
48 16 64 #301040
96 96 160 #6060a0
160 160 96 #a0a060
160 160 0 #a0a000
153 191 164 #99bfa4
160 160 96 #a0a060
97 24 0 #611800
204 63 200 #cc3fc8
224 224 224 #e0e0e0
Patterns of complementary colors
A
105 93 70 #695d46
255 113 44 #ff712c
207 194 145 #cfc291
161 232 217 #a1e8d9
255 246 197 #fff6c5
B
115 0 70 #730046
201 60 0 #c93c00
232 136 1 #e88801
255 194 0 #ffc200
191 187 17 #bfbb11
C
97 24 0 #611800
140 115 39 #8c7327
71 164 41 #47a429
153 191 164 #99bfa4
242 239 189 #f2efbd
D
20 87 110 #14576e
140 33 90 #8c215a
230 133 38 #e68526
195 102 163 #c366a3
242 207 242 #f2cff2
E
64 1 1 #400101
48 115 103 #307367
96 166 133 #60a685
242 236 145 #f2ec91
229 249 186 #e5f9ba
F
55 89 21 #375915
166 60 60 #a63c3c
115 108 73 #736c49
166 157 129 #a69d81
242 224 201 #f2e0c9
G
115 36 94 #73245e
166 69 33 #a64521
217 182 78 #d9b64e
242 218 145 #f2da91
242 242 242 #f2f2f2
H
255 77 0 #ff4d00
102 87 71 #665747
125 179 0 #7db300
153 138 122 #998a7a
217 195 98 #d9c362
I
128 0 38 #800026
128 128 83 #808053
92 153 122 #5c997a
163 204 143 #a3cc8f
255 230 153 #ffe699
Explanations
The program on this page is adapted from that in a paper by Moses et.al. (see references)
The Need for Curve Fitting the Receiver Operator Characteristic (ROC) Curve
The underlying assumptions of the ROC curve is that the Outcome is binary, but the Test is a continuous measurement. In
establishing the ROC from a set of reference data, it is assumed that the sample size provided is large enough, and the
granularity of the values in the data set is fine enough, to produce a valid curve.
The modelling data set unfortunately often failed these assumptions. A major problem is that test measurements are often
rounded to clinically meaningful intervals, so that the granularity of the data is coarse, and changes occurred in a
series of steps rather than in a smooth curve.
Furthermore, with rounding of values, often there are clusters with the same test value in one or both predictor groups, making interpretation difficult
A large cluster will cause a large change in True and False Positive Rates, when the change in cut off value is small
A cluster will result in an uneven relationship between false and true positive rates, as the values of one may change while the other remains the same.
An example of this is shown in the plot to the right. If the cut off for decision making is 155 (the black line), data points
can be clearly separated into above or below that value. However, if the cut off value is set at 154 (the blue line), there are 3 data points
in the Outcome Positive group and 2 in the Outcome Negative group that have this exact value. Whether these are considered above
the cut off, below the cut off, or excluded from consideration, will have a large impact on subsequent results produced.
The resulting ROC plot would be as the black line in the plot to the left.
Curve fitting would result in a ROC curve that has the closest fit with the data, yet allows a continuous interpretation along
the whole range of the Test values, as shown in the red line in the plot to the left.
References
Hanley JA, McNeil BJ (1982) The meaning and use of the Area Under a Receiver
Operating Characteristic (ROC) curve. Radiology 143:29-36
Simel D.L., Samsa G.P., Matchar D.B. (1991) Likelihood ratios with confidence:
sample size estimation for diagnostic test studies. J. Clin. Epidemiology
vol 44 No. 8 pp 763-770
Moses LE, Shapiro D, and Littenberg B(1993) Combining independent studies of a
diagnostic test into a Summary ROC Curve: Data analysis approaches and some
additional considerations. Statistics in Medicine 12:p1293-1316.
Deeks J.J, and Morris J.M. (1996) Evaluating diagnostic tests. In Bailliere's
Clinical Obstetrics and Gynaecology Vol.10 No. 4, December 1996
ISBN 0-7020-2260-8 p. 613-631.
Fagan T.J. (1975) Nomogram for Bayer's Theorem. New England J. Med. 293:257
Sackett D, Haynes R, Guyatt G, Tugwell P. (1991) Clinical Epidemiology: A Basic
Science for Clinical Medicine. Second edition. ISBN 0-316-76599-6.
Example
Test Value
FPR
TPR
162.5
0.96
1
162
0.92
1
161.5
0.84
1
160
0.84
0.96
159.5
0.76
0.96
159
0.68
0.96
158.5
0.48
0.92
157.5
0.4
0.88
157
0.36
0.88
156.5
0.36
0.8
156
0.24
0.68
155.5
0.2
0.6
154
0.12
0.48
153.5
0.04
0.4
153
0.04
0.36
152.5
0
0.28
151.5
0
0.24
151
0
0.2
150.5
0
0.16
150
0
0.12
149
0
0.08
This example are computer generated and do not represent any real information. It purports to be from a study of using maternal height (cms) as a test to predict the outcome of Caesarean Section in childbirth, the shorter the height, the more likely Caesarean Section. The 3 columns are the test value (maternal height in cms), False Positive Rate (FPR), and True Positive Rate (TPR). The data is as shown in the table to the right. This table can be generated from original clinical observations using the ROCs program
The Algorithm uses the polynomial curve fitting. As both False and True positive rates are probabilities, their logit transform were used as the dependent variable. The formulae are:
p represents FPR or TPR, and y its logit transform.
x represents the predictor (height in cms in this case)
The formulae are:
y = log((p / (1-p))) p = 1 / (1 + exp(-y))
Polynomial curve fitting is y = Intercept + c1(x) + c2(x2) + c3(x3)
Before processing, FPR and TPR values less than 0.00001 are defaulted to 0.00001, and greater than 0.99999 to 0.99999 to avoid the division by zero error
Three options for selection data
Option A includes all the data, as entered.
Option B includes only those test values from the two outcome groups overlapped, excluding values where TPR or FPR are 0 or 1. The excluded data are usually irrelevant to the ROC, as their interpretation is obvious, and their inclusion may bias the fitted curve to hug the borders excessively. For these reasons, option B is recommended
Option C includes only data that are in the upper left quadrant of the ROC plot, where FPR<=0.5 and TPR>=0.5. The results of the option provides greater precision to those values that are of interest to the clinicians, as values where the predictor has a high probability of being wrong (FPR>0.5 or TPR<0.5) are excluded.
Options for polynomial power of curve fitting
Polynomial Regression allows any value for power, but only up to the third power (3) are provided for curve fitting the ROC in this page. In most cases, the results from different options are very similar, as most test had a linear relationship with the logit of the probabilities concerned, and the curve only needs to be bent slightly to cater for slight difference in the probability distribution at different test values.
The use of higher power also risk overfitting, a greater precision in fitting the data presented, but producing results that are less reproducible.
Users should thereforre examine the results of using different power, and choose the lowest level that produces a satisfactory result. In most cases, a linear (power=1) regression would be the most appropriate option.
Results and their Interpretations
The program produces one plot and two tables. Using the default example input data,
the plots produced from different options are shown to the left. The red curve used algorithm A, all data presented and curve fitted to the power of 2. The black curve used algorithm B, excluding non-overlapping data. The green curve uses algorithm C, including only data where TPR>=0.5 and FPR<=0.5. Both black and green curves were curve fitted linearly (power=1).
The plot to the right and the two tables on this panel show the relationship between original
data (black circular dots) and the curve fitted ROC curve using algorithm B, including data that
have values >0 and <1. The curve is fitted linearly (power=1), and the short straight line joins the
coordinate of the original values to the values occupied on the fitted curve for each data point.
The formular produced using the default example data are:
For False Positive Fate (FPR)
y = (-102.072417 + (0.646875(maternal height)))
FPR = ( 1 / (1 + EXP(-y)))
e,g, for maternal height of 160, y = 1.4276, FPR = 0.8065
For True Positive Rate (TPR)
y = (-91.204314 + (0.591408(maternal height)))
TPR = (1 / (1 + EXP(-y)))
e,g, for maternal height of 160, y = 0.4210, TPR = 0.9684
Data
Curve Fitted
160
0.84
0.96
0.81
0.97
159.5
0.76
0.96
0.75
0.96
159
0.68
0.96
0.68
0.94
158.5
0.48
0.92
0.61
0.93
157.5
0.4
0.88
0.45
0.88
157
0.36
0.88
0.37
0.84
156.5
0.36
0.8
0.30
0.80
156
0.24
0.68
0.24
0.74
155.5
0.2
0.6
0.18
0.68
154
0.12
0.48
0.08
0.47
153.5
0.04
0.4
0.06
0.40
153
0.04
0.36
0.04
0.33
Please note that the program produces coefficients to 6 decimal point precision and results to 4 decimal point precision. Tables are rounded to 2 decimal points for presentation on this page.
Table of Transformed Data is the table on the left. The first 3 columns displays the original
data as they were entered, and the last two column the curve fitted FPR and TPR. This table is for
the user to review, to consider whether the algorithm chosen is appropriate, whether the
results reflect the inputted data, and whether the parameters of the curve fitted ROC can be
generalized for future clinical use.
It can be seen that, above a height of 160cms, all mothers delivered vaginally, and below 153cms all
mothers required a Caesarean Section The data overlapped between these two values were used for curve
fitting (in this example).
It can also be seen that, where the data overlapped, the curve fitted is
closed enough to the original for practical use.
Test Value
FPR
TPR
TNR
YI
TPR/TNR
TNR/TPR
LR+
LR-
153.0
0.04
0.33
0.96
0.28
0.34
2.92
7.60
0.70
153.1
0.05
0.35
0.95
0.30
0.36
2.75
7.36
0.69
153.3
0.05
0.37
0.95
0.31
0.38
2.60
7.13
0.67
153.4
0.06
0.38
0.94
0.33
0.41
2.46
6.89
0.65
153.6
0.06
0.40
0.94
0.34
0.43
2.32
6.65
0.63
153.7
0.07
0.42
0.93
0.36
0.45
2.20
6.42
0.62
153.8
0.07
0.44
0.93
0.37
0.48
2.09
6.18
0.60
154.0
0.08
0.47
0.92
0.39
0.50
1.98
5.95
0.58
154.1
0.09
0.49
0.92
0.40
0.53
1.88
5.72
0.56
154.3
0.09
0.51
0.91
0.41
0.56
1.79
5.49
0.54
154.4
0.10
0.53
0.90
0.43
0.59
1.71
5.26
0.53
154.5
0.11
0.55
0.89
0.44
0.61
1.63
5.04
0.51
154.7
0.12
0.57
0.88
0.45
0.64
1.55
4.82
0.49
154.8
0.13
0.59
0.87
0.46
0.67
1.48
4.61
0.47
155.0
0.14
0.61
0.86
0.47
0.71
1.42
4.41
0.45
155.1
0.15
0.63
0.85
0.48
0.74
1.36
4.21
0.44
155.2
0.16
0.65
0.84
0.49
0.77
1.30
4.02
0.42
155.4
0.17
0.67
0.83
0.49
0.81
1.24
3.84
0.40
155.5
0.19
0.68
0.81
0.50
0.84
1.19
3.66
0.39
155.7
0.20
0.70
0.80
0.50
0.88
1.14
3.49
0.37
155.8
0.22
0.72
0.78
0.50
0.92
1.09
3.33
0.36
155.9
0.23
0.74
0.77
0.50
0.96
1.05
3.17
0.34
156.1
0.25
0.75
0.75
0.50
1.00
1.00
3.03
0.33
156.2
0.27
0.77
0.73
0.50
1.04
0.96
2.88
0.32
156.4
0.28
0.78
0.72
0.50
1.09
0.92
2.75
0.31
156.5
0.30
0.79
0.70
0.49
1.14
0.88
2.63
0.29
156.6
0.32
0.81
0.68
0.49
1.19
0.84
2.51
0.28
156.8
0.34
0.82
0.66
0.48
1.25
0.80
2.40
0.27
156.9
0.36
0.83
0.64
0.47
1.30
0.77
2.29
0.26
157.1
0.38
0.84
0.62
0.46
1.37
0.73
2.20
0.25
157.2
0.41
0.85
0.59
0.45
1.44
0.70
2.11
0.25
157.3
0.43
0.86
0.57
0.44
1.51
0.66
2.02
0.24
157.5
0.45
0.87
0.55
0.42
1.59
0.63
1.94
0.23
157.6
0.47
0.88
0.53
0.41
1.67
0.60
1.87
0.22
157.8
0.49
0.89
0.51
0.40
1.76
0.57
1.80
0.22
157.9
0.52
0.90
0.48
0.38
1.86
0.54
1.74
0.21
158.0
0.54
0.91
0.46
0.37
1.97
0.51
1.68
0.21
158.2
0.56
0.91
0.44
0.35
2.08
0.48
1.62
0.20
158.3
0.58
0.92
0.42
0.33
2.21
0.45
1.57
0.20
158.5
0.61
0.92
0.39
0.32
2.35
0.43
1.53
0.19
158.6
0.63
0.93
0.37
0.30
2.50
0.40
1.48
0.19
158.7
0.65
0.94
0.35
0.29
2.66
0.38
1.44
0.18
158.9
0.67
0.94
0.33
0.27
2.84
0.35
1.41
0.18
159.0
0.69
0.94
0.31
0.26
3.03
0.33
1.37
0.18
159.2
0.71
0.95
0.29
0.24
3.25
0.31
1.34
0.17
159.3
0.73
0.95
0.27
0.23
3.48
0.29
1.31
0.17
159.4
0.74
0.96
0.26
0.21
3.73
0.27
1.29
0.17
159.6
0.76
0.96
0.24
0.20
4.01
0.25
1.26
0.17
159.7
0.78
0.96
0.22
0.19
4.31
0.23
1.24
0.17
159.9
0.79
0.97
0.21
0.17
4.64
0.22
1.22
0.16
160.0
0.81
0.97
0.19
0.16
5.00
0.20
1.20
0.16
Table of Curve Fitted Values
The table to the right provides the results of curve fitting between the range of input data, divided into 50 intervals. Once the user is satisfied with the results, this table can be used as reference for decision making.
Column 1 is the calculated intervals of test values (in this case maternal height). Column 2 and 3 are the False (FPR) and True (TPR) Positives
Column 4 is the True Negative Rate TNR = 1-FPR. This is used in some of the subsequent calculations
Column 5 is the Youden Index YI = TPR+TNR-1, which represents the overall accuracy of the values. The Test value associated
with the maximum YI is sometimes used as the cut off value for clinical decision making, and in this example, the closest
is a maternal height of 156cms (156.02), with Youden Index = 0.51
Column 6 and 7 is the ratio of TPR/TNR and its inverse TNR/TPR. These are commonly used for the following purposes
An alternative to the Youden Index for selecting the best cut off value is Q*, suggested by Moses et.al (see references).
This is a point where TPR/TNR = 1, and represents the intersection between the ROC and a line joining the top left and
bottom right corner of the plot. In this example, the closest is also a maternal height of 156cms, with TPR/TNR=0.98
If the test is being used for screening purposes, to create an early warning system, then a High TPR is preferred over a
high TNR. A TPR/TNR ratio of between 2 and 3 is sometimes used for this purposes. In our example, the closest is a maternal
height of 159cms, where TPR/TNR=2.94. This can be set as an alert trigger, possibly making a rule that all
mothers admitted to the labour ward shorter than 159cms should be reviewed by an experienced obstetrician in early labour.
If the test is to make decisions, particularly if the decision is expensive or has a high risk, then a High TNR is preferred over a
high TPR. A TNR/TPR ratio of between 2 and 3 is sometimes used for this purposes. In our example, the closest is a maternal
height of 153cms (153.1), where TPR/TNR=2.86. This can be set as an decision trigger, possibly making a rule that all
mothers admitted to the labour ward shorter than 153cms should be considered for Caesarean Section without a trial of labour.
Column 8 and 9 are Likelihood Ratios for Test Positive and Test negative. Discussions on Likelihood Ratio are provided in
the prediction page and will not be repeated here.
Disclaimer and Comments
The reasons for developing the curve fitting program for ROC are presented in the introduction. The program has gone through a number of changes.
The initial development was to repeat the method described in the paper by Moses et.al., regressing logit(TPR) against logit(FPR), but using data from a single study rather than multiple sets of FPR and TNR from a meta-analysis. Although this seemed to work, there was no provision to include the test values as a predictor.
A second attempt (2017) was to add a regression of logit(FPR) against the test value, so that, from the test value, one can estimate the FPR, and from the FPR one can estimate the TPR. Options to select which part of the data to analysed was also introduced. This also seemed to work, but a regression upon a regression seems to be adding approximation to approximation, giving rise to anxiety over reproducibility.
The current version (Feb 2020) is a major departure, seperately regressing the logits of FPR and TPR agains the test values, and providing a polynomial curve fit instead of assuming a linear relationship between the test and the logits.
Please be aware that the curve fitting program used formula found in the paper by Moses et.al. (see reference), to draw a line through all the data points in a ROC curve. The only assumptions are that the predictor (test measurement) is a continuous measurement, and that FPR are TPR are probabilities with a logistic distribution.
The algorithm has not been rigorously tested or reviewed, and users should not assume that the method is a generally accepted statistical procedure. Currently (February 2020) I am unable to find any reference on this subject, and I have not received any feedback or criticism, so I am uncertain whether there are any pitfalls in this approach that I have overlooked. My own approach is to use this as a tool, and to separately study the validity of the results produced.
Users inexperienced in statistics should seek professional advice before using this algorithm. From the experienced users, feedback, advice, and criticisms would be most welcomed.
Javascript Program
Data
Power (1-3) for curve fitting
Data from a single ROC : All rows have 3 columns - Column 1 = Test Value
- Column 2 = False Positive Rate (FPR)
- Column 3 = True Positive Rate (TPR)
MacroPlot Code
R Code
The following is a program written by me in R, which produces the same results as that written in the Javascript prpogram
This R program was used to check and validate the results produced in the php program, and can be copied and pasted into RStudio, and run directly.
The program is presented here so that those interested can cross check the calculations, or to develop the idea further.
No restrictions are placed on the copy and use of these codes, although an acknowledgement would be appreciated.
Feedback, advice, or criticism are all very welcomed.
# Curvefit ROC
# This program uses all of the data (Option A in the php program)
# Power of curve fit is set before running, by changing the value of pw
myDat = ("
Test FPR TPR
162.5 0.96 1.00
162.0 0.92 1.00
161.5 0.84 1.00
160.0 0.84 0.96
159.5 0.76 0.96
159.0 0.68 0.96
158.5 0.48 0.92
157.5 0.40 0.88
157.0 0.36 0.88
156.5 0.36 0.80
156.0 0.24 0.68
155.5 0.20 0.60
154.0 0.12 0.48
153.5 0.04 0.40
153.0 0.04 0.36
152.5 0.00 0.28
151.5 0.00 0.24
151.0 0.00 0.20
150.5 0.00 0.16
150.0 0.00 0.12
149.0 0.00 0.08
")
# create dataframe from input data. df is the dataframe
df <- read.table(textConnection(myDat),header=TRUE)
summary(df)
# create logits of FPR and TPR using function MakeLogit
MakeLogit <- function(vec)
{
vec[vec>0.99999] <- 0.99999
vec[vec<0.00001] <- 0.00001
vecRes <- log(vec / (1 - vec))
vecRes
}
logitFPR <- MakeLogit(df$FPR)
logitTPR <- MakeLogit(df$TPR)
# curvefit logitFPR and logitTPR against Test.
# pw = power of polynomial curve fitting
pw = 2
resFPR<-lm(formula = logitFPR ~ poly(df$Test, pw, raw=TRUE))
resTPR<-lm(formula = logitTPR ~ poly(df$Test, pw, raw=TRUE))
# Display results of curve fitting
summary(resFPR)
summary(resTPR)
# Extract coefficients vector for future calculations
coefFPR <- coef(summary(resFPR))[1:(pw+1)]
coefTPR <- coef(summary(resTPR))[1:(pw+1)]
# Calculate curve fitted values for FPR and TPR
# using function CalCurveFitValues
# and append them to data frame
CalCurveFitValues <- function(coefVec, datVec)
{
f = length(coefVec)
n = length(datVec)
vecResult <- vector()
for ( i in 1:n)
{
x = datVec[i]
y = coefVec[1] + coefVec[2] * x
for (j in seq(3, f, by=1)){ y = y + coefVec[j] * x^(j-1) }
vecResult[i] = 1 / (1 + exp(-(y)))
}
vecResult
}
df$cfFPR <- CalCurveFitValues(coefFPR, df$Test)
df$cfTPR <- CalCurveFitValues(coefTPR, df$Test)
# Display original and curve fitted values
df
# Create dataframe table of calculations for range of predictor
# divided into 50 intervals
minv = min(df$Test)
maxv = max(df$Test)
Test <- seq(from = minv, to = maxv, length.out = 50)
dfTable <- data.frame(Test)
# Calculate and append all columns into dfTable,
# rounded to 4 decimal places
# False Positive Rate FPR
dfTable$FPR <- round(CalCurveFitValues(coefFPR, dfTable$Test),4)
# True Positive Rate TPR
dfTable$TPR <- round(CalCurveFitValues(coefTPR, dfTable$Test),4)
# False Negative Rate FNR
dfTable$FNR <- round(1-dfTable$TPR,4)
# True Negative Rate TNR
dfTable$TNR <- round(1-dfTable$FPR,4)
# Youden Index YI
dfTable$YI <- round(dfTable$TPR + dfTable$TNR - 1,4)
# TPR / TNR PNRatio
dfTable$PNRatio <- round(dfTable$TPR / dfTable$TNR,4)
# TNR / TPR NPRatio
dfTable$NPRatio <- round(dfTable$TNR / dfTable$TPR,4)
# Likelihood Ratio Test Positive LRPos
dfTable$LRPos <- round(dfTable$TPR / dfTable$FPR,4)
# Likelihood Ratio Test Negative LRNeg
dfTable$LRNeg <- round(dfTable$FNR / dfTable$TNR,4)
# Display table
dfTable