Box-and-Whisker Plots with The SAS System David Shannon, Amadeus Software Limited



Similar documents
Using SPSS, Chapter 2: Descriptive Statistics

Multiple Box-and-Whisker Plot

Exploratory data analysis (Chapter 2) Fall 2011

3: Summary Statistics

Descriptive statistics Statistical inference statistical inference, statistical induction and inferential statistics

Bellwork Students will review their study guide for their test. Box-and-Whisker Plots will be discussed after the test.

Variables. Exploratory Data Analysis

STATS8: Introduction to Biostatistics. Data Exploration. Babak Shahbaba Department of Statistics, UCI

CC03 PRODUCING SIMPLE AND QUICK GRAPHS WITH PROC GPLOT

Scatter Plots with Error Bars

HISTOGRAMS, CUMULATIVE FREQUENCY AND BOX PLOTS

Exercise 1.12 (Pg )

2 Describing, Exploring, and

Describing, Exploring, and Comparing Data

Describing and presenting data

Lecture 1: Review and Exploratory Data Analysis (EDA)

Formulas, Functions and Charts

Statgraphics Getting started

Probability Distributions

Microsoft Excel 2010 Part 3: Advanced Excel

AP * Statistics Review. Descriptive Statistics

Diagrams and Graphs of Statistical Data

Graphing in SAS Software

Scientific Graphing in Excel 2010

Descriptive Statistics

Descriptive Statistics

The right edge of the box is the third quartile, Q 3, which is the median of the data values above the median. Maximum Median

Summary of Formulas and Concepts. Descriptive Statistics (Ch. 1-4)

CHAPTER TWELVE TABLES, CHARTS, AND GRAPHS

Lecture 2. Summarizing the Sample

Training/Internship Brochure Advanced Clinical SAS Programming Full Time 6 months Program

Introduction to Statistics for Psychology. Quantitative Methods for Human Sciences

Bar Graphs and Dot Plots

Intro to Statistics 8 Curriculum

Box-and-Whisker Plots

Chapter 18 The BOXPLOT Procedure. Chapter Table of Contents

Good luck! BUSINESS STATISTICS FINAL EXAM INSTRUCTIONS. Name:

1.3 Measuring Center & Spread, The Five Number Summary & Boxplots. Describing Quantitative Data with Numbers

SPSS Introduction. Yi Li

Means, standard deviations and. and standard errors

Visualizing Data. Contents. 1 Visualizing Data. Anthony Tanbakuchi Department of Mathematics Pima Community College. Introductory Statistics Lectures

How Does My TI-84 Do That

Solar Matters III Teacher Page

Data Exploration Data Visualization

Paper KEYWORDS PROC TRANSPOSE, PROC CORR, PROC MEANS, PROC GPLOT, Macro Language, Mean, Standard Deviation, Vertical Reference.

Box-and-Whisker Plots

CHARTS AND GRAPHS INTRODUCTION USING SPSS TO DRAW GRAPHS SPSS GRAPH OPTIONS CAG08

Using Excel for descriptive statistics

Common Tools for Displaying and Communicating Data for Process Improvement

Modifying Colors and Symbols in ArcMap

Creating Charts in Microsoft Excel A supplement to Chapter 5 of Quantitative Approaches in Business Studies

Understanding, Identifying & Analyzing Box & Whisker Plots

Confidence Intervals for One Standard Deviation Using Standard Deviation

Exploratory Data Analysis

Northumberland Knowledge

Module 2: Introduction to Quantitative Data Analysis

Introduction... 1 Welcome Screen... 2 Map View Generating a map Map View Basic Map Features... 4

Pie Charts. proportion of ice-cream flavors sold annually by a given brand. AMS-5: Statistics. Cherry. Cherry. Blueberry. Blueberry. Apple.

Instat Tutorial. by Roger Stern, Sandro Leidi, Ian Dale and Colin Grayer. Contents. Installation 2

Descriptive Analysis

Tutorial 3: Graphics and Exploratory Data Analysis in R Jason Pienaar and Tom Miller

Innovative Techniques and Tools to Detect Data Quality Problems

STAT355 - Probability & Statistics

Dealing with Data in Excel 2010

BNG 202 Biomechanics Lab. Descriptive statistics and probability distributions I

LEGEND OPTIONS USING MULTIPLE PLOT STATEMENTS IN PROC GPLOT

University of Arkansas Libraries ArcGIS Desktop Tutorial. Section 2: Manipulating Display Parameters in ArcMap. Symbolizing Features and Rasters:

Demographics of Atlanta, Georgia:

OVERVIEW OF THE ENTERPRISE GUIDE INTERFACE

How To Write A Data Analysis

Week 1. Exploratory Data Analysis

Chapter 1: Looking at Data Section 1.1: Displaying Distributions with Graphs

Chapter 6: Constructing and Interpreting Graphic Displays of Behavioral Data

Mathematical goals. Starting points. Materials required. Time needed

The Basics of Creating Graphs with SAS/GRAPH Software Jeff Cartier, SAS Institute Inc., Cary, NC

Mean = (sum of the values / the number of the value) if probabilities are equal

Getting started in Excel

How To Check For Differences In The One Way Anova

MBA 611 STATISTICS AND QUANTITATIVE METHODS

Histogram of Numeric Data Distribution from the UNIVARIATE Procedure

Measurement with Ratios

GeoGebra Statistics and Probability

Center: Finding the Median. Median. Spread: Home on the Range. Center: Finding the Median (cont.)

Dongfeng Li. Autumn 2010

Drawing a histogram using Excel

Producing Structured Clinical Trial Reports Using SAS: A Company Solution

Geostatistics Exploratory Analysis

Exploratory Spatial Data Analysis

Statistics Chapter 2

CHAPTER THREE COMMON DESCRIPTIVE STATISTICS COMMON DESCRIPTIVE STATISTICS / 13

Scatter Chart. Segmented Bar Chart. Overlay Chart

Mean, Median, and Mode

Lecture 2: Descriptive Statistics and Exploratory Data Analysis

Cell Phone Impairment?

Transcription:

Box-and-Whisker Plots with The SAS System David Shannon, Amadeus Software Limited Abstract One regularly used graphical method of presenting data is the box-and-whisker plot. Whilst the vast majority of pharmaceutical statisticians produce their statistical output with The SAS System, until V8 producing boxand-whisker diagrams to a high standard was only achievable through custom macros and annotating graphics. With the introduction of Proc BOXPLOT to the SAS/STAT module statisticians now have the power to produce several styles of box-and-whisker plots, thus enabling comparative displays of data groups to be easily presented. This paper examines the statistical capabilities of Proc BOXPLOT, the styles of box-and-whisker plot it can produced and points out the pitfalls those programming the procedure should consider. Introduction The box-and-whisker plot, referred to as a box plot, was first proposed by Tukey in 1977. Figure 1: Box & Whisker Diagram, Tukey, 1977. Maximum Value H 3 H 1 Minimum Value Tukey s original box-and-whisker plot used the less familiar hinge instead of upper and lower quantile measurements. The whiskers were drawn all the way to the upper and lower observations, were a dot and hatched line represented these values, respectively. Since then several variations and enhancements from the original definition have been published, notably McGill, Tukey and Larsen in 1978 which introduced the notched box plot for locating confidence limits of the median within the box-and-whisker plot. As a graphical means of exploring distributions of qualitative data, many researchers, not just in the pharmaceutical industry, use this technique for examining data and presenting findings. Commonly box-and-whisker plots are used to show trends of a distribution through time, or for side-by-side comparisons of groups of data. This paper examines how the pharmaceutical statisticians most commonly available tool, The SAS System, can produce box-and-whisker plots. It should be noted that in addition to Base SAS, the SAS/STAT and SAS/GRAPH modules are required to use the BOXPLOT procedure. Amadeus Software Limited, Orchard Farm, Witney Lane, Leafield, Oxfordshire UK OX29 9PG Page 1 of 9 Tel: 01993 878287 Fax: 01993 878042 email:info@amadeus.co.uk

How are Box-and-Whisker Plot Constructed? Box-and-whisker plots are constructed from the data groups mean, median, quartiles and outlying observations. The two common styles of box-and-whisker plot used in statistics today are the skeletal and schematic plots. Figure 2: Skeletal Box & Whisker Style Maximum Value The skeletal plot (shown in Figure 2), draws its whiskers to the maximum and minimum values in the group of data plotted. The upper and lower quartiles make up the boundaries of the box, the height of the box therefore represents the interquartile range (IQR). Upper Quartile (Q3) Mean Lower Quartile (Q1) Interquartile Range The arithmetic mean of the group of data is plotted with a symbol, in this example a plus sign is used. Minimum Value The schematic style of box-and-whisker plot is shown in Figure 3. This also draws the box height as the interquartile range, and plots a symbol at the arithmetic mean. Figure 3: Schematic Box & Whisker Style Maximum Value Outlying observation However, a skeletal plot determines where the lower and upper fences are. These are located at 1½ x IQR either side of Q3 and Q1. The fences are not actually plotted on the graph. The whiskers are drawn to the value nearest to, but within, each fence. Any observations beyond a fence is plotted with a symbol. In Figure 3 the lower whisker is drawn to the minimum value because it falls within the lower fence. 1.5 x IQR Interquartile Range Upper Fence = (1.5 x IQR )+Q3 Highest observation within fence Upper Quartile (Q3) Mean Lower Quartile (Q1) 1.5 x IQR Minimum Value Lower Fence = Q1-(1.5 x IQR ) Page 2 of 9

The SAS System s Proc Boxplot Prior to version eight of SAS, box-and-whisker plots could be produced with Proc UNIVARIATE. Proc GPLOT could produce high resolution box-and-whisker plots as an interpolation option, although their is little flexibility over methodology and appearance. Many variations of macros to draw plots with the annotate facility can be found, however such approaches require potential maintenance of code and are not necessarily supported by SAS Institute. With the release of V8 the BOXPLOT procedure became production, allowing side-by-side box-and-whisker plots to be produced on groups of data. The minimum syntax of the procedure is as follows: Where: PROC BOXPLOT ; PLOT analysis-variable * group-variable / options; RUN; analysis-variable is the measurement of interest. This will be plotted on the y-axis. group-variable is plotted on the x-axis. options can be any of 89 options which control the box-and-whisker plot drawing methodology and appearance. Both analysis and group variables are required. Interestingly, the input data set must be sorted on the group variable, otherwise an error is returned for numeric variables and character variables, whilst appearing to take on a life of their own, are actually treated similarly to a class variable that has not been consolidated into unique groups. Statistical Capabilities The BOXPLOT procedure draws the box-and-whisker plots directly from the raw data. There is no method of saving the quantile and mean statistics generated by the procedure, used to in the plot. There is one option on the plot statement (NLEGEND) which allows the group sample sizes to be included in a legend on the plot. Control over the methodology used to calculate the quantile statistics can be exercised, as in Base SAS procedures which calculate quantile statistics. The PCTLDEF=index option allows any of the following five definitions to be used. The default is 5: Index Definition 1 Weighted average x np 2 Observation numbered closed to np 3 Empirical distribution function 4 Weighted average x p(n+1) 5 Empirical distribution function with averaging The NOTCHES option can be used to apply the McGill, Tukey and Larson variation on a box-and-whisker plot which draws approximate 95% confidence intervals of the medians. Page 3 of 9

Figure 4: Box & Whisker Plot with Notches Maximum Value The notches in Figure 4 are shown between the arrows. The confidence interval of the median (identified by the notch) is located between: IQR 1. 58 n 1.58( IQR / n) Upper Quartile (Q3) Mean Lower Quartile (Q1) Minimum Value When like groups of data are plotted side-by-side and the notch boundaries do not overlap, it can be concluded there is a difference between the medians at around the 5% level of statistical significance. In small sample sizes a notch may appear to fold back on its self, e.g. the lower quartile is higher than the lower confidence limit of the median. Types of Box-and-Whisker Plots Produced by SAS Skeletal By default Proc BOXPLOT produces a skeletal plot. The following example takes a data set of white blood cell counts and generates box-and-whisker plots for each treatment group at Day 1. * Data must be sorted by the grouping variable; proc sort data=boxplot.wbc out=work.skeletal; by trtcd; * Generate skeletal plot for the BASELINE analysis variable; proc boxplot data=work.skeletal(where=(day=1)); title1 "White Blood Cell Count at Day 1 (g/l)"; title2 "Skeletal Box-and-Whisker Plot"; plot baseline*trtcd; Page 4 of 9

Figure 5: Skeletal Box & Whisker Plot from Proc Boxplot Schematic A schematic plot can be requested by altering setting the BOXSTYLE option on the plot statement as follows: PLOT analysis-variable * group-variable / BOXSTYLE= SCHEMATIC ; Schematic ID An extension of the schematic plot is to include a label to each of the outlying observations. For example, this may be a subject number or observed value. The value from the first variable given in the ID statement is draw against the outlying value. The following code demonstrates requesting a schematic box-and-whisker plot with outlying values labelled with the subject identifier. The BOXWIDTHSCALE option is included to draw boxes with widths proportional to proportional to n in each group. proc boxplot data=work.schematic(where=(trtcd=1)); plot supdia*day / boxstyle=schematicid boxwidthscale=0.5; id subjid; Page 5 of 9

Figure 6: Schematic Box & Whisker Plot with Labelled Outliers Figure 6 shows subject 006, 010 and 019 identified as observations falling outside either the upper or lower fences. Notice also the widths of bars varies through time as the number of subjects with observed data fluctuates. Schematic ID Far When the schematic BOXSTYLE=SCHEMATICIDFAR option is used in combination with an ID variable on the ID statement, only observations falling outside the upper and lower far fences are labelled. Upper and lower far fences are determined with similar methodology as described in Figure 3 above, except the far fences are located at 3xIQR either side of the upper and lower quartiles. Box Widths All styles of box-and-whisker plots allow the BOXWIDTHSCALE option to draw each box width in proportion to the sample size in that boxes group. The usage of BOXWIDTHSCALE= is as follows: PLOT analysis-variable * group-variable / BOXWIDTHSCALE= value; Where value determines the function used to calculate the proportion as follows: n value Therefore when value is 0.5 widths are proportional to n as shown in Figure 6. If desired, the width of all boxes can set to a percentage of the screen width or absolute number of pixels with the BOXWIDTH= option. Page 6 of 9

Grouping Box-and-Whisker Plots within Blocks In addition to grouping data along the x-axis an additional blocking variable can be specified. This allows data to grouped within groups. For example, supposing the white blood cell data are to be presented through time, for each treatment group plot can be achieved as demonstrated in Figure 7. Figure 7: Box & Whisker Plot with Blocking and Notches The syntax for including a blocking variable is as follows: PLOT analysis-variable * group-variable(block-variable) / options ; Therefore it would be expected that the following syntax would produce the figure above: PROC BOXPLOT data= ; PLOT result * day (trtcd) / options ; ID subjid; RUN; However, because the group variable is numeric the input data set must be sorted on that variable, but to allows the blocks the data must also be sorted on the block variable, in this example TRTCD which represents the treatment code. In actual fact, the code above (when all variables in the plots statement are numeric) produces Figure 8. Notice that only the first level of the block variable has been displayed, and within that block the whole data set has been used to draw the three boxes for days 1, 14 and 21. Page 7 of 9

Figure 8: Box & Whisker Plot with Incorrect Blocking To avoid such a potentially dangerous mistake it is important to understand how the input data set must be constructed for Proc BOXPLOT when blocking is required. Firstly the group variable must be converted to a character field, this avoids the need for the input data set to be sorted on this variable first. The block variable is therefore the first sort variable with the character version of the day variable sorted within the block variable. The input data set now looks like the following sample: Notice that in Figures 7 & 8 the NOTCHES option is used. Also used is the CBOXES = (variable) option. This allows a variable in the input data set to hold the text of a valid SAS colour to which is used to draw each blocks box-and-whisker plots in that colour. The code used to produce Figure 7 is shown below, where DAYC is the character representation of the numeric DAY variable. Some additional options are also used to give an indication of the flexible appearance options, of which there are far too many to discuss. Page 8 of 9

proc sort data=boxplot.wbc out=work.wbc; by trtcd dayc ; proc boxplot data=work.wbc; plot result * dayc(trtcd) / boxstyle=schematicid notches blockpos=2 vaxis=axis1 cboxes=(colorb) noframe pagenum='page # of #'; id subjid; label dayc ='Day'; Conclusions Box-and-whisker plots are a useful means of exploring and presenting data. There are several variations of presentation style any of which may be valid presentations of a data set. Producing high resolution box-and-whisker plots in SAS has only previously been available as an interpolation option through Proc GPLOT with SAS/GRAPH. The level of control is limited through this route, requiring potentially complex macros to be required used to achieve the desired result. Now Proc BOXPLOT allows box-and-whisker plots to be drawn in several styles of plot, whilst allowing extensive control over appearance itself. As Proc BOXPLOT adheres to the rules of SAS/GRAPH any graphic options are also honoured in the usual way. Users of the procedure should be aware that the input data set must be sorted appropriately for grouping data. Particular attention must be given to the set-up of input data when blocking is also applied to the box-andwhisker plots, as potentially inaccurate figures could be misleading. Contact I very much welcome your feedback on this paper, or your thoughts on the subject of statistical graphics with The SAS System. Contact the author: David Shannon Amadeus Software Limited Orchard Farm Witney Lane Leafield Oxfordshire OX29 9PG United Kingdom Phone: +44 (0)1993 878287 Fax: +44 (0)1993 878042 Email: david.shannon@amadeus.co.uk Web: www.amadeus.co.uk SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies. Amadeus Software Limited, 2003. Page 9 of 9