Survey

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Survey

Document related concepts

Foundations of statistics wikipedia , lookup

Taylor's law wikipedia , lookup

History of statistics wikipedia , lookup

Bootstrapping (statistics) wikipedia , lookup

Gibbs sampling wikipedia , lookup

Time series wikipedia , lookup

Categorical variable wikipedia , lookup

Student's t-test wikipedia , lookup

Transcript

MINITAB Manual For David Moore and George McCabe’s Introduction To The Practice of Statistics Michael Evans University of Toronto ii Contents Preface I vii Minitab for Data Management 1 2 3 4 5 6 7 Manual Overview and Conventions . . . . . Accessing and Exiting Minitab . . . . . . . . Files Used by Minitab . . . . . . . . . . . . . Getting Help . . . . . . . . . . . . . . . . . . The Worksheet . . . . . . . . . . . . . . . . . Minitab Commands . . . . . . . . . . . . . . Entering Data into a Worksheet . . . . . . . 7.1 Importing Data . . . . . . . . . . . . 7.2 Patterned Data . . . . . . . . . . . . 7.3 Printing Data in the Session Window 7.4 Assigning Constants . . . . . . . . . . 7.5 Naming Variables and Constants . . . 7.6 Information about a Worksheet . . . 7.7 Editing a Worksheet . . . . . . . . . . 8 Saving, Retrieving, and Printing . . . . . . . 9 Mathematical Operations . . . . . . . . . . . 9.1 Arithmetical Operations . . . . . . . . 9.2 Mathematical Functions . . . . . . . . 9.3 Comparisons and Logical Operations . 9.4 Column and Row Statistics . . . . . . 9.5 Sorting Data . . . . . . . . . . . . . . 9.6 Computing Ranks . . . . . . . . . . . 10 Exercises . . . . . . . . . . . . . . . . . . . . II Minitab for Data Analysis 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 4 6 7 7 9 12 13 17 18 19 20 21 21 24 27 27 28 29 31 33 34 35 37 1 Looking at Data–Distributions 39 1.1 Tabulating and Summarizing Data . . . . . . . . . . . . . . . . . 40 1.1.1 Tallying Data . . . . . . . . . . . . . . . . . . . . . . . . . 41 iii iv CONTENTS 1.1.2 Describing Data . . . . . . . . . . . . . . . . Plotting Data . . . . . . . . . . . . . . . . . . . . . . 1.2.1 Stem-and-Leaf Plots . . . . . . . . . . . . . . 1.2.2 Histograms . . . . . . . . . . . . . . . . . . . 1.2.3 Boxplots . . . . . . . . . . . . . . . . . . . . . 1.2.4 Bar Charts . . . . . . . . . . . . . . . . . . . 1.2.5 Pie Charts . . . . . . . . . . . . . . . . . . . 1.2.6 Time Series Plots . . . . . . . . . . . . . . . . 1.3 The Normal Distribution . . . . . . . . . . . . . . . . 1.3.1 Calculating the Density . . . . . . . . . . . . 1.3.2 Calculating the Distribution Function . . . . 1.3.3 Calculating the Inverse Distribution Function 1.3.4 Normal Probability Plots . . . . . . . . . . . 1.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 1.2 2 Looking at Data–Relationships 2.1 Scatterplots . . . . . . . . . . . 2.2 Correlations . . . . . . . . . . . 2.3 Regression . . . . . . . . . . . . 2.4 Transformations . . . . . . . . 2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 45 45 46 51 53 55 56 58 58 59 60 60 63 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 65 69 69 73 74 3 Producing Data 77 3.1 Generating a Random Sample . . . . . . . . . . . . . . . . . . . . 78 3.2 Sampling from Distributions . . . . . . . . . . . . . . . . . . . . . 80 3.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 4 Probability: The Study of Randomness 4.1 Basic Probability Calculations . . . . . . . . 4.2 More on Sampling from Distributions . . . 4.3 Simulation for Approximating Probabilities 4.4 Simulation for Approximating Means . . . . 4.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 85 87 90 91 91 5 Sampling Distributions 95 5.1 The Binomial Distribution . . . . . . . . . . . . . . . . . . . . . . 95 5.2 Simulating Sampling Distributions . . . . . . . . . . . . . . . . . 98 5.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 6 Introduction to Inference 6.1 z ConÞdence Intervals . . . . . . . . 6.2 z Tests . . . . . . . . . . . . . . . . . 6.3 Simulations for ConÞdence Intervals 6.4 Power Calculations . . . . . . . . . . 6.5 The Chi-Square Distribution . . . . 6.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 105 106 108 110 112 113 CONTENTS 7 Inference for Distributions 7.1 The Student Distribution 7.2 t ConÞdence Intervals . . 7.3 t Tests . . . . . . . . . . . 7.4 The Sign Test . . . . . . . 7.5 Comparing Two Samples 7.6 The F Distribution . . . . 7.7 Exercises . . . . . . . . . v . . . . . . . 115 115 116 117 118 120 122 124 8 Inference for Proportions 8.1 Inference for a Single Proportion . . . . . . . . . . . . . . . . . . 8.2 Inference for Two Proportions . . . . . . . . . . . . . . . . . . . . 8.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 127 130 132 9 Inference for Two-Way Tables 9.1 Tabulating and Plotting . . . 9.2 The Chi-square Test . . . . . 9.3 Analyzing Tables of Counts . 9.4 Exercises . . . . . . . . . . . 133 133 138 140 142 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Inference for Regression 145 10.1 Simple Regression Analysis . . . . . . . . . . . . . . . . . . . . . 145 10.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 11 Multiple Regression 155 11.1 Example of a Multiple Regression . . . . . . . . . . . . . . . . . . 155 11.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 12 One-Way Analysis of Variance 12.1 A Categorical Variable and a Quantitative Variable . . . . . . . . 12.2 One-Way Analysis of Variance . . . . . . . . . . . . . . . . . . . 12.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 163 167 172 13 Two-Way Analysis of Variance 175 13.1 The Two-Way ANOVA Command . . . . . . . . . . . . . . . . . 175 13.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 14 Bootstrap Methods and Permutation Tests 14.1 Bootstrap Sampling . . . . . . . . . . . . . . . . . . . . . . . . . 14.2 Permutation Tests . . . . . . . . . . . . . . . . . . . . . . . . . . 14.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 182 185 189 15 Nonparametric Tests 15.1 The Wilcoxon Rank Sum Procedures . . 15.2 The Wilcoxon Signed Rank Procedures . 15.3 The Kruskal-Wallis Test . . . . . . . . . 15.4 Exercises . . . . . . . . . . . . . . . . . 191 191 193 194 195 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi CONTENTS 16 Logistic Regression 197 16.1 The Logistic Regression Model . . . . . . . . . . . . . . . . . . . 197 16.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 16.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 17 Statistics for Quality: Control and Capability 17.1 Producing x̄ Charts . . . . . . . . . . . . . . . 17.2 Producing S Charts . . . . . . . . . . . . . . . 17.3 Producing p Charts . . . . . . . . . . . . . . . . 17.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Projects 203 203 207 208 210 213 B Functions in Minitab 215 B.1 Mathematical Functions . . . . . . . . . . . . . . . . . . . . . . . 215 B.2 Column Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 B.3 Row Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 C More Minitab Commands C.1 Coding . . . . . . . . . . C.2 Concatenating Columns C.3 Converting Data Types C.4 History . . . . . . . . . C.5 Stacking and Unstacking . . . . . . . . . . . . . . . . . . . . . . . . Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 219 220 221 222 223 D Programming in Minitab D.1 Global Macros . . . . . D.2 Control Statements . . . D.3 Startup Macro . . . . . D.4 Interactive Macros . . . D.5 Local Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 225 226 230 230 231 . . . . . . . . . . . . . . . . . . . . . . . . . E Matrix Algebra in Minitab 233 E.1 Creating Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 234 E.2 Commands for Matrix Operations . . . . . . . . . . . . . . . . . 238 Index 243 Preface This Minitab manual is to be used as an accompaniment to Introduction to the Practice of Statistics, Fifth Edition, by David S. Moore and George P. McCabe, and to the CD-ROM that accompanies this text. We abbreviate the textbook title as IPS. It can be used with either Minitab Student Version 14, Minitab Version 14 or Minitab Version 13 running under Windows. The text is based on Minitab Student Version 14 and Minitab Version 14, but we have also indicated in the manual wherever there are diﬀerences with Minitab Version 13, in the way these versions work. The core of the manual is a discussion of the menu commands while not neglecting to refer to the session commands, as these are needed for certain problems. The material on session commands is always at the end of each section and can be skipped if the reader will deÞnitely not be using them. We have provided some Exercises for each chapter. Minitab is a statistical software package that was designed especially for the teaching of introductory statistics courses. It is our view that an easy-to-use statistical software package is a vital and signiÞcant component of such a course. This permits the student to focus on statistical concepts and thinking rather than computations or the learning of a statistical package. The main aim of any introductory statistics course should always be the “why” of statistics rather than technical details that do little to stimulate the majority of students or, in our opinion, do little to reinforce the key concepts. IPS succeeds admirably in communicating the important basic foundations of statistical thinking, and it is hoped that this manual serves as a useful adjunct to the text. It is natural to ask why Minitab is advocated for the course. In the author’s experience, ease of learning and use are the salient features of the package, with obvious beneÞts to the student and to the instructor, who can relegate many details to the software. While more sophisticated packages are necessary for higher-level professional work, it is our experience that attempting to teach one of these in a course forces too much attention on technical aspects. The time students need to spend to learn Minitab is relatively small and it is a great virtue. Further Minitab will serve as a perfectly adequate tool for many of the statistical problems students will encounter in their undergraduate education. vii viii This manual is divided into two parts. Part I is an introduction that provides the necessary details to start using Minitab and, in particular, how to use worksheets. We recommend reading Part I before starting to use Minitab. Overall, the introductory Part I serves as a reference for most of the nonstatistical commands in Minitab. Part II follows the structure of the textbook. Each chapter is titled and numbered as in IPS. The last two chapters are not in IPS but correspond to optional material included on the CD-ROM. The Minitab commands relevant to doing the problems in each IPS chapter are introduced and their use illustrated. Each chapter concludes with a set of exercises, some of which are modiÞcations of or related to problems in IPS and many of which are new and speciÞcally designed to ensure that the relevant Minitab material has been understood. There are also appendices dealing with some more advanced features of Minitab, such as programming in Minitab and matrix algebra. This manual does not attempt a complete coverage of Minitab. Rather, we introduce and discuss those concepts in Minitab that we feel are most relevant for a student studying introductory statistics with IPS. We do introduce some concepts that are, strictly speaking, not necessary for solving the problems in IPS where we feel that they were likely to prove useful in a large number of data analysis problems encountered outside the classroom. While the manual’s primary goal is to teach Minitab, generally we want to help develop strong data analytic skills in conjunction with the text and the CD-ROM. Thanks to W. H. Freeman and Company for their help and consideration. Also thanks to Rosemary and Heather. For further information on Minitab software, contact: Minitab Inc. 3081 Enterprise Drive State College, PA 16801 USA ph: 814.328.3280 fax: 814.238.4383 email: [email protected] URL: http://www.minitab.com Part I Minitab for Data Management 1 New Minitab commands discussed in this part Calc I Calculator Calc I Column Statistics ¯ ¯ ¯ ¯ Calc I Make Patterned Data Calc I Row Statistics ¯ ¯ ¯ ¯ Edit I Copy Cells Edit I Cut Cells ¯ ¯ ¯ ¯ ¯ Edit I Paste Cells Edit I Select All Cells ¯ ¯ ¯ ¯ Edit I Undo Cut Edit I Undo Paste ¯ ¯ ¯ ¯ Editor I Enable Commands Editor I Insert Cells ¯ ¯ ¯ ¯ Editor I Insert Columns Editor I Insert Rows ¯ ¯ ¯ ¯ Editor I Output Editable ¯ ¯ File I Exit File I New ¯ ¯ File I Other Files I Export Special Text File I Open Worksheet ¯ ¯ ¯ ¯ ¯ File I Other Files I Import Special Text File I Print Session Window ¯ ¯ ¯ ¯ ¯ File I Print Worksheet File I Save Current Worksheet ¯ ¯ ¯ ¯ File I Save Current Worksheet As File I Save Session Window As ¯ ¯ ¯ ¯ Help ¯ Data I Copy Columns Data I Display Data ¯ ¯ ¯ ¯ Data I Erase Variables Data I Rank ¯ ¯ ¯ ¯ Data I Sort ¯ ¯ Window I Project Manager ¯ 1 Manual Overview and Conventions Minitab is a software package for carrying out statistical, numerical, and graphical calculations. This manual does not attempt to describe all the possible implementations or the full extent of the package. We limit our discussion to those features common to the most recent versions of Minitab running under the Windows operating system. Version 14 refers to the latest version of Minitab at the time of writing this manual, but we also make reference to Version 13 when there are diﬀerences. This manual can be used with both versions. In this manual, special statistical or Minitab concepts will be highlighted in italic font. You should be sure that you understand these concepts. Primarily, we will be discussing the menu commands that are available in Minitab. Menu commands are accessed by clicking the left button of the mouse 3 4 Minitab for Data Management on items in lists. We use a special notation for menu commands. For example, AIBIC is to be interpreted as left click the command A on the menu bar, then in the list that drops down, left click the command B, and, Þnally, left click C. The menu commands will be denoted in ordinary font (the actual appearance may vary slightly depending on the version of Windows you use). There are also session commands and subcommands that are typed by the user rather than using the mouse. These will be denoted in bold font. Any commands that we actually type, and the output obtained, will be denoted in typewriter font, as will the names of any Þles used by Minitab, variables, constants, and worksheets. We recommend that whenever feasible, the reader use Minitab to do the problems in the text. While many problems can be done by hand, you will save a considerable amount of time and avoid errors by learning to use Minitab eﬀectively. We also recommend that you try out the Minitab commands as you read about them, as this will ensure full understanding. 2 Accessing and Exiting Minitab The Þrst thing you should do is Þnd out how to access the Minitab package. This information will come from your instructor, system personnel, or from your software documentation if you have purchased Minitab to run on your own computer. In most cases, you will double click an icon, such as that shown in Display I.1, that corresponds to the Minitab program. Alternatively, you can use the Start button and click on Minitab in the Programs list. In this case, the program opens with a Minitab window, such as the one shown in Display I.2. The Minitab window is divided into two sub-windows with the upper window called the Session window and the lower one called the Data window. Left clicking the mouse anywhere on a particular window brings that window to the foreground, i.e., makes it the active window, and the border at the top of the window turns dark blue. For example, clicking in the Session window will make that window active. Alternatively, you can use the command Window I ¯ Session in the menu bar at the top of the Minitab window to make this window ¯ active. Display I.1: Minitab icon. Minitab for Data Management 5 Display I.2: Minitab window. You may not see the MTB > prompt in the Session window, and for some things described in this manual it is important that you do so. You can ensure that this prompt always appears in your Session window by using Tools I Options I Session Window I Sub¯ Enable¯radio button and then clicking on mitting Commands, clicking on the OK. Without the MTB > prompt, you cannot type commands to be executed in the Session window. In the session window, Minitab commands are typed after the MTB > prompt and executed when you hit the Enter or Return key. For example, the command exit takes you out of your Minitab session and returns you to the system prompt or operating system. Otherwise, you can access commands using the menu bar (Display I.3) that resides at the top of the Minitab window. For example, you can access the exit command using File I Exit. In many circum¯ ¯ stances, using the menu commands to do your analyses is easy and convenient, although there are certain circumstances where typing the session commands is necessary. You can also exit by clicking on the × symbol in the upper right-hand corner of the Minitab window. When you exit, you are prompted by Minitab in a dialog window with something like the question, “Save changes to this Project before closing?” You can safely answer no to this question unless you are in fact using the Projects feature in Minitab as described in Appendix A. Later, we will discuss how to save the contents of a Data window before exiting. This is something you will commonly want to do. 6 Minitab for Data Management Display I.3: Menu bar. Immediately below the menu bar in the Minitab window is the taskbar . The taskbar consists of various icons that provide a shortcut method for carrying out various operations by clicking on them. These operations can be identiÞed by holding the cursor over each in turn, and it is a good idea to familiarize yourself with these as they can save time. Of particular importance are the Cut Cells, Copy Cells, and Paste Cells icons, which are available when a Data window is active. When the operation associated with an icon is not available, the icon is faded. Minitab is an interactive program. By this we mean that you supply Minitab with input data, or tell it where your input data is, and then Minitab responds instantaneously to any commands you give telling it to do something with that data. You are then ready to give another command. It is also possible to run a collection of Minitab commands in a batch program, i.e., several Minitab commands are executed sequentially before the output is returned to the user. The batch version is useful when there is an extensive number of computations to be carried out. You are referred to Appendix D for more discussion of the batch version. 3 Files Used by Minitab Minitab can accept input from a variety of Þles and write output to a variety of Þles. Each Þle is distinguished by a Þle name and an extension that indicates the type of Þle it is. For example, marks.mtw is the name of a Þle that would be referred to as ‘marks’ (note the single quotes around the Þle name) within Minitab. The extension .mtw indicates that this is a Minitab worksheet. We describe what a worksheet is in Section I.5. This Þle is stored somewhere on the hard drive of a computer as a Þle called marks.mtw. There are other Þles that you will want to access from outside Minitab, perhaps to print them out on a printer. In such a case, you have to give the relevant system print command together with the full path name of the Þle you wish to print. As various implementations of Minitab diﬀer as to where these Þles are stored on the hard drive, you will have to determine this information from your instructor or documentation or systems person. For example, in Windows the full path name of the worksheet Þle marks.mtw could be c : \Program Files\MINITAB 14\Data\marks.mtw or something similar. This path name indicates that the Þle marks.mtw is stored on the C hard drive in the directory called Program Files\MINITAB 14\Data. We will discuss several diﬀerent types of Þles in this manual. It is generally best to name your Þles so that the Þle name reßects its contents. For example, the Þle name marks may refer to a data set composed of student marks in a number of courses. Minitab for Data Management 7 4 Getting Help At times, you may want more information about a command or some other aspect of Minitab than this manual provides, or you may wish to remind yourself of some detail that you have partially forgotten. Minitab contains an online manual that is very convenient. You can access this information directly by clicking on Help in the Menu bar and using the table of contents (via Help ¯ ¯ I Help) or doing a search (via Search I Help) of the manual for a particular ¯ ¯ concept. From the MTB > prompt, you can use the help command for this purpose. Typing help followed by the name of the command of interest and hitting Enter will cause Minitab to produce relevant output. For example, asking for help on the command help itself via the command MTB >help help will give you the table of contents of the online help manual. The help command should be used to Þnd out about session commands. 5 The Worksheet The basic structural component of Minitab is the worksheet. Basically, the worksheet can be thought of as a big rectangular array, or matrix, of cells organized into rows and columns as in the Data window of Display I.2. Each cell holds one piece of data. This piece of data could be a number, i.e., numeric data, or it could be a sequence of characters, such as a word or an arbitrary sequence of letters and numbers, i.e., text data. Data often comes as numbers, such as 1.7, 2.3, . . . , but sometimes it comes in the form of a sequence of characters, such as black, brown, red, etc. Typically, sequences of characters are used as identiÞers in classiÞcations for some variable of interest, e.g., color, gender. A piece of text data can be up to 80 characters in length in Minitab. Minitab also allows for date data, which is data especially formatted to indicate a date, for example, 3/4/97. We will not discuss date data. If possible, try to avoid using text data with Minitab, i.e., make sure all the values of a variable are numbers, as dealing with text data in Minitab is more diﬃcult. For example, denote colors by numbers rather than by names. Still, there will be applications where data comes to you as text data, e.g., in a computer Þle, and it is too extensive to convert to numeric data. So we will discuss how to input text data into a Minitab worksheet, but we recommend that in such cases you convert text data to numeric data, using the methods of Section C.3 in Appendix C, once it has been input. Display I.4 provides an example of a worksheet. Notice that the columns are labeled C1, C2, etc., and the rows are labeled 1, 2, 3, etc. We will refer to the 8 Minitab for Data Management worksheet depicted in Display I.4 as the marks worksheet hereafter and will use it throughout Part I to illustrate various Minitab commands and operations. Data arises from the process of taking measurements of variables in some real-world context. For example, in a population of students, suppose that we are conducting a study of academic performance in a Statistics course. Specifically, suppose that we want to examine the relationship between grades in Statistics, grades in a Calculus course, grades in a Physics course, and gender. So we collect the following information for each student in the study: student number, grade in Statistics, grade in Calculus, grade in Physics, and gender. Therefore, we have Þve variables–student number and the grades in the three subjects are numeric variables, and gender is a text variable. Let us further suppose that there are ten students in the study. Display I.4 gives a possible outcome from collecting the data in such a study. Column C1 contains the student number (note that this is a categorical variable even though it is a number). The student number primarily serves as an identiÞer so that we can check that the data has been entered correctly. This is something you should always do as a Þrst step in your analysis. Columns C2— C4 contain the student grades in their Statistics, Calculus, and Physics courses and column C5 contains the gender data. Notice that a column contains the values collected for a single variable, and a row contains the values of all the variables for a single student. Sometimes, a row is referred to as an observation or case. Observe that the data for this study occupies a 10 × 5 subtable of the full worksheet. All of the other blank entries of the worksheet can be ignored, as they are undeÞned. There will be limitations on the number of columns and rows you can have in your worksheet, and this depends on the particular implementation of Minitab you are using. So if you plan to use Minitab for a large problem, you should check with the system person or further documentation to see what these limitations are. For example, in Minitab Student Version 14 there is a limitation of 10,000 cells. So there can be one variable with 10,000 values in it, or 50 variables with 200 values each, etc. Associated with a worksheet is a table of constants. Typically, these are numbers that you want to use in some arithmetical operation applied to every value in a column. For example, you may have recorded heights of people in inches and want to convert these to heights in centimeters. So you must multiply every height by the value 2.54. The Minitab constants are labeled K1, K2, etc. To continue with the above problem, we might assign the value 2.54 to K1. In Section I.7.4, we show how to make such an assignment, and in Section I.10.1 we show how to multiply every entry in a column by this value. There is an additional structure in Minitab beyond the worksheet called the project. A project can have multiple worksheets associated with it. Also, a project can have associated with it various graphs and records of the commands you have typed and the output obtained while working on the worksheets. Projects, which are discussed in Appendix A, can be saved and retrieved for later work. Minitab for Data Management 9 Display I.4: The marks worksheet. 6 Minitab Commands We will now begin to introduce various Minitab commands to get data into a worksheet, edit a worksheet, perform various operations on the elements of a worksheet, and save and access a saved worksheet. Before we do, however, it is useful to know something about the basic structure of all Minitab commands. Associated with every command is of course its name, as in File I Exit and ¯ ¯ Help. Most commands also take arguments, and these arguments are column ¯ names, constants, and sometimes Þle names. Commands can be accessed by making use of the File, Edit, Data (Manip ¯ ¯ ¯ ¯ in Version 13), Calc, Stat, Graph, and Editor entries in the menu bar. Clicking ¯ ¯ ¯ ¯ any of these brings up a list of commands that you can use to operate on your worksheet. The lists that appear may depend on which window is active, e.g., either a Data window or the Session window. Unless otherwise speciÞed, we will always assume that the Session window is active when discussing menu 10 Minitab for Data Management commands. If a command name in a list is faded, then it is not available. Typically, using a command from the menu bar requires the use of a dialog box or dialog window that opens when you click on a command in the list. These are used to provide the arguments and subcommands to the command and specify where the output is to go. Dialog boxes have various boxes that must be Þlled in to correctly execute a command. Clicking in a box that needs to be Þlled in typically causes a variable list of all items in the active worksheet that can be placed in that box to appear in the left-most box. Double clicking on items in the variable list places them in the box, or, alternatively, you can type them in directly. When you have Þlled in the dialog box and clicked OK, the command is printed in the Session window and executed. Any output is also printed in the Session window. Dialog boxes have a Help button that can be used to learn how to make the entries. For example, suppose that we want to calculate the mean of column C2 in the worksheet marks. Then the command Calc I Column Statistics brings ¯ ¯ up the dialog box shown in Display I.5. Notice that the radio button Sum is Þlled in. Clicking the radio button labeled Mean results in this button being Þlled in and the Sum button becoming empty. Whichever button is Þlled in will result in that statistic being calculated for the relevant columns when we Þnally implement the command by clicking OK. Currently, there are no columns selected, but clicking in the Input variable box brings up a list of possible columns in the display window on the left. The results of these operations are shown in Display I.6. We double click on C2 in the variable list, which places this entry in the Input variable box as shown in Display I.7. Alternatively, we could have simply typed this entry into the box. After clicking the OK button, we obtain the output Mean of C2 = 69.900 in the Session window. Display I.5: Initial view of the dialog box for Column Statistics. Minitab for Data Management 11 Display I.6: View of the dialog box for Column Statistics after selecting Mean and bringing up the variable list. Display I.7: Final view of the dialog box for Column Statistics. Quite often, it is faster and more convenient to simply type your commands directly into the Session window. Sometimes, it is necessary to use the Session window approach. So we now describe the use of commands in the Session window. The basic structure of such a command with n arguments is command name E1 ,E2 ,...,En where Ei is the ith argument. Alternatively, we can type command name E1 E2 ... En if we don’t want to type commas. Conveniently, if the arguments E1 ,E2 ,...,En are consecutive columns in the worksheet, we have the following short-form command name E1 -En which saves even more typing and accordingly decreases our chance of making a typing mistake. If you are going to type a long list of arguments and you don’t 12 Minitab for Data Management want them all on the same line, then you can type the continuation symbol & where you want to break the line and then hit Enter. Minitab responds with the prompt CONT> and you continue to type argument names. The command is executed when you hit Enter after an argument name without a continuation character following it. Many commands can, in addition, be supplied with various subcommands that alter the behavior of the command. The structure for commands with subcommands is command name E1 ... En1 ; subcommand name En1 +1 ... En2 ; .. . subcommand name Enk−1 +1 ... Enk . Notice that when there are subcommands each line ends with a semicolon until the last subcommand, which ends with a period. Also, subcommands may have arguments. When Minitab encounters a line ending in a semicolon it expects a subcommand on the next line and changes the prompt to SUBC > until it encounters a period, whereupon it executes the command. If while typing in one of your subcommands you suddenly decide that you would rather not execute the subcommand–perhaps you realize something was wrong on a previous line–then type abort after the SUBC > prompt and hit Enter. As a further convenience, it is worth noting that you need to only type in the Þrst four letters of any Minitab command or subcommand. For example, to calculate the mean of column C2 in the worksheet marks, we can use the mean command in the Session window, as in MTB > mean c2 and we obtain the same output in the Session window as before. There are additional ways in which you can input commands to Minitab. Instead of typing the commands directly into the Session window, you can also type these directly into the Command Line Editor, which is available via Edit ¯ I Command Line Editor. Multiple commands can then be typed directly into a ¯ box that pops up and executed when the Submit Commands button is clicked. Output appears in the Session window. Also, many commands are available on a toolbar that lies just below the menu bar at the top of the Minitab window. There is a diﬀerent toolbar depending upon which window is active. We give a brief discussion of some of the features available in the toolbar in later sections. 7 Entering Data into a Worksheet There are various methods for entering data into a worksheet. The simplest approach is to use the Data window to enter data directly into the worksheet by Minitab for Data Management 13 clicking your mouse in a cell and then typing the corresponding data entry and hitting Enter. Remember that you can make a Data window active by clicking anywhere in the window or by using Window in the menu bar. If you type any ¯ character that is not a number, Minitab automatically identiÞes the column containing that cell as a text variable and indicates that by appending T to the column name, e.g., C5-T in Display I.4. You do not need to append the T when referring to the column. Also, there is a data direction arrow in the upper left corner of the data window that indicates the direction the cursor moves after you hit Enter. Clicking on it alternates between row-wise and columnwise data entry. Certainly, this is an easy way to enter data when it is suitable. Remember, columns are variables and rows are observations! Also, you can have multiple data windows open and move data between them. Use the command File I New to open a new worksheet. ¯ ¯ 7.1 Importing Data If your data is in an external Þle (not an .mtw Þle), you will need to use File ¯ I Other Files I Import Special Text to get the data into your worksheet. For ¯ ¯ example, suppose in the Þle marks.txt we have the following data recorded, just as it appears. 12389 97658 53546 55542 11223 77788 44567 32156 33456 67945 81 75 77 63 71 87 23 67 81 74 85 72 83 42 82 56 45 72 77 91 78 62 81 55 67 * 35 81 88 92 Each row corresponds to an observation, with the student number being the Þrst entry, followed by the marks in the student’s Statistics, Calculus, and Physics courses. These entries are separated by blanks. Notice the * in the sixth row of this data Þle. In Minitab, a * signiÞes a missing numeric value, i.e., a data value that for some reason is not available. Alternatively, we could have just left this entry blank. A missing text value is simply denoted by a blank. Special attention should be paid to missing values. In general, Minitab statistical analyses ignore any cases (observations) that contain missing data except that the output of the command will tell you how many cases were ignored because of missing data. It is important to pay attention to this information. If your data is riddled with a large number of missing values, your analysis may be based on very few observations–even if you have a large data set! When data in such a Þle is blank-delimited like this it is very easy to read 14 Minitab for Data Management in. After the command File I Other Files I Import Special Text, we see the ¯ ¯ ¯ dialog box shown in Display I.8 less C1—C4 in the Store data in column(s): box. We typed C1-C4 into this window to indicate that we want the data read in to be stored in these columns. Note that it doesn’t matter if we use lower or upper case for the column names, as Minitab is not case sensitive. After clicking OK, we see the dialog box depicted in Display I.9, which we use to indicate from which Þle we want to read the data. Note that if your data is in .txt Þles rather than .dat Þles, you will have to indicate that you want to see these in the Files of type box by selecting Text Files (and then all Þles with this suﬃx in the Data directory are listed) or perhaps All Files. Clicking on marks.txt results in the data being read into the worksheet. Display I.8: Dialog box for importing data from external Þle. Display I.9: Dialog box for selecting Þle from which data is to be read in. Minitab for Data Management 15 Of course, this data set does not contain the text variable denoting the student’s gender. Suppose that the Þle marksgend.txt contains the following data exactly as typed. 12389 81 85 78 m 97658 75 72 62 m 53546 77 83 81 f 55542 63 42 55 m 11223 71 82 67 f 77788 87 56 * f 44567 23 45 35 m 32156 67 72 81 m 33456 81 77 88 f 67945 74 91 92 f As this Þle contains text data in the Þfth column, we must tell Minitab how the data is formatted in the Þle. To access this feature, we click on the Format button in the dialog box shown in Display I.8. This brings up the dialog box shown in Display I.10. To indicate that we will specify the format, we click the radio button User-speciÞed format and Þll the particular format into the box as shown in Display I.11. The format statement says that we are going to read in the data according to the following rule: a numeric variable occupying Þve spaces and with no decimals, followed by a space, a numeric variable occupying two spaces with no decimals, a space, a numeric variable occupying two spaces with no decimals, a space, a numeric variable occupying two spaces with no decimals, a space, and a text variable occupying one space. This rule must be rigorously adhered to or errors will occur. Display I.10: Initial dialog box for formatted input. 16 Minitab for Data Management Display I.11: Dialog box for formatted input with the format Þlled in. So the rules you need to remember, if you use formatted input, are that ak indicates a text variable occupying k spaces, kx indicates k spaces, and fk.l indicates a numeric variable occupying k spaces, of which l are to the right of the decimal point. Note if a data value does not Þll up the full number of spaces allotted to it in the format statement, it must be right justiÞed in its Þeld. Also, if a decimal point is included in the number, this occupies one of the spaces allocated to the variable and similarly for a minus or plus sign. There are many other features to formatted input that we will not discuss here. Use the Help button in the dialog box for information on these features. Finally, clicking on the OK button reads this data into a worksheet as depicted in Display I.4. Typically, we try to avoid the use of formatted input because it is somewhat cumbersome, but sometimes we must use it. In the session environment, the read command is available for inputting data into a worksheet with capabilities similar to what we have described. For example, the commands MTB >read c1-c4 DATA>12389 81 85 78 DATA>97658 75 72 62 DATA>53546 77 83 81 DATA>55542 63 42 55 DATA>11223 71 82 67 DATA>77788 87 56 * DATA>44567 23 45 35 DATA>32156 67 72 81 DATA>33456 81 77 88 DATA>67945 74 91 92 DATA>end 10 rows read. Minitab for Data Management 17 place the Þrst four columns into the marks worksheet. After typing read c1-c4 after the MTB > prompt and hitting Enter, Minitab responds with the DATA> prompt, and we type each row of the worksheet in as shown. To indicate that there is no more data, we type end and hit Enter. Similarly, we can enter text data in this way but can’t combine the two unless we use a format subcommand. We refer the reader to help for more description of how this command works. 7.2 Patterned Data Often, we want to input patterned data into a worksheet. By this we mean that the values of a variable follow some determined rule. We use the command Calc I Make Patterned Data for this. For example, implementing this com¯ ¯ mand with the entries in the dialog box depicted in Display I.12 (for a Simple ¯ Set of Numbers) adds a column C6 to the marks worksheet with the sequence 0, 0.5, 1.0, 1.5, 2.0 repeated twice. For this we entered 0 in the From Þrst value box, a 2 in the To last value box, a .5 in the In steps of box, a 1 in the List each value box, and a 2 in the List the whole sequence box. Basically, we can start a sequence at any number m and successively increment this with any number d > 0 until the next addition would exceed the last value n prescribed, repeat each element l times, and Þnally repeat the whole sequence k times. Display I.12: Dialog box for making patterned data with some entries Þlled in. There is some shorthand associated with patterned data that can be very convenient. For example, typing m : n in a Minitab command is equivalent to typing the values m, m + 1, . . . , n when m < n and m, m − 1, ..., n when m > n, and m when m = n. The expression m : n/d, where d > 0, expands to a list as above but with the increment of d or −d, whichever is relevant, replacing 1 or 18 Minitab for Data Management −1. If m < n, then d is added to m until the next addition would exceed n, and if m > n, then d is subtracted from m until the next subtraction would be lower than n. The expression k(m : n/d) repeats m : n/d for k times, while (m : n/d)l repeats each element in m : n/d for l times. The expression k(m : n/d)l repeats (m : n/d)l for k times. The set command is available in the Session window to input patterned data. For example, suppose we want C6 to contain the ten entries 1, 2, 3, 4, 5, 5, 4, 3, 2, 1. The command MTB >set c6 DATA>1:5 DATA>5:1 DATA>end does this. Also, we can add elements in parentheses. For example, the command MTB >set c6 DATA>(1:2/.5 4:3/.2) DATA>end creates the column with entries 1.0, 1.5, 2.0, 4.0, 3.8, 3.6, 3.4, 3.2, 3.0. The multiplicative factors k and l can also be used in such a context. Obviously, there is a great deal of scope for entering patterned data with set. The general syntax of the set command is set E1 where E1 is a column. 7.3 Printing Data in the Session Window Once we have entered the data into the worksheet, we should always check that we have made the entries correctly. Typically, this means printing out the worksheet and checking the entries. The command Data I Display Data ¯ ¯ (Manip I Display Data in Version 13) will print the data you ask for in the ¯ ¯ Session window. For example, with the worksheet marks the dialog box pictured in Display I.13 causes the contents of this worksheet to be printed when we click on OK. We selected which variables to print by Þrst clicking in the Columns, constants, and matrices to display box, and then double clicking on the variables in the variable list on the left. The print command is available in the Session window and is often convenient to use. The general syntax for the print command is print E1 ... Em where E1 , ..., Em are columns and constants. This prints the contents of these columns and constants in the Session window. Minitab for Data Management 19 Display I.13: Dialog box for printing worksheet in the Session window. 7.4 Assigning Constants To enter constants, we use the Calc I Calculator command and Þll in the dialog ¯ ¯ box appropriately. For example, suppose we want to assign the values k1=.5, k2=.25, and k3=.25 to the constants k1, k2, and k3. These could serve as weights to calculate a weighted average of the marks in the marks worksheet. Then the Calc I Calculator command leads to the dialog box displayed in ¯ ¯ Display I.14, where we have typed k1 into the Store result in variable box and the value .5 into the Expression box. Clicking on OK then makes the assignment. Note that we can assign text values to constants by enclosing the text in double quotes. We will talk about further features of Calculator later in this manual. Similarly, we assign values to k2 and k3. Display I.14: Filled in dialog box for assigning the constant k1 the value .5. 20 Minitab for Data Management The let command is available in the Session window and is quite convenient. The following commands make this assignment and then we check, using the print command, that we have entered the constants correctly. MTB >let k1=.5 MTB >let k2=.25 MTB >let k3=.25 MTB >print k1-k3 K1 0.500000 K2 0.250000 K3 0.250000 Also, we can assign constants text values. For example, MTB >let k4=”result” assigns K4 the value result. Note the use of double quotes. 7.5 Naming Variables and Constants It often makes sense to give the columns and constants names rather than just referring to them as C1, C2, ..., K1, K2, etc. This is especially true when there are many variables and constants, as it would be easy to slip and use the wrong column in an analysis and then wind up making a mistake. To assign a name to a variable, simply go to the blank cell at the top of the column in the worksheet corresponding to the variable and type in an appropriate name. For example, we have used studid, statistics, calculus, physics, and gender for the names of C1, C2, C3, C4, and C5, respectively, and these names appear in Display I.15. Display I.15: Worksheet marks with named variables. Minitab for Data Management 21 In the Session window, the name command is available for naming variables and constants. For example, the commands MTB >name c1 ’studid’ c2 ’stats’ c3 ’calculus’ & CONT>c4 ’physics’ c5 ’gender’ & CONT>k1 ’weight1’ k2 ’weight2’ k3 ’weight3’ give the names studid to C1, stats to C2, calculus to C3, physics to C4, gender to C5, weight1 to K1, weight2 to K2, and weight3 to K3. Notice that we have made use of the continuation character & for convenience in typing in the full input to name. When using the variables as arguments, just enclose the names in single quotes. For example, MTB >print ’studid’ ’calculus’ prints out the contents of these variables in the Session window. Variable and constant names can be at most 31 characters in length, cannot include the characters #, ’, and cannot start with a leading blank or *. Recall that Minitab is not case sensitive, so it does not matter if we use lower or upper case letters when specifying the names. 7.6 Information about a Worksheet We can get information on the data we have entered into the worksheet by using the info command in the Session window. For example, we get the following results based on what we have entered into the marks worksheet so far. MTB >info Column Name Count Missing A C1 studid 10 0 C2 stats 10 0 C3 calculus 10 0 C4 physics 10 1 A C5 gender 10 0 Constant Name Value K1 weight1 0.500000 K2 weight2 0.250000 K3 weight3 0.250000 Notice that the info command tells us how many missing values there are and in what columns they occur and also the values of the constants. This information can also be accessed directly from the Project Manager window via Window I Project Manager ¯ 7.7 Editing a Worksheet It often happens that after data entry we notice that we have made some mistakes or we obtain some additional information, such as more observations. So 22 Minitab for Data Management far, the only way we could change any entries in the worksheet or add some rows is to reenter the whole worksheet! Editing the worksheet is straightforward because we simply change any cells by retyping their entries and hitting the Enter key. We can add rows and columns at the end of the worksheet by simply typing new data entries in the relevant cells. To insert a row before a particular row, simply click on any entry in that row and then the menu command Editor I Insert Rows. Fill in the ¯ ¯ blank entries in the new row. To insert a column before a particular column, simply click on any entry in that column and then the menu command Editor ¯ I Insert Columns. Fill in the blank entries in the new column. To insert a ¯ cell before a particular cell, simply click on any entry in that cell and the menu command Editor I Insert Cells. Fill in the blank entry in the new cell that ¯ ¯ appears in place of the original with all other cells in that column – and only that column–pushed down. If you wish to clear a number of cells in a block, click in the cell at the start of the block, and holding the mouse key down, drag the cursor through the block so that it is highlighted in black. Click on the Cut Cells icon on the Minitab taskbar , and all the entries will be deleted. Cells immediately below the block move up to Þll in the vacated places. A convenient method for clearing all the data entries in a worksheet, with the relevant Data window active, is to use the command Edit I Select All Cells, which causes all the cells to be ¯ icon. Always save the contents of the highlighted, and click ¯on the Cut Cells current worksheet before doing this unless you are absolutely sure you don’t need the data again. We discuss how to save the contents of a worksheet in Section I.8. To copy a block of cells, click in the cell at the start of the block and, holding the mouse key down, drag the cursor through the block so that it is highlighted in black, but, instead of hitting the backspace key, use the command Edit I ¯ Copy Cells or click on the Copy Cells icon on the Minitab taskbar. The block ¯ of cells is now copied to your clipboard. If you not only want to copy a block of cells to your clipboard but remove them from the worksheet, use the command Edit I Cut Cells or the Cut Cells icon on the Minitab taskbar instead. Note ¯ ¯ that any cells below the removed block will move up to replace these entries. To paste the block of cells into the worksheet, click on the cell before which you want the block to appear or that is at the start of the block of cells you wish to replace and issue the command Edit I Paste Cells, or use the Paste Cells icon ¯ ¯ on the Minitab taskbar. A dialog box appears as in Display I.16, where you are prompted as to what you want to do with the copied block of cells. If you feel that a cutting or pasting was in error, you can undo this operation by using Edit I Undo Cut or Edit I Undo Paste, respectively, or use the Undo icon on ¯ ¯ ¯ ¯ the Minitab taskbar. Minitab for Data Management 23 Display I.16: Dialog box that determines how a block of copied cells is used. An alternative approach is available for copying operations using Data I ¯ Copy (or Manip I Copy Columns in Version 13) and Þlling in the dialog box ¯ ¯ ¯ appropriately. We refer the reader to the online manual for more description of these features. One can also delete selected rows from speciÞed columns using Data I Delete ¯ ¯ Rows (or Manip I Delete Rows in Version 13) and Þlling in the dialog box ¯ ¯ appropriately. Notice, however, that whenever we delete a cell, the contents of the cells beneath the deleted one in that column simply move up to Þll the cell. The cell entry does not become missing; rather, cells at the bottom of the column become undeÞned! If you delete an entire row, this is not a problem because the rows below just shift up. For example, if we delete the third row, then in the new worksheet, after the deletion, the third row is now occupied by what was formerly the fourth row. Therefore, you should be careful, when you are not deleting whole rows, to ensure that you get the result you intended. Note that if you should delete all the entries from a column, this variable is still in the worksheet, but it is empty now. If you wish to delete a variable and all its entries, this can be accomplished from Data I Erase Variables (Manip I ¯ ¯ ¯ Erase Variables in Version 13) and Þlling in the dialog box appropriately. This ¯ is a good idea if you have a lot of variables and no longer need some of them. There are various commands in the Session window available for carrying out these editing operations. For example, the restart command in the Session window can be used to remove all entries from a worksheet. The let command allows you to replace individual entries. For example, MTB > let c2(2)=3 assigns the value 3 to the second entry in the column C2. The copy command can be used to copy a block of cells from one place to another. The insert command allows you to insert rows or observations anywhere in the worksheet. The delete command allows you to delete rows. The erase command is available for the deletion of columns or variables from the worksheet. As it is more 24 Minitab for Data Management convenient to edit a worksheet by directly working on the worksheet and using the menu commands, we do not discuss these commands further here. 8 Saving, Retrieving, and Printing Quite often, you will want to save the results of all your work in creating a worksheet. If you exit Minitab before you save your work, you will have to reenter everything. So we recommend that you always save. To use the commands of this section, make sure that the Worksheet window of the worksheet in question is active. Use File I Save Current Worksheet to save the worksheet with its current ¯ ¯ name, or the default name if it doesn’t have one. If you want to provide a name or store the worksheet in a new location, then use File I Save Current Worksheet ¯ ¯ As and Þll in the dialog box depicted in Display I.17 appropriately. The Save in box at the top contains the name of the folder in which the worksheet will be saved once you click on the Save button. Here the folder is called files, and you can navigate to a new folder using the Up One Level button immediately to the right of this box. The next button allows you to create a subfolder within the current folder. The box immediately below contains a list of all Þles of type .mtw in the current folder. You can select the type of Þle to display by clicking on the arrow in the Save as type box, which we have done here, and click on the type of Þle you want to display that appears in the drop-down list. There are several possibilities including saving the worksheet in other formats, such as Excel. Currently, there is one .mtw Þle in the folder files and it is called marks.mtw. If you want to save the worksheet with a particular name, type this name in the File name box and click on the Save button. Display I.17: Dialog box for saving a worksheet. Minitab for Data Management 25 To retrieve a worksheet, use File I Open Worksheet and Þll in the dialog ¯ ¯ box as depicted in Display I.18 appropriately. The various windows and buttons in this dialog box work as described for the File I Save Current Worksheet As ¯ ¯ command, with the exception that we now type the name of the Þle we want to open in the File name box and click on the Open button. To print a worksheet, use the command File I Print Worksheet. The dialog ¯ ¯ box that subsequently pops up allows you to control the output in a number of ways. It may be that you would prefer to write out the contents of a worksheet to an external Þle that can be edited by an editor or perhaps used by some other program. This will not be the case if we save the worksheet as an .mtw Þle as only Minitab can read these. To do this, use the command File I Other Files ¯ ¯ I Export Special Text, Þlling in the dialog box and specifying the destination ¯ Þle when prompted. For example, if we want to save the contents of the marks worksheet, this command results in the dialog box of Display I.19 appearing. We have entered all Þve columns into the Columns to export box and have not speciÞed a format, so the columns will be stored in the Þle with single blanks separating the columns. Clicking the OK button results in the dialog box of Display I.20 appearing. Here, we have typed in the name marks.dat to hold the contents. Note that while we have chosen a .dat type Þle, we also could have chosen a .txt type Þle. Clicking on the Save button results in a Þle marks.dat being created in the folder data with contents as in Display I.21. Display I.18: Dialog box for retrieving a worksheet. 26 Minitab for Data Management Display I.19: Dialog box for saving the contents of a worksheet to an external (non-Minitab) Þle. Display I.20: Dialog box for selecting external Þle to hold contents of a worksheet. Display I.21: Contents of the Þle marks.dat. Minitab for Data Management 27 In the Session window, the commands save and retrieve are available for saving and retrieving a worksheet in the .mtw format and the command write is available for saving a worksheet in an external Þle. We refer the reader to help for a description of how these commands work. 9 Mathematical Operations When carrying out a data analysis, a statistician is often called upon to transform the data in some way. This may involve applying some simple transformation to a variable to create a new variable–e.g., take the natural logarithm of every grade in the marks worksheet–to combining several variables together to form a new variable–e.g., calculate the average grade for each student in the marks worksheet. In this section, we present some of the ways of doing this. 9.1 Arithmetical Operations Simple arithmetic can be carried out on the columns of a worksheet using the arithmetical operations of addition +, subtraction −, multiplication *, division /, and exponentiation ** via the Calc I Calculator command. When columns ¯ ¯ are added together, subtracted one from the other, multiplied together, divided one by the other (make sure there are no zeros in the denominator column), or one column exponentiates another, these operations are always performed component-wise. For example, C1*C2 means that the ith entry of C1 is multiplied by the ith entry of C2, etc. Also, make sure that the columns on which you are going to perform these operations correspond to numeric variables! While these operations have the order of precedence **, */, +−, parentheses ( ) can and should be used to ensure an unambiguous result. For example, suppose in the marks worksheet we want to create a new variable by taking the average of the Statistics and Calculus grades and then subtracting this average from the Physics grade and placing the result in C6. Filling in the dialog box, corresponding to Calc I Calculator, as shown in Display I.22 accomplishes this when ¯ ¯ we click on the OK button. Note that we can either type the relevant expression into the Expression box or use the buttons and double click on the relevant columns. Further, we type the column where we wish to store the results of our calculation in the Store result in variable box. These operations are done on the corresponding entries in each column; corresponding entries in the columns are operated on according to the formula we have speciÞed, and a new column of the same length containing all the outcomes is created. Note that the sixth entry in C6 will be *–missing–because this entry was missing for C4. These kinds of operations can also be carried out directly in the Session window using the let command, and in some ways this is a simpler approach. For example, the session command MTB >let c6=c4-(c2+c3)/2 28 Minitab for Data Management accomplishes this. Display I.22: Dialog box for carrying out mathematical calculations. We can also use these arithmetical operations on the constants K1, K2, etc., and numbers to create new constants or use the constants as scalars in operations with columns. For example, suppose that we want to compute the weighted average of the Statistics, Calculus, and Physics grades, where Statistics gets twice the weight of the other grades. Suppose that we created, as part of the marks worksheet, the constants weight1 = .5, weight2 = .25, and weight3 = .25 in K1, K2, and K3, respectively. So this weighted average is computed via the command MTB >let c7=’weight1’*’stats’+’weight2’*’calculus’& CONT>+’weight3’*’physics’ 9.2 Mathematical Functions Various mathematical functions are available in Minitab. For example, suppose we want to compute the natural logarithm of the Statistics mark for each student and store the result in C8. Using the Calc I Calculator command, with the ¯ ¯ dialog box as in Display I.23, accomplishes this. A complete list of such functions is given in the Functions window when All functions is in the window directly above the list. The same result can be obtained using the session command let and the natural logarithm function loge. For example, MTB >let c8=loge(c2) calculates the natural log of every entry in C2 and places the results in C8. Minitab for Data Management 29 Display I.23: Dialog box for mathematical calculations illustrating the use of the natural logarithm function. 9.3 Comparisons and Logical Operations Minitab also contains the following comparison and logical operators. Comparison operators equal to =, eq not equal to <>, ne less than <, lt greater than >, gt less than or equal to <=, le greater than or equal to >=, ge Logical operators &, and \, or ~, not Notice that there are two choices for these operators; for example, use either the symbol >= or the mnemonic ge. The comparison and logical operators are useful when we have simple questions about the worksheet that would be tedious to answer by inspection. This feature is particularly useful when we are dealing with large data sets. For example, suppose that we want to count the number of times the Statistics grade was greater than the corresponding Calculus grade in the marks worksheet. The command Calc I Calculator gives the dialog box shown in Display I.24, where ¯ ¯ we have put c6 in the Store result in variable box and c2 > c3 in the Expres¯ sion box. Clicking on the OK button results in the ith entry in C6 containing a 1 if the ith entry in C2 is greater than the ith entry in C3, i.e., the comparison is true, and a 0 otherwise. In this case, C6 contains the entries: 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, which the worksheet in Display 1.4 veriÞes as appropriate. If we use Calc I Calculator to calculate the sum of the entries in C6, we will have ¯ ¯ computed the number of times the Statistics grade is greater than the Calculus grade. 30 Minitab for Data Management These operations can also be simply carried out using session commands. For example, MTB >let c6=c2>c3 MTB >let k4=sum(c6) MTB >print k4 K4 4.00000 accomplishes this. The logical operators combine with the comparison operators to allow more complicated questions to be asked. For example, suppose we wanted to calculate the number of students whose Statistics mark was greater than their Calculus mark and less than or equal to their Physics mark. The commands MTB >let c6=c2>c3 and c2<=c4 MTB >let k4=sum(c6) MTB >print k4 K4 1.00000 accomplish this. In this case, both conditions c2>c3 and c2<=c4 have to be true for a 1 to be recorded in C6. Note that the observation with the missing Physics mark is excluded. Of course, we can also implement this using Calc I ¯ Calculator and Þlling in the dialog box appropriately. ¯ Text variables can be used in comparisons where the ordering is alphabetical. For example, MTB >let c6=c5<”m” puts a 1 in C6 whenever the corresponding entry in C5 is alphabetically smaller than m. Display I.24: Dialog box for comparisons. Minitab for Data Management 31 9.4 Column and Row Statistics There are various column statistics that compute a single number from a column by operating on all of the elements in a column. For example, suppose that we want the mean of all the Statistics marks, i.e., the mean of all the entries in C2. The command Calc I Column Statistics produces the dialog box of Display ¯ ¯ I.25, where we have selected Mean as the particular statistic to compute and C2 as the column to use. Clicking OK causes the mean of column C2 to be printed in the Session window. If we want to, we can store this result in a constant or column by making an appropriate entry in the Store result in box. In Display I.25, we see that we have stored the mean of C2 in the constant K1. We also see from the dialog box that there are a number of possible statistics that can be computed. We can also compute statistics row-wise. One diﬀerence with column statistics is that these must be stored. For example, suppose we want to compute the average of the Statistics, Calculus, and Physics marks for each individual. The command Calc I Row Statistics produces the dialog box shown in Display ¯ ¯ I.26, where we have placed C2, C3, and C4 into the Input variables box and C6 into the Store result in box. Display I.25: Dialog box for computing column statistics. 32 Minitab for Data Management Display I.26: Dialog box for computing row statistics. It is also possible to compute column statistics using session commands. For example, MTB >mean(c2) MEAN = 69.900 computes the mean of c2. If we want to save the value for subsequent use, then the command MTB >let k1=mean(c2) does this. The general syntax for column statistic commands is column statistic name(E1 ) where the operation is carried out on the entries in column E1 , and output is written to the screen unless it is assigned to a constant using the let command. See Appendix B.2 for a list of all the column statistics available. Also, for most column statistics there are versions that compute row statistics, and these are obtained by placing r in front of the column statistic name. For example, MTB >rmean(c2 c3 c4 c6) computes the mean of the corresponding entries in C2, C3, and C4 and places the result in C6. The general syntax for row statistic commands is row statistic name(E1 . . . Em Em+1 ) where the operations are carried out on the rows in columns E1 , . . . , Em , and the output is placed in column Em+1 . See Appendix B.3 for a list of all the row statistics available. Minitab for Data Management 33 9.5 Sorting Data It often arises that we want to sort a column so that its values ascend from smallest to largest or descend from largest to smallest. Note that ordering here could refer to numerical order or alphabetical order, so we also consider ordering text columns. Also, we may want to sort all the rows contained in some subset of the columns in the worksheet by a particular column. The Data I Sort ¯ ¯ command (Manip I Sort in Version 13) allows us to carry out these tasks. ¯ ¯ For example, suppose that we want to sort the entries in C2 in the marks worksheet–the Statistics grades–from smallest to largest and place the sorted values in C6. Then the Data I Sort command brings up the dialog box shown ¯ ¯ in Display I.27, where the Sort column(s) box contains the column C2 to be sorted, the Store sorted data In box contains C6, where we will store the sorted column, and C2 is also placed in the By column box. This command results in C6 containing 23, 63, 67, 71, 74, 75, 77, 81, 81, and 87. If we had clicked the Descending box, the order of appearance of these values in C6 would have been reversed. If we had placed another column in the By column box, say C5, then C5 would have been sorted with the values in C2 carried along and placed in C6, i.e., the values in C2 would be sorted by the values in C5. So all the Statistics marks of females, in the order they appear in C2 will appear in C6 Þrst and then the Statistics marks of males. So, replacing C2 by C5 in this box would result in the values in C6 becoming 77, 71, 87, 81, 74, 81, 75, 63, 23, and 67. If we Þll in the next By column box with another column, say C3, then the values in C2 are sorted Þrst by gender and then within gender by the values in C3. Display I.27: Dialog box for sorting. The general syntax of the corresponding session command sort is sort E1 E2 . . .Em Em+1 . . .E2m 34 Minitab for Data Management where E1 is the column to be sorted, and E2 , ..., Em are carried along with the results placed in columns Em+1 , ..., E2m . Note that this sort can also be accomplished using the by subcommand, where the general syntax is sort E1 E2 . . .Em Em+1 . . .E2m ; by E2m+1 . . .En . where now we sort by columns E2m+1 , ..., En , sorting Þrst by E2m+1, then E2m+2 , etc., carrying along E1 , ..., Em and placing the result in Em+1 , ..., E2m . The descending subcommand can also be used to indicate which sorting variables we want to use in descending order, rather than ascending order. 9.6 Computing Ranks Sometimes, we want to compute the ranks of the numeric values in a column. The rank ri of the ith value in a column is a value that reßects its relative size in the column. For example, if the ith value is the smallest value, then ri = 1, if it is the third smallest, then ri = 3, etc. If values are the same, i.e., tied, then each value receives the average rank. To calculate the ranks of the entries in a column, we use the Data I Rank command (Manip I Rank in Version 13). ¯ ¯ ¯ ¯ For example, suppose that C6 contains the values 6, 4 , 3, 2, 3, and 1. Then the Data I Rank command brings up the dialog box in Display I.28, which is ¯ ¯ Þlled in so that the ranks of the entries in C6 are placed in C7. In this case, the ranks are 6.0, 5.0, 3.5, 2.0, 3.5, and 1.0, respectively. Display I.28: Dialog box for computing ranks. The syntax of the corresponding session command rank is rank E1 E2 where E1 is the column whose ranks we want to compute and E2 is the column that will hold the computed ranks. Minitab for Data Management 35 10 Exercises 1. Start Minitab and set it up so that you can type commands in the Session window and edit your output. Print the contents of the Session window. 2. Use the online manual to read and print the entry on how you can get help in Minitab. 3. Invoke the Calc I Calculator command, place k1 in the Store result in ¯ ¯ variable box, read Help in the dialog box, and from this Þgure out how to compute the expression 203*(10345-678)/3.6. Finally, invoke the session command print k1 and print the Session window. 4. The following data give the High and Low trading prices in dollars for various stocks on a given day on an exchange. Create a worksheet, giving the columns the same variable names. Print the worksheet to check that you have successfully entered it. Save the worksheet giving it the name stocks. Stock High Low ACR 7.95 7.80 MGI 4.75 4.00 BLD 112.25 109.75 CFP 9.65 9.25 MAL 8.25 8.10 CM 45.90 45.30 AZC 1.99 1.93 CMW 20.00 19.00 AMZ 2.70 2.30 GAC 52.00 50.25 5. Generate a column C1 containing all the values starting at 1 to 10 in increments of .1. Generate a column C2 containing the sequence 1:10 repeated ten times. Save these two columns in a Þle columns.txt and print this Þle. 6. Create a .txt Þle containing the data in Exercise 4. Using a format statement input, these data into a worksheet. Print the contents of your session. 7. Retrieve the worksheet stocks created in Exercise 4. Change the Low value in the stock MGI to 3.95. Calculate the average of the High and Low prices for all the stocks, and save this in a column called average. Calculate the average of all the High prices, and save this in a constant called avhi. Similarly, do this for all the Low prices, and save this in a constant called avlo. Save the worksheet using the same name. Write all the columns out to a Þle called stocks.dat. Print the Þle stocks.dat on your system printer. 36 Minitab for Data Management 8. Retrieve the worksheet created in Exercise 7. Using Minitab commands, calculate the number of stocks in the worksheet whose average is greater than $5.00 and less than or equal to $45.00. 9. Using the worksheet created in Exercise 7, insert the following stocks at the beginning of the worksheet. Stock CLV SIL AC High 1.85 34.00 14.45 Low 1.78 34.00 14.05 Delete the variable average. Print and save the worksheet. 10. (a) Using patterned data input, place the values from −10 to 10 in increments of .1 in C1. (b) For each of the values in C1, calculate the value of the quadratic polynomial 2x2 + 4x − 3 (i.e., substitute the value in each entry in C1 into this expression) and place these values in C2. (c) Using Minitab commands and the values in C1 and C2, estimate the point in the range from −10 to 10 where this polynomial takes its smallest value and what this smallest value is. (Hint: Compute the ranks of the values in C2.) (d) Using Minitab commands and the values in C1 and C2, estimate the points in the range from −10 to 10 where this polynomial is closest to 0. 11. (a) Using patterned data input, place values in the range from 0 to 5 using an increment of .01 in C1. (b) Calculate the value of 1 − e−x for each value in C1 and place the result in C2. (c) Using Minitab commands, Þnd the largest value in C1 where the corresponding entry in C2 is less than or equal to .5. Note that e−x corresponds to the exponentiate command (see Appendix B.1) evaluated at −x. 12. Using patterned data input, place values in the range from −4 to 4 using an increment of .01 in C1. Calculate the value of 2 1 √ e−x /2 2π for each value in C1, and place the result in C2, where π = 3.1415927. Using parsums (see Appendix B.1), calculate the partial sums for C2, and place the result in C3. Multiply C3 times .01. Find the largest value in C1 such that the corresponding entry in C3 is less than or equal to .25. Part II Minitab for Data Analysis 37 Chapter 1 Looking at Data–Distributions New Minitab commands discussed in this chapter Calc I Probability Distributions I Normal ¯ ¯ ¯ Data I Code ¯ ¯ File I Open Graph ¯ ¯ File I Save Graph As ¯ ¯ Graph I Boxplot ¯ ¯ Graph I Chart ¯ ¯ Graph I Dotplot ¯ ¯ Graph I Histogram ¯ ¯ Graph I Pie Chart ¯ ¯ Graph I Probability Plot ¯ ¯ Graph I Stem-and-Leaf ¯ ¯ Graph I Time Series Plot ¯ ¯ Stat I Basic Statistics I Display Descriptive Statistics ¯ ¯ ¯ Stat I Basic Statistics I Store Descriptive Statistics ¯ ¯ ¯ Stat I Tables I Tally ¯ ¯ ¯ This chapter of IPS is concerned with the various ways of presenting and summarizing a data set. By presenting data, we mean convenient and informative methods of conveying the information contained in a data set. There are two basic methods for presenting data, namely graphically and through tabulations. Still, it can be hard to summarize exactly what these presentations are saying about the data. So the chapter also introduces various summary statistics that are commonly used to convey meaningful information in a concise way. All of these topics can involve much tedious, error-prone calculation, if we were to insist on doing them by hand. An important point is that you should 39 40 Chapter 1 almost never rely on hand calculation in carrying out a data analysis. Not only are there many far more important things for you to be thinking about, as the text discusses, but you are also likely to make an error. On the other hand, never blindly trust the computer! Check your results and make sure that they make sense in light of the application. For this, a few simple hand calculations can prove valuable. In working through the problems in IPS, you should try to use Minitab as much as possible, as this will increase your skill with the package and inevitably make your data analyses easier and more eﬀective. 1.1 Tabulating and Summarizing Data If a variable is categorical, we construct a table using the values of the variable and record the frequency (count) of each value in the data and perhaps the relative frequency (proportion) of each value in the data as well. These relative frequencies then serve as a convenient summarization of the data. If the variable is quantitative, we typically group the data in some way, i.e., divide the range of the data into nonoverlapping intervals and record the frequency and proportion of values in each interval. Grouping is accomplished using the Data I Code (Manip I Code in Version 13) command discussed in ¯ ¯ ¯ ¯ Appendix C.1. If the values of a variable are ordered, we can record the cumulative distribution, namely, the proportion of values less than or equal to each value. Quantitative variables are always ordered but sometimes categorical variables are as well, e.g., when a categorical variable arises from grouping a quantitative variable. Often, it is convenient with quantitative variables to record the empirical distribution function, which for data values x1 , . . . , xn is given by F̂ (x) = # of xi ≤ x n at a value x, i.e., F̂ (x) is the proportion of data values less than or equal to x. We can summarize such a presentation via the calculation of a few quantities, such as the Þrst quartile, the median, and the third quartile, or present the mean and the standard deviation. We introduce some new commands to carry out the necessary computations using the data shown in Table 1.1.1. This is data collected by A.A. Michelson and Simon Newcomb in 1882 concerning the speed of light. We will refer to these hereafter as Newcomb’s data and place them in the column C1 with the name time in the worksheet called newcomb. Looking at Data–Distributions 28 22 36 26 28 28 26 24 32 30 27 24 33 21 36 32 31 25 24 25 28 36 27 32 34 30 25 26 26 25 41 −44 23 21 30 33 29 27 29 28 22 26 27 16 31 29 36 32 28 40 19 37 23 32 29 −2 24 25 27 24 16 29 20 28 27 39 23 Table 1.1.1: Newcomb’s data. 1.1.1 Tallying Data The Stat I Tables I Tally command tabulates data. Consider Newcomb’s mea¯ ¯ ¯ surements in Table 1.1.1. These data range from −44 to 40 (use minimum and maximum in Calc I Calculator to calculate these values). Suppose we decide to ¯ ¯ group these into the intervals (−50, 0], (0, 20], (20, 25], (25, 30], (30, 35], (35, 50]. Next, we want to record the frequencies, relative frequencies, cumulative frequencies, and cumulative distribution of this grouped variable. First, we used the Data I Code I Numeric to Numeric command (Manip I Code I Numeric ¯ ¯ ¯ ¯ ¯ ¯ to Numeric in version 13), as described in Appendix C.1, to recode the data so that every value in (−50, 0] is given the value 1, every value in (0, 20] is given the value 2, etc., and these values are placed in C2. The dialog box for doing this is shown in Display 1.1.1. Display 1.1.1: Dialog box for recoding Newcomb’s data. Next, we used the Stat I Tables I Tally command, with the dialog box ¯ ¯ ¯ shown in Display 1.1.2, to produce the output 42 Chapter 1 C2 Count Percent CumCnt CumPct 1 2 3.03 2 3.03 2 4 6.06 6 9.09 3 17 25.76 23 34.85 4 26 39.39 49 74.24 5 10 15.15 59 89.39 6 7 10.61 66 100.00 N= 66 in the Session window. Display 1.1.2: Dialog box for tallying the variable C2 in the newcomb worksheet. We can also use the Stat I Tables I Tally command to compute the em¯ ¯ ¯ pirical distribution function of C1 in the newcomb worksheet. First, we must sort the values in C1, from smallest to largest, using the Data I Sort command ¯ ¯ (Manip I Sort in Version 13) described in Section I.10.6, and then we apply ¯ ¯ the Stat I Tables I Tally command to this sorted variable. Note that if values ¯ ¯ ¯ are repeated, then the value of the empirical cdf at this point is the largest proportion. The general syntax of the corresponding session command tally is tally E1 . . .Em where E1 , ..., Em are columns of categorical variables, and the command is applied to each column. If no subcommands are given, then only frequencies are computed, while the subcommands percents computes relative frequencies, cumcnts computes the cumulative frequency function, and cumpcts computes the cumulative distribution of C2. Any of the subcommands can be dropped. For example, the commands MTB >sort c1 c3 MTB >tally c3; SUBC>cumpcnts; SUBC>store c4 c5. Looking at Data–Distributions 43 Þrst use the sort command to sort the data in C1 from smallest to largest and place the results in C3. The cumulative distribution is computed for the values in C3 with the unique values in C3 stored in C4 and the cumulative distribution at each of the unique values stored in C5 via the store subcommand to tally. 1.1.2 Describing Data The Stat I Basic Statistics I Display Descriptive Statistics command is used ¯ ¯ with ¯quantitative variables to present a numerical summary of the variable values. These values are in a sense a summarization of the empirical distribution of the variable. For example, in the newcomb worksheet the dialog box shown in Display 1.1.3 leads to the output Variable N N* Mean SE Mean StDev Minimum Q1 Median time 66 0 26.21 1.32 10.75 -44.00 24.00 27.00 Q3 Maximum 31.00 40.00 in the Session window. This provides the count N, the number of missing values N*, the mean, standard error of the mean, standard deviation, minimum, Þrst quartile Q1, median, third quartile Q3, and maximum of the variable C1. If we want such a summary of a variable by the values of another variable, we place these variables in the By variables box (in Version 13 we also need to check the By box). For example, we might want such a summary for each of the groups we created in Section 1.1.1, and so we would place C2 in this box. Note that a number of summary statistics can also be computed using the Calc I Column ¯ ¯ Statistics command discussed in Section I.10.3. Display 1.1.3: Dialog box for computing basic descriptive statistics of a quantitative variable. If we wish to compute some basic statistics and store these values for later use, then the Stat I Basic Statistics I Store Descriptive Statistics command ¯ ¯ ¯ 44 Chapter 1 is available for this. For example, with the newcomb worksheet this command leads to the dialog box shown in Display 1.1.4. Clicking on the Statistics button results in the dialog box of Display 1.1.5, where we have checked First quartile, Median, Third quartile, Interquartile range, and N nonmissing as the statistics ¯ we want to compute. The result of these choices is that the next available variables in the worksheet contain these values. So in this case, the values of C3—C7 are as depicted in Display 1.1.6. Note that these variables are now named as well. Note that many more statistics are available using this command. Display 1.1.4: Dialog box for computing and storing various descriptive statistics. Display 1.1.5: Dialog box for choosing the descriptive statistics to compute and store. Display 1.1.6: Values obtained for descriptive statistics using dialog boxes in Displays 1.1.4 and 1.1.5. The general syntax of the Session command describe, corresponding to Stat ¯ I Basic Statistics I Display Descriptive Statistics, is ¯ ¯ describe E1 . . .Em Looking at Data–Distributions 45 where E1 , ..., Em are columns of quantitative variables and the command is applied to each column. A by subcommand can also be used. The stats command is available in the Session window if we want to store the values of statistics. We refer the reader to help for a description of this command. 1.2 Plotting Data One of the most informative ways of presenting data is via a plot. There are many diﬀerent types of plots within Minitab, and which one to use depends on the type of variable you have and what you are trying to learn. In this section, we describe how to use the plotting features in Minitab. There are, however, many features of plotting that we will not describe. For example, there are many graphical editing capabilities that allow you to add features, such as titles or legends. We refer the reader to Help for more details on these features. A plot in Minitab is made in a Graph window. You can make multiple plots and retain each Graph window until you want to delete it simply by clicking the × symbol in the upper right-hand corner. You make any particular Graph window active by clicking in it or by using the Window command. A plot can ¯ be saved in an external Þle in a variety of formats, such as Minitab graph .mgf, bitmap .bmp JPEG .jpg, etc., using the File I Save Graph As command. If ¯ ¯ a graph has been saved in the .mgf format, it can be reopened using the File I ¯ Open Graph command. ¯ Plotting diﬀers somewhat between Versions 13 and 14, so we discuss each version separately where this is deemed appropriate. 1.2.1 Stem-and-Leaf Plots Stem-and-leaf plots are produced by the Graph I Stem-and-Leaf command. ¯ ¯ These plots are also referred to as stemplots, as in IPS. For example, using this command with the newcomb worksheet and the dialog box in Display 1.2.1 produces the following output in the Session window. Stem-and-leaf of time N = 66 Leaf Unit = 1.0 1 -4 4 1 -3 1 -2 1 -1 2 -0 2 2 0 5 1 669 (41) 2 01122333444445555566666777777888888899999 20 3 0001122222334666679 1 4 0 46 Chapter 1 It is a stem-and-leaf plot of the values in time with an increment of 10. Notice that we have placed 10 in the Increment box in the dialog box shown in Display 1.2.1 to reßect the fact we want the stem to be the units of 10. Display 1.2.1: Dialog box for droducing a stem-and-leaf plot. The Þrst column gives the depths for a given stem, i.e., the number of observations on that line and below it or above it, depending on whether or not the observation is below or above the median. The row containing the median is enclosed in parentheses ( ), and the depth is only the observations on that line. If the number of observations is even and the median is the average of values on diﬀerent rows, then parentheses do not appear. The second column gives the stems, as determined by what is placed in Increment, and the remaining columns give the ordered leaves, where each digit represents one observation. The Leaf Unit determines where the decimal place goes after each leaf. So in this example, the Þrst observation is −44.0, while it would be −4.4 if the Leaf Unit were .1. Multiple stem-and-leaf plots can be carried out for a number of columns simultaneously and also for a single variable by the values of another variable. 1.2.2 Histograms A histogram is a plot where the data are grouped into intervals, and over each such interval a bar is drawn of height equal to the frequency (count) of data values in that interval (frequency histogram) or of height equal to the relative frequency (proportion) of data values in that interval (relative frequency histogram) or of height equal to the density of points in that interval, i.e., the proportion of points in the interval divided by the length of the interval (density histogram). We recommend plotting density histograms. The Graph I ¯ Histogram command is used to obtain these plots. Since the implementation ¯ Looking at Data–Distributions 47 of these plots is somewhat diﬀerent in Versions 13 and 14, we describe this for each version. An important consideration when plotting multiple histograms for comparison purposes is to ensure that all the histograms have the same x and y scales so that the plots are visually comparable. The Graph I Histogram command ¯ ¯ contains options that impose this restriction. Histograms in Version 14 Using Graph I Histogram with the newcomb worksheet, produces the dialog ¯ ¯ box shown in Display 1.2.2. Selecting Simple and clicking on OK leads to the dialog box in Display 1.2.3. We have placed the variable time in the Graph variables box to indicate we want a histogram of this variable. To select a density histogram we click on the Scale button, which brings up the dialog box of Display 1.2.4, and then click on the Y-scale type to obtain the dialog box in Display 1.2.5, in which we have Þlled in the Density radio button. Clicking on OK in this dialog box and in the dialog box of Display 1.2.3 produces the density histogram of Display 1.2.6. Note that we can produce multiple histograms by clicking on the Multiple Graphs button in the dialog box of Display 1.2.3. Display 1.2.2: Dialog box for selecting type of histogram. Display 1.2.3: Dialog box for creating a histogram of the time variable in the newcomb worksheet. 48 Chapter 1 Display 1.2.4: Dialog box for specifying characteristics of the histogram plotted. Display 1.2.5: Dialog box for selecting frequency, relative frequency or density histogram. Display 1.2.6: Density histogram of the time variable in the newcomb worksheet. Looking at Data–Distributions 49 We can also edit a graph to modify its appearance by double-clicking on various components of the plot in the graph window. For example, the plot in Display 1.2.6 is based on a default algorithm in Minitab to divide up the range of the data into bins and plot each bar over the mid-point of each bin. Sometimes we prefer to select the bins ourselves and moreover specify cutpoints (the endpoints of each bin) rather than midpoints and have these cutpoints along the x-axis. To do this, we double click on a value on the x-axis which brings up the dialog box in Display 1.2.7, where we have clicked on the Binning tab. Here, we have selected the radio button Cutpoints in the Interval type box and have Þlled in the cutpoints −45, −30, −15, 0, 15, 30, 45 in the Midpoint/Cutpoint positions box. Clicking on OK produces the plot shown in Display 1.2.8. Display 1.2.7: Dialog box for editing the bins for the histogram. Display 1.2.8: Density histogram of the time variable in the newcomb worksheet with speciÞed cutpoints. Histograms in Version 13 In Version 13, using Graph I Histogram with the newcomb worksheet produces ¯ ¯ the dialog box shown in Display 1.2.9. We have placed the variable time in the Þrst X box to indicate we want a histogram of this variable. We can produce 50 Chapter 1 multiple histograms by placing more variables in the X boxes. To select the type of histogram to plot, we next click on the Options button, which produces the di¯ alog box of Display 1.2.10. Here, we have selected a density histogram and have speciÞed the intervals to use for grouping the data by specifying the cutpoints −45, −30, −15, 0, 15, 30, 45, which prescribe the intervals [−45, −30), [−30, −15), etc., for the grouping. Alternatively, we could have speciÞed the midpoints of the grouping intervals. The advantage with cutpoints is that subintervals of unequal lengths can be speciÞed. Clicking on the OK buttons in these boxes ¯ produces a histogram similar to that shown in Display 1.2.8. As can be seen from the dialog box of Display 1.2.9, there are a variety of methods for controlling the appearance of the histogram produced, and we refer the reader to the Help button for a description of these. Display 1.2.9: Dialog box for creating a histogram of the time variable in the newcomb worksheet (Version 13). Display 1.2.10: Dialog box for selecting the type of histogram to plot (Version 13). An important consideration when plotting multiple histograms is to ensure that all the histograms have the same x and y scales so that the plots are visually comparable. This can be accomplished from the dialog box shown in Display 1.2.9 by Frame I Multiple Graphs and then selecting Same X and same Y. ¯ ¯ ¯ Looking at Data–Distributions 51 Session Commands for Histograms The session command histogram is also available. This has the general syntax histogram E1 . . .Em where E1 , ..., Em correspond to columns. For example, the commands MTB >histogram c1; SUBC>cutpoints -45 -30 -15 0 15 30 45; SUBC>density. produce the histogram in Display 1.2.8 using the cutpoints and density subcommands. There are also subcommands midpoints and nintervals, which specify the number of subintervals, and frequency or percent, which respectively ensure that the heights of the bar lines equal the frequency and relative frequency of the data values in the interval. Also, the cumulative subcommand is available so that the bars represent all the values less than or equal to the endpoint of an interval. The subcommand same ensures that multiple histograms all have the same scale. 1.2.3 Boxplots Boxplots are useful summaries of a quantitative variable and are obtained using the Graph I Boxplot command. Boxplots are used to provide a graphical notion ¯ ¯ of the location of the data and its scatter in a concise and evocative way. A boxplot is presented in Display 1.2.13 for the variable time in the newcomb worksheet. The line in the center of the box is the median. The line below the median is the Þrst quartile, also called the lower hinge, and the line above is third quartile, also called the upper hinge. The diﬀerence between the third and Þrst quartile, is called the interquartile range, or IQR. The vertical lines from the hinges are called whiskers, and these run from the hinges to the adjacent values. The adjacent values are given by the greatest value less than or equal to the upper limit (the third quartile plus 1.5 times the IQR) and by the least value greater than or equal to the lower limit (the Þrst quartile minus 1.5 times the IQR). The upper and lower limits are also referred to as the inner fences. The outer fences are deÞned by replacing the multiple 1.5 in the deÞnition of the inner fences by 3.0. Values beyond the outer fences are plotted with a * and are called outliers. As with the plotting of histograms, multiple boxplots can be plotted for comparison purposes, and again, it is important to make sure that they all have the same scale. Boxplots in Version 14 In Version 14, the Graph I Boxplot command produces the dialog box shown ¯ ¯ in Display 1.2.11. Selecting Simple and clicking on OK produces the dialog box shown in Display 1.2.12, where we have Þlled in the time variable in the Graph variable box. Clicking on OK produces the boxplot shown in Display 1.2.13. There is a corresponding session command called boxplot. We refer the reader to help for more discussion of this command. 52 Chapter 1 Display 1.2.11: Dialog box for selecting type of boxplot. Display 1.2.12: Dialog box for producing a boxplot of the time variable in the newcomb worksheet. Display 1.2.13: Boxplot of the time variable in the newcomb worksheet. Boxplots in Version 13 In Version 13, the Graph I Boxplot command produces the dialog box shown ¯ ¯ in Display 1.2.14, where we have Þlled in the time variable in the Graph 1, Y box. Clicking on OK produces a plot similar to that shown in Display 1.2.13. Looking at Data–Distributions 53 Display 1.2.14: Dialog box for producing a boxplot of the time variable in the newcomb worksheet (Version 13). Session Commands for Boxplots There is a corresponding session command called boxplot. We refer the reader to help for more discussion of this command. 1.2.4 Bar Charts Bar charts are used to plot the distributions of categorical variables. Bar Charts in Version 14 Consider the categorical variable C2 (created in Section 1.1.1) in the newcomb worksheet. The command Graph I Bar Chart brings up the dialog box shown ¯ ¯ in Display 1.2.15. Selecting Simple and clicking on OK brings up the dialog box shown in Display 1.2.16, where we have Þlled in the Categorical variables box with C2. Now since we want a graph of the distribution of C2, we next clicked on the Bar Chart Options button to bring up the dialog box of Display 1.2.17, where we have checked the Show Y as a Percent box. Clicking on OK in this and the dialog box of Display 1.2.16 produces the bar chart of Display 1.2.18. Display 1.2.15: Dialog box for selecting type of bar chart. 54 Chapter 1 Display 1.2.16: Dialog box for selecting variable to plot in a bar chart. Display 1.2.17: Dialog box to use to specify that you want the distribution to be plotted (and not just the counts). Display 1.2.18: Bar chart of the variable C2 in the newcomb worksheet. Looking at Data–Distributions 55 Bar Charts in Version 13 Consider the variable C2 (created in Section 1.1.1) in the newcomb worksheet. In Version 13, we use the Graph I Chart command. To get a bar chart of the ¯ ¯ distribution we must Þrst tally the variable to determine the relative frequencies for each of the categories. Then place the values of the variable in one column, say C3, and the percentages in the corresponding entries of the second column, say C4. We can then do a bar chart of C3 using the Sum function applied to the entries in C4. For example, the dialog box shown in Display 1.2.19 plots a bar chart of the distribution of the variable C2 in the newcomb worksheet similar to that shown in Display 1.2.18. Display 1.2.19: Dialog box for plotting bar charts (Version 13). Session Commands for Bar Charts The corresponding session command is chart E1 which produces a bar chart for the values in column E1 . The subcommand percent ensures that the distribution is plotted. 1.2.5 Pie Charts A pie chart is a disk divided up into wedges where each wedge corresponds to a unique value of a variable, and the area of the wedge is proportional to the relative frequency of the value with which it corresponds. Pie charts can be obtained via Graph I Pie Chart, and there are various features available in the ¯ ¯ dialog box that can be used to enhance these plots. Pie charts are a common method for plotting categorical variables. 56 Chapter 1 1.2.6 Time Series Plots Often, data are collected sequentially in time. In such a context, it is instructive to plot the values of quantitative variables against time in a time series plot. For this we use the Graph I Time Series Plot command. If we suppose that the ¯ ¯ data values in time of the newcomb worksheet were obtained in the order they are listed (down the Þrst column, then down the second column, etc.), then we can use this command to obtain the a time series plot. Time Series Plots in Version 14 The Graph I Time Series Plot command brings up the dialog box shown in ¯ ¯ Display 1.2.20. Clicking on Simple and OK brings up the dialog box shown in Display 1.2.21 where we have asked for a time series plot of the variable time. This produces the time plot shown in Display 1.2.22. There are various options available to modify the presentation of this graph. Display 1.2.20: First dialog box for for producing a time series plot. Display 1.2.21: Dialog box for a time series plot of the variable time from the newcomb worksheet. Looking at Data–Distributions 57 Time Series Plot of time 40 30 20 time 10 0 -10 -20 -30 -40 -50 1 7 14 21 28 35 Index 42 49 56 63 Display 1.2.22: Time series plot of the variable time from the newcomb worksheet. Time Series Plots in Version 13 In Version 13, the Graph I Time Series Plot command brings up the dialog box ¯ ¯ shown in Display 1.2.23. Notice that in the Data display box we have speciÞed ¯ that the graph should plot a symbol for each point and that the symbols plotted should connect via lines. For example, if we had left out connect, only the points would have been plotted. The lines help to visualize the form of the graph. The symbol plotted is a solid circle but other choices could have been made using the Edit Attributes button. Also, for the Time Scale we have chosen Index, which ¯ is just the order in which the observations are listed. If these observations were made at periodic time intervals, there are other possible choices that could be more meaningful. This dialog box produces a plot similar to that shown in Display 1.2.22. Display 1.2.23: Dialog box for a time series plot of the variable time from the newcomb worksheet. 58 Chapter 1 Session Commands for Time Series Plot There is also a corresponding session command tsplot. We refer the reader to help for more discussion of this. 1.3 The Normal Distribution It is important in statistics to be able to do computations with the normal distribution. The equation of the density curve for the normal distribution with mean µ and standard deviation σ is given by 1 z−µ 2 1 √ e− 2 ( σ ) 2πσ where z is a number. We refer to this as the N (µ, σ) density curve. Also of interest is the area under the density curve from −∞ to a number x, i.e., the area between the graph of the N (µ, σ) density curve and the interval (−∞, x]. As noted in IPS, this is a value between 0 and 1. Sometimes, we specify a value p between 0 and 1 and then want to Þnd the point xp , such that p of the area under the N (µ, σ) density curve lies over (−∞, xp ]. The point xp is called the pth percentile of the N (µ, σ) density curve. 1.3.1 Calculating the Density Suppose that we want to evaluate the N (µ, σ) probability density function at a value x. For this, we use the Calc I Probability Distributions I Normal ¯ ¯ ¯ command. For example, the dialog box in Display 1.3.1 calculates the N (10, 1) density curve at the value x = 11.0. Display 1.3.1: Dialog box for normal probability calculations. After clicking on the OK button, the output Normal with mean = 10.0000 and standard deviation = 1.00000 x f( x ) 11.0000 0.241971 Looking at Data–Distributions 59 is printed in the Session window, which gives the value as 0.241971. Sometimes, we will want to evaluate the density curve at every value in a column of values, e.g., when we are plotting this curve. For this, we simply click on the radio button Input column and type the relevant column in the associated box. The general syntax of the corresponding session command pdf with the normal subcommand is pdf E1 . . .Em into Em+1 . . .E2m ; normal mu = V1 sigma = V2 . where E1 , ..., Em are columns or constants containing numbers and Em+1 , ..., E2m are the columns or constants that store the values of the N (µ, σ) density curve at these numbers and V1 = µ and V2 = σ. If no storage is speciÞed, then the values are printed. For example, if we want to compute the N (−.5, 1.2) density curve at every value between −3 and 3 in increments of .01, the commands MTB >set c1 DATA>-3:3/.01 DATA>end MTB >pdf c1 c2; SUBC>normal mu=-.5 sigma=1.2. put the values between −3 and 3 in increments of .01 in C1 using the set command. The pdf command with the normal subcommand calculates the N(−.5, 1.2) density curve at each of these values and puts the outcomes in the corresponding entries of C2. If we plot C2 against C1, we will have a plot of the density curve of this distribution. For this, we use the scatterplot facilities in Minitab as discussed in II.3. Note that with the normal subcommand we must also specify the mean and the standard deviation via mu and sigma. 1.3.2 Calculating the Distribution Function Suppose that we want to evaluate the area under N (µ, σ) density curve over the interval (−∞, x]. This is the value of the cumulative distribution function of the N (µ, σ) distribution at the value x. For this, we use the Calc I Probability ¯ Distributions I Normal as well, but in this case, in the dialog box of Display ¯ ¯ 1.3.1, we select Cumulative probability instead. Making this change in the dialog box of Display 1.3.1, we get the output x 11.0000 P( X <= x ) 0.8413 in the Session window. Again, we can evaluate this function at a single point or at every value in a variable. The general syntax of the corresponding session command cdf command with the normal subcommand is cdf E1 . . .Em into Em+1 . . .E2m ; normal mu = V1 sigma = V2 . 60 Chapter 1 where E1 , ..., Em are columns or constants containing numbers and Em+1 , ..., E2m are the columns or constants that store the values of the area under N (µ, σ) density curve over the interval from −∞ to these numbers and V1 = µ and V2 = σ. If no storage is speciÞed, the values are printed. 1.3.3 Calculating the Inverse Distribution Function To evaluate inverse cdf for the N(µ, σ) distribution, we again use the Calc I ¯ Probability Distributions I Normal command, but in this case, in the dialog ¯ ¯ box of Display 1.3.1, we select Inverse cumulative probability. Making this change in the dialog box of Display 1.3.1 and replacing 11 by .75–recall that the argument to this function must be between 0 and 1–we get the output P( X <= x ) x 0.7500 10.6745 in the Session window. This indicates that the area to the left of 10.6745 underneath the N (10, 1) density curve is .75. The general syntax of the corresponding session command invcdf with the normal subcommand is invcdf E1 . . .Em into Em+1 . . .E2m ; normal mu = V1 sigma = V2 . where E1 , ..., Em are columns or constants containing numbers between 0 and 1 and Em+1 , ..., E2m are the columns or constants that store the values of the percentiles of the N(µ, σ) density curve at these numbers and where V1 = µ and V2 = σ. If no storage is speciÞed, then the values are printed. 1.3.4 Normal Probability Plots Some statistical procedures require that we assume that values for some variables are a sample from a normal distribution. A normal probability plot checks for the reasonableness of this assumption. To create such a plot, we use the Graph ¯ I Probability Plot command. ¯ Normal Probability Plots in Version 14 Suppose we want a normal probability plot for the time variable in the newcomb worksheet. In Version 14, using Graph I Probability Plot, we get the dialog ¯ ¯ box in Display 1.3.2, where we have selected Single and then clicked on OK. This brings up the dialog box in Display 1.3.3, where we placed time in the Variables box. Clicking on the Scale button and then the Y-Scale Type tab produces the dialog box of Display 1.3.4, where we have Þlled in the Scores option. Clicking on the OK button in this and the dialog box of Display 1.3.3 produces the plot in Display 1.3.5. The normal probability plot is given by the symbol •. This plot should be like a straight line. It is not a straight line in this case and would appear to be clear evidence that the data do not come from a normal distribution. There are Looking at Data–Distributions 61 many other features available with these plots and we refer the reader to the online manual for a discussion of these. It should be noted that Minitab computes the (normal) scores as follows. For an observation that has rank i the normal score is calculated as Φ−1 ((i − .375) / (n + .25)) . In Display 1.3.4, the values (i − .375) / (n + .25) are referred to as probabilities, while 100 (i − .375) / (n + .25) are referred to as percents. Display 1.3.2: First dialog box for producing a normal probability plot. Display 1.3.3: Second dialog box for producing normal probability plots. Display 1.3.4: Dialog box for selecting the Y-scale in a normal probability plot. 62 Chapter 1 Probability Plot of time Normal - 95% CI 3 Mean StDev N AD P-Value 2 26.21 10.75 66 5.884 <0.005 Score 1 0 -1 -2 -3 -50 -25 0 25 50 75 time Display 1.3.5: Normal probability plot for the time variable in the newcomb worksheet. Normal Probability Plots in Version 13 In Version 13, Graph I Probability Plot takes us directly to the dialog box ¯ ¯ shown in Display 1.3.6, which we have Þlled in to produce a normal probability plot like the one in Display 1.3.5, but on the y-axis it uses the values 100 (i − .375) / (n + .25) (percents). Display 1.3.6: Dialog box for producing normal probability plots. Session Commands for Normal Probability Plots The session commands MTB >nscores c1 c3 MTB >plot c3*c1 produce a normal probability plot like that shown in Display 1.3.5. The nscores (normal scores) command computes the score for each observation in C1 and Looking at Data–Distributions 63 places this in the corresponding entry of C3. The plot command then plots C3 versus C1 in a scatterplot. 1.4 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. Using Newcomb’s measurements in Table 1.1.1, create a new variable by grouping these values into three subintervals [−50, 0), [0, 20), [20, 50). Calculate the frequency distribution, the relative frequency distribution, and the cumulative distribution of this ordered categorical variable. 2. (1.33) Use Minitab to print the empirical distribution function. From this, determine the Þrst quartile, median, and third quartile. Also, use the empirical distribution function to compute the 10th and 90th percentiles. 3. Use Minitab to produce the stemplot of Example 1.5 of IPS. 4. Use Minitab to produce the time plot of Example 1.6 of IPS. 5. (1.28) Use Minitab commands for the stemplot and the time plot. Use Minitab commands to compute a numerical summary of this data, and justify your choices. 6. (1.30) Transform the data in this problem by subtracting 5 from each value and multiplying by 10. Calculate the means and standard deviations, using any Minitab commands, of both the original and transformed data. Compute the ratio of the standard deviation of the transformed data to the standard deviation of the original data. Comment on this value. 7. (1.30) Transform this data by multiplying each value by 3. Compute the ratio of the standard deviation to the mean (called the coeﬃcient of variation) for the original data and for the transformed data. Justify the outcome. 8. For the N (6, 1.1) density curve, compute the area between the interval (3, 5) and the density curve. What number has 53% of the area to the left of it for this density curve? 9. Use Minitab commands to verify the 68-95-99.7 rule for the N (2, 3) density curve. 64 Chapter 1 10. Calculate and store the values of the N (0, 1) density curve at each value in [−3, 3] using an increment of .01. Put the values in the interval [−3, 3] in C1 and the values of the density curve in C2. Using the command plot C2*C1, plot the density curve. Comment on the shape of this curve. 11. Use Minitab commands to make the normal quantile plots presented in Figures 1.32 and 1.34 of IPS. Chapter 2 Looking at Data–Relationships New Minitab commands discussed in this chapter Graph I Plot ¯ ¯ Stat I Basic Statistics I Correlation ¯ ¯ ¯ Stat I Regression I Fitted Line Plot ¯ ¯ ¯ Stat I Regression I Regression ¯ ¯ ¯ In this chapter, Minitab commands are described that permit the analysis of relationships among two variables. The methods are diﬀerent depending on whether or not both variables are quantitative, both variables are categorical, or one is quantitative and the other is categorical. This chapter considers relationships between two quantitative variables with the remaining cases discussed in later chapters. Graphical methods are very useful in looking for relationships among variables, and we examine various plots for this. 2.1 Scatterplots A scatterplot of two quantitative variables is a useful technique when looking for a relationship between two variables. By a scatterplot we mean a plot of one variable on the y-axis against the other variable on the x-axis. For example, consider the data in Table 2.1.1 collected from Þve fossil specimens of the extinct bird Archaeopteryx, where femur is the length in centimeters of the femur and humerus is the length in centimeters of the humerus. Here we are concerned with the relationship between the length of the femur and the length of the humerus. Suppose that we have input the data so that length of the humerus measurements are in C2, which has been named femur, and the 65 66 Chapter 2 length of the femur measurements are in C2, which has been named humerus, of the worksheet archaeopteryx. humerus femur 38 41 56 63 59 70 64 72 74 82 Table 2.1.1: Archaeopteryx data. We now want to plot the values of C2 against C1. We indicate how to do this using commands appropriate to the version of Minitab that you are using. Scatterplots in Version 14 Now we apply the Graph I Scatterplot command to the contents of C1 and ¯ ¯ C2. First, we obtain Display 2.1.1 and from this we select Simple and click OK, which leads to the dialog box in Display 2.1.2. We then Þll in C2 for the Y variable and C1 for the X variable. The plot depicted in Display 2.1.3 is produced in a separate Graph window when we click on OK. Display 2.1.1: Dialog box for selecting the type of scatterplot. Display 2.1.2: Dialog box for selecting the columns in a scatterplot. Looking at Data–Relationships 67 Scatterplot of femur vs humerus 75 70 65 femur 60 55 50 45 40 40 50 60 70 80 90 humerus Display 2.1.3: Scatter plot of femur length (C1) versus humerus length (C2). Note that the plotting symbol used in Display 2.1.3 for each point (x, y) is •. Alternatives are available. Clicking on Data View in the dialog box of Display 2.1.2 leads to the the dialog box of Display 2.1.4. If we select Connect line and plot the graph, we obtain the plot shown in Display 2.1.5. Also, you can add projection lines (drop a line from each point to the x-axis), and add areas (Þll in the area under a polygon joining the points). Furthermore, you can employ the scatterplot smoother lowess to plot a piecewise linear continuous curve through the scatter of points (look under Smoother). In particular, the plot itself can be edited by clicking on objects in the plot. There are a number of other features that allow you to control the appearance of the plot. In particular, you can double click any element of the plot and possibly modify its appearance according to the selections oﬀered in the dropdown list that appears. For example, if we double click the plotted curve, we have the option of changing the plotting symbol and its size. We refer the reader to the online manual for a full description of this feature. Display 2.1.4: Dialog box for selecting the appearance of the plotted line. 68 Chapter 2 Scatterplot of femur vs humerus 75 70 65 femur 60 55 50 45 40 40 50 60 70 80 90 humerus Display 2.1.5: Scatterplot with connecting lines. Scatterplots Using Version 13 The command Graph I Plot produces the dialog box of Display 2.1.6, where we ¯ ¯ have placed femur into the Þrst box for the y variable and humerus in the Þrst box for the x variable. This produces a plot like that shown in Display 2.1.3. Note that we could alter the plotting symbol using the dialog box that appears when we click on the Edit Attributes box. Using the dialog box that ¯ appears when you click on the Annotation button, it is possible to give the ¯ plot a title, label plotted points, etc. Using the dialog box that appears when you click on the Frame button, you can change the labels on the axes. Rather ¯ than just plotting the points in a scatterplot, you can add connection lines (join the points with lines), add projection lines (drop a line from each point to the x-axis), and add areas (Þll in the area under a polygon joining the points). Also, you can employ the scatterplot smoother lowess to plot a piecewise linear continuous curve through the scatter of points. These features are available via Graph I Plot I Display. There are a number of other features that allow you ¯ ¯ to control the appearance of the plot. Display 2.1.6: Dialog box for producing a scatterplot. Looking at Data–Relationships 69 Scatterplots Using Session Commands The corresponding session command is plot. For example, MTB > plot femur*humerus produces a plot like that shown in Display 2.1.3. Note that the Þrst variable is plotted along the y-axis, and the second variable is plotted along the x-axis. There are various subcommands that can be used with plot, and we refer the reader to Help for a description of these. ¯ 2.2 Correlations While a scatterplot is a convenient graphical method for assessing whether or not there is any relationship between two variables, we would also like to assess this numerically. The correlation coeﬃcient provides a numerical summarization of the degree to which a linear relationship exists between two quantitative variables, and this can be calculated using the Stat I Basic Statistics I ¯ ¯ Correlation command. For example, applying this command to the femur and ¯ humerus variables of the worksheet archaeopteryx, i.e., the data in Table 2.1.1 and depicted in Display 2.1.3, we obtain the output Pearson correlation of femur and humerus = 0.994 P-Value = 0.001 in the Session window. For now, we ignore the number recorded as P-Value. The general syntax of the corresponding session command correlate is given by correlate E1 . . . Em where E1 , ..., Em are columns corresponding to numerical variables, and a correlation coeﬃcient is computed between each pair. This gives m(m − 1)/2 correlation coeﬃcients. The subcommand nopvalues is available if you want to suppress the printing of P -values. 2.3 Regression Regression is another technique for assessing the strength of a linear relationship existing between two variables and it is closely related to correlation. For this, we use the Stat I Regression command. ¯ ¯ As noted in IPS, the regression analysis of two quantitative variables involves computing the least-squares line y = a + bx, where one variable is taken to be the response variable y and the other is taken to be the explanatory variable x. Note that the least squares line is diﬀerent depending upon which choice is made. For example, for the data of of the worksheet archaeopteryx, i.e., the data in Table 2.1.1 and depicted in Display 2.1.3, letting femur be the response and humerus be the predictor or explanatory variable, the Stat I Regression ¯ ¯ 70 Chapter 2 I Regression command leads to the dialog box of Display 2.2.1, where we have ¯ made the appropriate entries in the Response and Predictors boxes. Clicking on ¯ ¯ the OK button leads to the output of Display 2.2.2 being printed in the Session window. This gives the least-squares line as y = 3.70 + .826x, i.e., a = 3.70 and b = .826, which we also see under the Coef column in the Þrst table. In addition, we obtain the value of the square of the correlation coeﬃcient, also known as the coeﬃcient of determination, as R-Sq = 98.8%. We will discuss the remaining output from this command in Chapter 10. Display 2.2.1: Dialog box for a regression analysis. Display 2.2.2: Output from the dialog box of Display 2.2.1. It is very convenient to have a scatterplot of the points together with the least-squares line. This can be accomplished using the Stat I Regression I ¯ ¯ Fitted Line Plot command. Filling in the dialog box for this command as in ¯ Display 2.2.1 produces the output in the Session window of Display 2.2.2 together with the plot of Display 2.2.3. Looking at Data–Relationships 71 Fitted Line Plot humerus = - 3.660 + 1.197 femur 90 S R-Sq R-Sq(adj) 1.98203 98.8% 98.4% humerus 80 70 60 50 40 40 45 50 55 60 femur 65 70 75 Display 2.2.3: Scatterplot of femur versus humerus in the archaeopteryx worksheet together with the least-squares line. There are some additional quantities that are often of interest in a regression analysis. For example, you may wish to have the Þtted values ŷ = a +bx at each x value printed as well as the residuals y − ŷ. Clicking on the Results button in ¯ the dialog box of Display 2.2.1 and Þlling in the ensuing dialog box as in Display 2.2.4 results in these quantities being printed in the Session window as well as the output of Display 2.2.2. Display 2.2.4: Dialog box for controlling output for a regression. You will probably want to keep these values for later work. In this case, clicking on the Storage button of Display 2.2.1 and Þlling in the ensuing dialog box as in Display 2.2.5 results in these quantities being saved in the next two available columns–in this case, C3 and C4–with the names resl1 and fits1 for the residuals and Þts, respectively. 72 Chapter 2 Display 2.2.5: Dialog box for storing various quantities computed in a regression. Even more likely is that you will want to plot the residuals as part of assessing whether or not the assumptions that underlie a regression analysis make sense in the particular application. For this, click on the Graphs button in the dialog box of Display 2.2.1. The dialog box of Display 2.2.6 becomes available. Notice that we have requested that the standardized residuals–each residual divided by its standard error–be plotted, and this plot appears in Display 2.2.7. All the standardized residuals should be in the interval (−3, 3) , and no pattern should be discernible. In this case, this residual plot looks Þne. From the dialog box of Display 2.2.6, we see that there are many other possibilities for residual plots. Display 2.2.6: Dialog box for selecting various residual plots as part of a regression. Looking at Data–Relationships 73 Residuals Versus humerus (response is femur) 1.0 Standardized Residual 0.5 0.0 -0.5 -1.0 -1.5 -2.0 40 50 60 70 80 90 humerus Display 2.2.7: Plot of the standardized residuals versus humerus after regressing femur against humerus in the archaeopteryx worksheet. The corresponding session command is given by regress, and by using the subcommands pÞts, residual, and sresidual we can calculate and store Þtted values, residuals, and standardized residuals, respectively. For example, MTB > SUBC> SUBC> SUBC> regress c1 1 c2; fits c3; residuals c4; sresiduals c5. gives the output of Display 2.2.2 and also stores the Þtted values in C3, stores the residuals y − ŷ in C4, and stores the standardized residuals in C5. Note that the 1 in regress c1 1 c2 refers to the number of predictors we are using to predict the response variable. To plot the standardized residuals against humerus, we use MTB > plot c5*c2 which results in a plot like Display 2.2.7 but with diﬀerent labels on the x axis. 2.4 Transformations Sometimes, transformations of the variables are appropriate before we carry out a regression analysis. This is accomplished in Minitab using the Calc I ¯ Calculator command and the arithmetical and mathematical operations dis¯ cussed in Sections I.10.1 and I.10.2. In particular, when a residual plot looks bad, sometimes this can be Þxed by transforming one or more of the variables using a simple transformation, such as replacing the response variable by its logarithm or something else. For example, if we want to calculate the cube root – i.e., x1/3 –of every value in C1 and place these in C2, we use the Calc I ¯ 74 Chapter 2 Calculator command and the dialog box as depicted in Display 2.2.8. Alterna¯ tively, we could use the session command let as in MTB > let c2=c1**(1/3) to produce the same result. Display 2.2.8: Dialog box for calculating transformations of variables. 2.5 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. (2.14) Calculate the least-squares line and make a scatterplot of Fuel used against Speed together with the least-squares line. Plot the standardized residuals against Speed. What is the squared correlation coeﬃcient between these variables? 2. (2.13) Make a scatterplot of Rate against Mass where the points for different Sexes are labeled diﬀerently (use Minitab for the labeling, too) and with the least-squares line on it. Hint: Make use of the stack command discussed in Appendix C.5. 3. Place the values 1 through 100 with an increment of .1 in C1 and the square of these values in C2. Calculate the correlation coeﬃcient between Looking at Data–Relationships 75 C1 and C2. Multiply each value in C1 by 10, add 5, and place the results in C3. Calculate the correlation coeﬃcient between C2 and C3. Why are these correlation coeﬃcients the same? 4. Place the values 1 through 100 with an increment of .1 in C1 and the square of these values in C2. Calculate the least-squares line with C2 as response and C1 as explanatory variable. Plot the standardized residuals. If you see such a pattern of residuals what transformation, might you use to remedy the problem? 5. (2.45) For the data in this problem, numerically verify the algebraic relationship that exists between the correlation coeﬃcient and the slope of the least-squares line. 6. For Example 2.17 in IPS, calculate the least-squares line and reproduce Display 2.21. Calculate the sum of the residuals and the sum of the squared residuals and divide this by the number of data points minus 2. Is there anything you can say about what these quantities are equal to in general? 7. (2.70) Use Minitab to do all the calculations in this problem. 8. Place the values 1 through 10 with an increment of .1 in C1, and place exp (−1 + 2x) of these values in C2. Calculate the least-squares line using C2 as the response variable, and plot the standardized residuals against C1. What transformation would you use to remedy this residual plot? What is the least-squares line when you carry out this transformation? 76 Chapter 2 Chapter 3 Producing Data New Minitab commands discussed in this chapter Calc I Set Base ¯ ¯ Calc I Random Data ¯ ¯ This chapter is concerned with the collection of data, perhaps the most important step in a statistical problem, as this determines the quality of whatever conclusions are subsequently drawn. A poor analysis can be Þxed if the data collected are good by simply redoing the analysis. But if the data have not been appropriately collected, then no amount of analysis can rescue the study. We discuss Minitab commands that enable you to generate samples from populations and also to randomly allocate treatments to experimental units. Minitab uses computer algorithms to mimic randomness. Still, the results are not truly random. In fact, any simulation in Minitab can be repeated, with exactly the same results being obtained, using the Calc I Set Base command. ¯ ¯ For example, in the dialog box of Display 3.1, we have speciÞed the base, or seed, random number as 1111089. The base can be any integer. When you want to repeat the simulation, you give this command, with the same integer. Provided you use the same simulation commands, you will get the same results. This can also be accomplished using the session command base V, where V is an integer. Display 3.1: Dialog box for setting base or seed random number. 77 78 Chapter 3 3.1 Generating a Random Sample Suppose that we have a large population of size N and we want to select a sample of n < N from the population. Further, we suppose that the elements of the population are ordered, i.e., we have been able to assign a unique number 1, . . . , N to each element of the population. To avoid selection biases, we want this to be a random sample, i.e., every subset of size n from the population has the same “chance” of being selected. As discussed in IPS, this implies that we generate our sample so that every subset of size n in the population has the same chance of being chosen. We can do this physically by using some simple random system, such as chips in a bowl or coin tossing. We could also use a table of random numbers, or, more conveniently, we can use computer algorithms that mimic the behavior of random systems. For example, suppose there are 1000 elements in a population, and we want to generate a sample of 50 from this population without replacement. We can use the Calc I Random Data I Sample from Columns command to do this. ¯ ¯ ¯ For example, suppose we have labeled each element of the population with a unique number in 1, 2, . . . , 1000, and, further, we have put these numbers in C1 of a worksheet. The dialog box of Display 3.1.1 results in a random sample of 50 being generated without replacement from C1 and stored in C2. Display 3.1.1: Dialog box for generating a random sample without replacement. Printing this sample gives the output MTB > print c2 C2 441 956 87 736 438 205 760 246 538 348 70 54 277 112 610 890 764 584 566 495 414 613 618 685 185 16 362 503 547 864 515 321 492 332 488 883 371 182 413 206 957 493 841 886 557 690 393 287 798 263 Producing Data 79 in the Session window. So now we go to the population and select the elements labeled 441, 956, 87, etc. The algorithm that underlies this command is such that we can be conÞdent that this sample of 50 is like a random sample. The general syntax of the corresponding session command sample is sample V E1 . . . Em put into Em+1 . . . E2m where V is the sample size n and V rows are sampled from the columns E1 , ..., Em and stored in columns Em+1 , ..., E2m . If we wanted to sample with replacement–i.e., after a unit is sampled, it is placed back in the population so that it can possibly be sampled again–we use the replace subcommand. Of course, for simple random sampling, we do not use the replace subcommand. Note that the columns can be numeric or text. Sometimes we want to generate random permutations, i.e., n = N , and we are simply reordering the elements of the population. For example, in experimental design, suppose we have N = n1 + · · · + nk experimental units and k treatments, and we want to allocate ni applications of treatment i. Suppose further that we want all possible such applications to be equally likely. Then we generate a random permutation (l1 , . . . , lN ) of (1, . . . , N) and allocate treatment 1 to those experimental units labeled l1 , . . . , ln1 , allocate treatment 2 to those experimental units labeled ln1 +1 , . . . , ln1 +n2 , etc. For example, if we have 30 experimental units and 3 treatments and we want to allocate 10 experimental units to each treatment, placing the numbers 1, 2, . . . , 30 in C1 and using the Calc I Random Data I Sample from Columns command as in the dialog box of ¯ ¯ ¯ Display 3.1.1, but with 30 in the Sample box, generates a random permutation ¯ of 1, 2, . . . , 30 in C2. Implementing this gives us the random permutation MTB > print c2 C2 13 7 26 8 22 23 28 17 3 25 9 2 14 29 15 18 6 11 16 5 12 27 4 30 20 24 1 19 21 10 and for the treatment allocation you can read the numbers row-wise or columnwise, as long as you are consistent. Row-wise is probably best, as this is how the numbers are stored in C2, and so you can always refer back to C2 (presuming you save your worksheet) if you get mixed up. The above examples show how to directly generate a sample from a population of modest size. But what happens if the population is huge or it is not convenient to label each unit with a number? For example, suppose we have a population of size 100,000 for which we have an ordered list and we want a sample of size 100. In this case, more sophisticated techniques need to be used, but simple random sampling can still typically be accomplished (see Exercise 3.3 for a simple method that works in some contexts). Simple random sampling corresponds to sampling without replacement, i.e., after we randomly select an element from the population, we do not return it to the population before selecting the next sample element. Sampling with replacement corresponds to replacing each sample element in the population 80 Chapter 3 after selecting it and recording only the element that was obtained. So at each selection, every element has the same chance of being selected, and an element may appear more than once in the sample. Notice that we can also sample with replacement if we check the Sample with replacement box in the dialog box of Display 3.1.1. 3.2 Sampling from Distributions Once we have generated a sample from a population, we measure various attributes of the sampled elements. For example, if we were sampling from a population of humans, we might measure each sampled unit’s height. The height for the sample unit is now a random variable that follows the height distribution in the population from which we are sampling. For example, if 80% of the people in the population are between 4.5 feet and 6 feet, then under repeated sampling of an element from the population (with replacement) in the long run, 80% of the sampled units will have their heights in this range. Sometimes, we want to sample directly from this population distribution, i.e., generate a number in such a way that under repeated sampling in the long run the proportion of values falling in any range agrees with that prescribed by the population distribution. Of course, we typically don’t know the population distribution, as this is what we want to Þnd out about in a statistical investigation. Still, there are many instances where we want to pretend that we do know it and simulate from this distribution, e.g., perhaps we want to consider the eﬀect of various choices of population distribution on the sampling distribution of some statistic of interest. There are computer algorithms that allow us to do this for a variety of distributions. In Minitab, this is accomplished using the Calc I Random Data ¯ ¯ command. For example, suppose that we want to simulate the tossing of a fair coin (a coin where head and tail are equally likely as outcomes). The Calc I ¯ Random Data I Bernoulli command together with the dialog box of Display ¯ ¯ 3.2.1 generates a sample of 100 from the Bernoulli(.5) distribution and places these values in C1. A random variable has a Bernoulli(p) distribution if the probability the variable equals 1–success–is p and the probability the variable equals 0–failure–is 1 − p. So to generate a sample of n from the Bernoulli(p) distribution, we put n in the Generate box and p in the Probability of success box. In such a case, we are simulating the tossing of a coin that produces a head on a single toss with probability p, i.e., the long-run proportion of heads that we observe in repeated tossing is p. Note that we can generate m samples of size n by putting m distinct columns in the Store in column(s) box. Often, a normal distribution with some particular mean and standard deviation is considered a reasonable assumption for the distribution of a measurement in a population. For example, the Calc I Random Data I Normal command ¯ ¯ ¯ together with the dialog box of Display 3.2.2 generates a sample of 200 from the N (5.2, 1.3) distribution and places this sample in C1. To generate a sample of n from the N (µ, σ) distribution, we put n in the Generate box, µ in the Mean Producing Data 81 box, and σ in the Standard deviation box. Display 3.2.1: Dialog box for generating a sample form a Bernoulli distribution. Display 3.2.2: Dialog box for generating a sample of 200 from a N (5.2, 1.3) distribution. The general syntax of the corresponding session command random is random V into E1 . . . Em and this puts a sample of size V into each of the columns E1 , ..., Em , according to the distribution speciÞed by the subcommand. For example, MTB > random 100 c1; SUBC> bernoulli .5. simulates the tossing of a fair coin 100 times and places the results in C1 using the bernoulli subcommand. If no subcommand is provided, this distribution is taken to be the N (0, 1) distribution. The command 82 Chapter 3 MTB > random 200 c1; SUBC> normal mu=2.1 sigma=3.3. generates a sample of 200 from the N(2.1, 3.3) distribution using the normal subcommand. There are a number of other subcommands specifying distributions, and we refer the reader to help for a description of these. 3.3 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. If your version of Minitab places restrictions such that the value of the simulation sample size N requested in these problems is not feasible, then substitute a more appropriate value. Be aware, however, that the accuracy of your results is dependent on how large N is. 1. (3.13) Generate a random permutation of the names using Minitab. 2. (3.32) Use the Data I Sort command described in I.10.6 to order the sub¯ ¯ jects by weight. Use the values 1—5 to indicate Þve blocks of equal length in a separate column, and then use the Data I Unstack command de¯ scribed in Appendix C.5 to put the blocks in separate columns. Generate a random permutation of each block. 3. Use the following methodology to generate a sample of 20 from a population of 100,000. First, put the values 0—9 in each of C1—C5. Next, use sampling with replacement to generate 50 values from C1, and put the results in C6. Do the same for each of C2—C5 and put the results in C7—C10 (don’t generate from these columns simultaneously). Create a single column of numbers using the digits in C6—C10 as the digits in the numbers. Pick out the Þrst unique 20 entries as labels for the sample. If you do not obtain 20 unique values, repeat the process until you do. Why does this work? 4. Suppose you wanted to carry out stratiÞed sampling where there are three strata, with the Þrst stratum containing 500 elements, the second stratum containing 400 elements, and the third stratum containing 100 elements. Generate a stratiÞed sample with 50 elements from the Þrst stratum, 40 elements from the second stratum, and 10 elements from the third stratum. When the strata sample sizes are the same proportion of the total sample size as the strata population sizes are of the total population size this is called proportional sampling. Producing Data 83 5. Suppose we have an urn containing 100 balls with 20 labeled 1, 50 labeled 2, and 30 labeled 3. Using sampling with replacement, generate a sample of size 1000 from this distribution employing the Calc I Random Data ¯ ¯ command to generate the sample directly from the relevant population distribution. Use the Stat I Tables I Cross Tabulation command to ¯ in the ¯sample. record the proportion of¯ each label 6. Carry out a simulation study with N = 1000 of the sampling distribution of p̂ for n = 5, 10, 20 and for p = .5, .75, .95. In particular, calculate the empirical distribution functions and plot the histograms. Comment on your Þndings. 7. Carry out a simulation study with N = 2000 of the sampling distribution of the sample standard deviation when sampling from the N (0, 1) distribution based on a sample of size n = 5. In particular, plot the histogram using cutpoints 0, 1.5, 2.0 2.5, 3.0 5.0. Repeat this for the sample coeﬃcient of variation (sample standard deviation divided by the sample mean) using the cutpoints −10, −9, ..., 0, ..., 9, 10. Comment on the shapes of the histograms relative to an N (0, 1) density curve. 84 Chapter 3 Chapter 4 Probability: The Study of Randomness In this chapter, the concept of probability is introduced more formally than previously in the book. Probability theory underlies the powerful computational methodology known as simulation, which we introduced in Chapter 3. Simulation has many applications in probability and statistics and also in many other Þelds, such as engineering, chemistry, physics, and economics. 4.1 Basic Probability Calculations The calculation of probabilities for random variables can often be simpliÞed by tabulating the cumulative distribution function. Also, means and variances are easily calculated using component-wise column operations in Minitab. For example, suppose we have the probability distribution x probability 1 .1 2 .2 3 .3 4 .4 in columns C1 and C2, with the values in C1 and the probabilities in C2. The Calc I Calculator command with the dialog box as in Display 4.1.1 computes ¯ ¯ the cumulative distribution function in C3 using Partial Sums. 85 86 Chapter 4 Display 4.1.1: Dialog box for computing partial sums of entries in C2 and placing these sums in C3. Printing C1 and C3 gives Row 1 2 3 4 C1 1 2 3 4 C3 0.1 0.3 0.6 1.0 in the Session window. We can also easily compute the mean and variance of this distribution. For example, the session commands MTB > let c4=c1*c2 MTB > let c5=c1*c1*c2 MTB > let k1=sum(c4) MTB > let k2=sum(c5)-k1*k1 MTB > print k1 k2 K1 3.00000 K2 1.00000 calculate the mean and variance and store these in K1 and K2, respectively. The mean is 3 and the variance is 1. Of course, we can also use Calc I Calculator ¯ ¯ to do these calculations. In presenting more extensive computations, it is somewhat easier to list the appropriate session commands, as we will do subsequently. However, this is not to be interpreted as the required way to do these computations, as it is obvious that the menu commands can be used as well. Use whatever you Þnd most convenient. Probability: The Study of Randomness 4.2 87 More on Sampling from Distributions As we saw in Section 3.2, Minitab includes algorithms for generating from many probability distributions using Calc I Random Data. This menu command ¯ ¯ produces a drop-down list that includes the normal, binomial, Chi-square, F , t, uniform, and many other distributions that the text, and this manual, will discuss. Clicking on one of these names results in a dialog box with entries to be Þlled in further specifying the distribution and the size of the sample. For example, we can generate from one particularly important class of probability distributions using Calc I Random Data I Discrete. These probability ¯ ¯ ¯ distributions are concentrated on a Þnite number of values. To illustrate this, suppose we have the following values in C1 and C2. Row 1 2 3 4 C1 -1 2 3 10 C2 0.3 0.2 0.4 0.1 Here, C1 contains the possible values of an outcome, and C2 contains the probabilities that each of these values is obtained, so, for example, P ({−1}) = .3, P ({2}) = .2, etc. The dialog box of Display 4.2.1 generates a sample of 50 from this discrete distribution and stores the sample in C3. Display 4.2.1: Dialog box for generating a sample from a discrete distribution with values in C1 and probabilities in C2 and storing the sample in C3. It is an interesting exercise to check that the algorithms Minitab is using are in fact producing samples appropriately. There are a variety of things one could check, but perhaps the simplest is to check that the long-run relative frequencies 88 Chapter 4 are correct. So in the example of this section, we want to make sure that, as we increase the size of the sample, the relative frequencies of −1, 2, 3, 10 in the sample are getting closer to .3, .2, .4, and .1, respectively. Note that it is not guaranteed that as we increase the sample size that the relative frequencies get closer monotonically to the corresponding probabilities, but inevitably this must be the case. First, we generated a sample of size 100 from this distribution and stored the values in C3 as in Display 4.2.1. Next, we recorded a 1 in C4 whenever the corresponding entry in C3 was −1 and recorded a 0 in C4 otherwise. To do this, we used the Calc I Calculator command with dialog box as shown in Display ¯ ¯ 4.2.2. Display 4.2.2: Dialog box to record the incidence of a −1 in C3. It is clear that the mean of C4 is the relative frequency of −1 in the sample. We calculated this mean using Calc I Column Statistics, as discussed in I.10.4, ¯ ¯ which gave the output Mean of C4 = 0.33000 in the Session window. Repeating this with a sample of size 1000, we obtained Mean of C4 = 0.28100 which we can see is a bit closer to the true value of .3. Repeating this with a sample of size 10, 000 from this distribution, we obtained Mean of C4 = 0.29300 which is closer still. It would appear that the relative frequency of −1 is indeed converging to .3. Probability: The Study of Randomness 89 We can generate a randomly chosen point from the line interval (a, b) , where a < b, using Calc I Random Data I Uniform. For example, the dialog box ¯ ¯ ¯ of Display 4.2.3 generates a sample of 1500 from the uniform distribution on the interval (3.0, 6.3) . With this distribution, the probability of any subinterval (c, d) of (a, b) is given by (d − c) / (b − a), i.e., the length of (c, d) over the length of (a, b). Of course, we can estimate this probability by just counting the number of times the generated response falls in the interval (c, d) and dividing this by the total sample size. For example, using the outcomes from the dialog box of Display 4.2.3 and estimating the probability of the interval (4, 5), we get the relative frequency 0.30867, which is close to the true value of (5 − 4) / (6.3 − 3) = 0.30303. Display 4.2.3: Dialog box for generating a sample of 1500 from a Uniform(3, 6.3) distribution and storing the sample in C3. We can generalize this to generate from a point randomly chosen from a rectangle (a, b) × (c, d), i.e., the set of all points (x, y) such that a < x < b, c < y < d. If we want a sample of n from this distribution, we generate a sample x1 , . . . , xn from the uniform on (a, b) and also generate a sample y1 , . . . , yn from the uniform distribution on (c, d). Then (x1 , y1 ) , . . . , (xn , yn ) is a sample of n from the uniform distribution on (a, b) × (c, d). We can approximate the probability of a random pair (x, y) falling in any subset A ⊂ (a, b) × (c, d) by computing the relative frequency of A in the sample. The random command is the session command for carrying out simulations in Minitab. For example, the subcommand uniform V1 V2 speciÞes the continuous uniform distribution on the interval (V1 , V2 ); i.e., subintervals of the same length have the same probability of occurring. If we have 90 Chapter 4 placed a discrete probability distribution in column E2 , on the values in column E1 , the subcommand discrete E1 E2 generates a sample from this distribution. 4.3 Simulation for Approximating Probabilities As previously noted, simulation can be used to approximate probabilities. For a variety of reasons, these simulations are most easily presented using session commands but it is clear that we can replace each step by the appropriate menu command. For example, suppose we are asked to calculate P (.1 ≤ X1 + X2 ≤ .3) when X1 , X2 are both independent and follow the uniform distribution on the interval (0, 1) . The session commands MTB > random 1000 c1 c2; SUBC> uniform 0 1. MTB > let c3=c1+c2 MTB > let c4 = .1<=c3 and c3<=.3 MTB > let k1=sum(c4)/n(c4) MTB > print k1 K1 0.0400000 MTB > let k2=sqrt(k1*(1-k1)/n(c4)) MTB > print k2 K2 0.00619677 MTB > let k3=k1-3*k2 MTB > let k4=k1+3*k2 MTB > print k3 k4 K3 0.0214097 K4 0.0585903 generate N = 1000 independent values of X1 , X2 and place these values in C1 and C2, respectively, then calculate the sum X1 + X2 and put these values in C3. Using the comparison operators discussed in I.10.3, a 1 is recorded in C4 every time .1 ≤ X1 + X2 ≤ .3 is true and a 0 is recorded there otherwise. We then calculate the proportion of 1’s in the sample as K1, and this is our estimate p̂ of the probability. We will see later that a good measure of the accuracy of this estimate is the standard error of the estimate, which in this case is given by p p̂ (1 − p̂) /N and this is computed in K2. Actually, we can feel fairly conÞdent that the true value of the probability is in the interval p p̂ ± 3 p̂ (1 − p̂) /N Probability: The Study of Randomness 91 which in this case, equals the interval (0.0214097, 0.0585903). So we know the true value of the probability with reasonable accuracy. As the simulation size N increases, the Law of Large Numbers says that p̂ converges to the true value of the probability. 4.4 Simulation for Approximating Means The means of distributions can be approximated using simulations in Minitab. For example, suppose X1 , X2 are both independent and follow the uniform distribution on the interval (0, 1) and that we want to calculate the mean of Y = 1/ (1 + X1 + X2 ) . We can approximate this in a simulation. The session commands MTB > random 1000 c1 c2; SUBC> uniform 0 1. MTB > let c3=1/(1+c1+c2) MTB > let k1=mean(c3) MTB > let k2=stdev(c3)/sqrt(n(c3)) MTB > print k1 k2 K1 0.521532 K2 0.00375769 MTB > let k3=k1-3*k2 MTB > let k4=k1+3*k2 MTB > print k3 k4 K3 0.510259 K4 0.532805 generate N = 1000 independent values of X1 , X2 and place these values in C1, C2, then calculate Y = 1/ (1 + X1 + X2 ) and put these values in C3. The mean of C3 is stored in K1, and this is our estimate of the mean value of Y . As a measure of how accurate this estimate is, we compute the standard error of the estimate, which is given by the standard deviation divided by the square root of the simulation sample size N . Again, we can feel fairly conÞdent that the interval given by the estimate plus or minus 3 times the standard error of the estimate contains the true value of the mean. In this case, this interval is given by (0.510259, 0.532805), and so we know this mean with reasonable accuracy. As the simulation size N increases, the Law of Large Numbers says that the approximation converges to the true value of the mean. 4.5 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. 92 Chapter 4 Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. If your version of Minitab places restrictions such that the value of the simulation sample size N requested in these problems is not feasible, then substitute a more appropriate value. Be aware, however, that the accuracy of your results is dependent on how large N is. 1. Suppose we have the probability distribution x probability 1 .15 2 .05 3 .33 4 .37 5 .10 on the values 1, 2, 3, 4, and 5. Calculate the mean and variance of this distribution. Suppose that three independent outcomes (X1 , X2 , X3 ) are generated from this distribution. Compute the probability that 1 < X1 ≤ 4, 2 ≤ X2 and 3 < X3 ≤ 5. 2. Suppose we have the probability distribution x probability 1 .15 2 .05 3 .33 4 .37 5 .10 on the values 1, 2, 3, 4, and 5. Using Minitab, verify that this is a probability distribution. Make a bar chart (probability histogram) of this distribution. Generate a sample of size 1000 from this distribution and plot a relative frequency histogram for the sample. 3. (4.25) Indicate how you would simulate the game of roulette using Minitab. Based on a simulation of N = 1000, estimate the probability of getting red and a multiple of 3. 4. A probability distribution is placed on the integers 1, 2, ..., 100, where the probability of integer i is c/i2 . Determine c so that this is a probability distribution. What is the 90th percentile? Generate a sample of 20 from the distribution. 5. Suppose an outcome is random on the square (0, 1) × (0, 1). Using simulation, approximate the probability that the Þrst coordinate plus the second coordinate is less than .75 but greater than .25. 6. Generate ª from the uniform distribution on the unit disk © a sample of 1000 D = (x, y) : x2 + y2 ≤ 1 . 7. The expression e−x for x > 0 is the density curve for what is called the Exponential(1) distribution. Plot this density curve in the interval from 0 to 10 using an increment of .1. The Calc I Random Data I Exponential ¯ ¯ ¯ command can be used to generate from this distribution by specifying the Mean as 1 in the ensuing dialog box. Generate a sample of 1000 from this distribution and estimate its mean. Approximate the probability that a Probability: The Study of Randomness 93 value generated from this distribution is in the interval (1,2). The general Exponential(λ) has a density curve given by λ−1 e−x/λ for x > 0 and where λ > 0 is the mean. Repeat the simulation with mean λ = 3. Comment on the values of the estimated means. 8. Suppose you carry out a simulation to approximate the mean of a random variable X and you report the value 1.23 with a standard error of .025. If you are asked to approximate the mean of Y = 3 + 5X, do you have to carry out another simulation? If not, what is your approximation, and what is the standard error of this approximation? 9. Suppose that a random variable X follows an N (3, 2.3) distribution. Subsequently, conditions change and no values smaller than −1 or bigger than 9.5 can occur, i.e., the distribution is conditioned to the interval (−1, 9.5). Generate a sample of 1000 from the truncated distribution, and use the sample to approximate its mean. 10. Suppose that X is a random variable and follows an N (0, 1) distribution. Simulate N = 1000 values from the distribution of Y = X 2 , and plot these values in a histogram with cutpoints 0, .5, 1, 1.5, ..., 15. Approximate the mean of this distribution. Generate Y directly from its distribution, which is known to be a Chi-square(1) distribution. In general, the Chi-square(k) distribution can be generated from via the command Calc I Random Data ¯ ¯ I Chi-Square, where k is speciÞed as the Degrees of freedom in the dialog ¯ box. Plot the Y values in a histogram using the same cutpoints. Comment on the two histograms. Note that you can plot the density curve of these distributions using Calc I Probability Distributions I Chi-Square and ¯ ¯ ¯ evaluating the probability density at a range of points as we discussed in II.2 for the normal distribution. 11. If X1 and X2 are independent random variables with X1 following a Chisquare(k1 ) distribution and X2 following a Chi-square(k2 ) distribution, then it is known that Y = X1 + X2 follows a Chi-square(k1 + k2 ) distribution. For k1 = 1, k2 = 1, verify this empirically by plotting histograms with cutpoints 0, .5, 1, 1.5, ..., 15, based on simulations of size N = 1000. 12. If X1 and X2 are independent random variables with X1 following an N (0, 1) distribution and X2 following a Chi-square(k) distribution, then it is known that X1 Y =p X2 /k follows a Student(k) distribution. The Student(k) distribution can be generated from using the command Calc I Random Data I t, where k ¯ ¯ ¯ is the Degrees of freedom and must be speciÞed in the dialog box. For ¯ k = 3, verify this result empirically by plotting histograms with cutpoints −10, −9, ..., 9, 10, based on simulations of size N = 1000. 94 Chapter 4 13. If X1 and X2 are independent random variables with X1 following a Chisquare(k1 ) distribution and X2 following a Chi-square(k2 ) distribution, then it is known that X1 /k1 Y = X2 /k2 follows an F (k1 , k2 ) distribution. The F (k1 , k2 ) distribution can be generated from using the subcommand Calc I Random Data I F, where k1 ¯ ¯ ¯ is the Numerator degrees of freedom and k2 is the Denominator degrees of freedom, both of which must be speciÞed in the dialog box. For k1 = 1, k2 = 1, verify this empirically by plotting histograms with cutpoints 0, .5, 1, 1.5, ..., 15, based on simulations of size N = 1000. Chapter 5 Sampling Distributions New Minitab command discussed in this chapter Calc I Probability Distributions I Binomial ¯ ¯ ¯ Once data have been collected, they are analyzed using a variety of statistical techniques. Virtually all of these involve computing statistics that measure some aspect of the data concerning questions we wish to answer. The answers determined by these statistics are subject to the uncertainty caused by the fact that we typically do not have the full population but only a sample from the population. As such, we have to be concerned with the variability in the answers when diﬀerent samples are obtained. This leads to a concern with the sampling distribution of a statistic. Sometimes, the sampling distribution of a statistic can be worked out exactly through various mathematical techniques, e.g., in Chapter 5 of IPS it is seen that the number of 1’s in a sample of n from a Bernoulli(p) distribution is Binomial(n, p). Often, however, this is not possible, and we must resort to approximations. One approximation technique is to use simulation. Sometimes, however, the statistics we are concerned with are averages, and, in such cases, the central limit theorem justiÞes approximating the sampling distribution via an appropriate normal distribution. 5.1 The Binomial Distribution Suppose that X1 , . . . , Xn is a sample from the Bernoulli(p) distribution, i.e., X1 , . . . , Xn are independent realizations, where each Xi takes the value 1 or 0 with probabilities p and 1 − p, respectively. The random variable Y = X1 +· · ·+Xn equals the number of 1’s in the sample and follows a Binomial(n, p) distribution. Therefore, Y can take on any of the values 0, 1, . . . , n with positive probability. In fact, an exact formula can be derived for these probabilities, 95 96 Chapter 5 ¡ ¢ namely, P (Y = k) = nk pk (1 − p)n−k is the probability that Y takes the value k for 0 ≤ k ≤ n. When n and k are small, this formula could be used to evaluate this probability, but it is almost always better to use software like Minitab to do it, and when these values are not small, it is necessary. Also, we can use Minitab to compute the Binomial(n, p) cumulative probability distribution–the probability contents of intervals (−∞, x] and the inverse cumulative distribution– quantiles of the distribution. For individual probabilities, we use the Calc I Probability Distributions I ¯ ¯ Binomial command. For example, suppose we have a Binomial(30, .2) distri¯ bution and want to compute the probability P (Y = 10). This command, with the dialog box as in Display 5.1.1, produces the output (note Minitab uses the notation p instead of p for the probability of success) Binomial with n = 30 and p = 0.200000 x P( X = x ) 10.00 0.0354709 in the Session window, i.e., P (Y = 10) = 0.0354709. Display 5.1.1: Dialog box for Binomial(n, p) probability calculations. If we want to compute the probability of getting 10 or fewer successes (this is the probability of the interval (−∞, 10]) we can use the Calc I Probability ¯ Distributions I Binomial command with the dialog box as in Display 5.1.2. ¯ ¯ This produces the output Binomial with n = 30 and p = 0.200000 x P( X <= x ) 10.00 0.974384 in the Session window, i.e., P (Y ≤ 10) = 0.974384. Sampling Distributions 97 Display 5.1.2: Dialog box for computing cumulative probabilities for the Binomial(n, p) distribution. Suppose we want to compute the Þrst quartile of this distribution. The Calc ¯ I Probability Distributions I Binomial command, with the dialog box as in ¯ ¯ Display 5.1.3, produces the output Binomial with n = 30 and p = 0.200000 x P( X <= x ) x P( X <= x ) 3 0.122711 4 0.255233 in the Session window. This gives the values x that have cumulative probabilities just smaller and just larger than the value requested. Recall that with a discrete distribution, such as the Binomial(n, p), we will not in general be able to obtain an exact quantile. Display 5.1.3 Dialog box for computing percentiles of the Binomial(n, p) distribution. These commands can operate on all the values in a column simultaneously. This is very convenient if you should want to tabulate or graph the probability 98 Chapter 5 function, cumulative distribution function, or inverse distribution function. The corresponding session commands are pdf (for calculating the probability function), cdf (for calculating the cdf), and invcdf (for calculating the inverse cdf) used with the binomial subcommand. For example, MTB > pdf 10; SUBC> binomial 30 .2. outputs P (Y = 10) when Y has the Binomial(30, .2) distribution. 5.2 Simulating Sampling Distributions First, we consider an example where we know the exact sampling distribution. Suppose we ßip a possibly biased coin n times and want to estimate the unknown probability p of getting a head. The natural estimate is p̂ the proportion of heads in the sample. We would like to assess the sampling behavior of this statistic in a simulation. To do this, we choose a value for p, then generate N samples from the Bernoulli distribution of size n, for each of these compute p̂, look at the empirical distribution of these N values, perhaps plotting a histogram as well. The larger N is the closer the empirical distribution and histogram will be to the true sampling distribution of p̂. Note that there are two sample sizes here: the sample size n of the original sample the statistic is based on, which is Þxed, and the simulation sample size N , which we can control. This is characteristic of all simulations. Sometimes, using more advanced analytical techniques we can determine N so that the sampling distribution of the statistic is estimated with some prescribed accuracy. Some techniques for doing this are discussed in later chapters of IPS. Another method is to increase N until we see the results stabilize. This is sometimes the only way available, but caution should be shown as it is easy for simulation results to be very misleading if the Þnal N is too small. We illustrate a simulation to determine the sampling distribution of p̂ when sampling from a Bernoulli(.75) distribution. For this, we use the commands Calc ¯ I Random Data I Bernoulli, Calc I Row Statistics, and Stat I Tables I Tally, ¯ ¯ ¯ ¯ ¯ ¯ ¯ with the dialog boxes given by Displays 5.2.1, 5.2.2, and 5.2.3, respectively, to produce the output Summary Statistics for Discrete Variables C11 CumPct 0.3 0.40 0.4 2.20 0.5 7.60 0.6 23.10 0.7 47.70 0.8 78.00 0.9 94.70 1.0 100.00 Sampling Distributions 99 in the Session window. Here we have generated N = 1000 samples of size n = 10 from the Bernoulli(.75) distribution, i.e., we simulated the tossing of this coin 10,000 times, and we placed the results in the rows of columns C1—C10 using Calc I Random Data I Bernoulli. The proportion of heads p̂ in each sample ¯ ¯ ¯ is computed and placed in C11 using Calc I Row Statistics. Note that a mean ¯ ¯of 1’s in the sample. Finally, we of values equal to 0 or 1 is just the proportion used Stat I Tables I Tally to compute the empirical distribution function of ¯ ¯ ¯ these 1000 values of p̂. For example, this says 78% of these values were .8 or smaller and there were no instances smaller than .3. In Display 5.2.4, we have plotted a density histogram of the 1000 values of p̂ and this gives a rough idea of the shape of the sampling distribution. Display 5.2.1: Dialog box for generating 10 columns of 1000 Bernoulli(.75) values. Display 5.2.2: Dialog box for computing the proportion of 1’s in each of the 1000 samples of size 10. 100 Chapter 5 Display 5.2.3: Dialog box for computing the empirical distribution function of p̂. Display 5.2.4: Density histogram of simulation of N = 1000 values of p̂ based on a sample of size n = 10 from the Bernoulli(.75) distribution. The corresponding session commands for this simulation are MTB > SUBC> MTB > MTB > SUBC> random 1000 c1-c10; bernoulli .75. rmean c1-c10 c11 tally c11; cumpcts. and these might seem like an easier way to implement the simulation. In Chapter 5 of IPS, we saw that the sampling distribution of p̂ can be determined exactly, i.e., there are formulas to determine this, so really there is no need for a simulation in this case. Still, it illustrates how such a simulation proceeds in more general circumstances. Furthermore, we can simulate directly from the sampling distribution of p̂, so this simulation can be made much more eﬃcient. In eﬀect, this entails using Sampling Distributions 101 the Calc I Random Data I Binomial command with dialog box as in Display ¯ ¯ 5.2.5 and dividing each entry in C1 by 10. This generates N = 1000 values of p̂ but uses a much smaller number of cells. Still, there are many statistics for which this kind of eﬃciency reduction is not available, and, to get some idea of what their sampling distribution is like, we must resort to the more brute force form of simulation of generating directly from the population distribution. Sometimes, more sophisticated simulation techniques are needed to get an accurate assessment of a sampling distribution. Within Minitab, there are programming techniques, which we do not discuss in this manual, that can be applied in such cases. For example, it is clear that if our simulation required the generation of 106 cells (and this is not at all uncommon for some harder problems), the simulation approach we have described would not work within Minitab, as the worksheet would be too large. See Appendix D for a discussion of how such simulations can proceed in Minitab. Display 5.2.5: Dialog box for generating 1000 values from the sampling distribution of 10p̂ using the Binomial(10, .75) distribution. 5.3 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. If your version of Minitab places restrictions such that the value of the simulation sample size N requested in these problems is not feasible, then substitute a more appropriate value. Be aware, however, that the accuracy of your results is dependent on how large N is. 1. Calculate all the probabilities for the Binomial(5, .4) distribution and the Binomial(5, .6) distribution. What relationship do you observe? Can you 102 Chapter 5 explain this and state a general rule? 2. Compute all the probabilities for a Binomial(5, .8) distribution and use these to directly calculate the mean and variance. Verify your answers using the formulas provided in IPS. 3. Compute and plot the probability and cumulative distribution functions of the Binomial(10, .2) and the Binomial(10, .5) distributions. Comment on the shapes of these distributions. 4. Generate 1000 samples of size 10 from the Bernoulli(.3) distribution. Compute the proportion of 1’s in each sample and compute the proportion of samples having no 1’s, one 1, two 1’s, etc. Compute what these proportions would be in the longrun and compare. 5. Carry out a simulation study with N = 1000 of the sampling distribution of p̂ for n = 5, 10, 20 and for p = .5, .75, .95. In particular, calculate the empirical distribution functions and plot the histograms. Comment on your Þndings. 6. Suppose that X1 , X2 , . . . are independent realizations from the Bernoulli(p) distribution, i.e., each Xi takes the value 1 or 0 with probabilities p and 1 − p, respectively. If the random variable Y counts the number of tosses until we obtain the Þrst head in a sequence of independent tosses X1 , X2 , X3 , . . . , then Y has a Geometric(p) distribution. Minitab does not have built-in algorithms for computing the probability function, distribution function, inverse distribution function, and for generating from this distribution. The probability function for this distribution is given by P (Y = y) = (1 − p) y−1 p for y = 1, 2, . . . . Plot the probability function for the Geometric(.5) distribution for the values y = 1, . . . , 10. Do the same for the Geometric(.1) distribution. What do you notice? 7. Using methods for summing geometric sums, the cumulative distribution function of the Geometric(p) distribution (see Exercise II.5.6) is given by P (Y ≤ y) = 1−(1 − p)y . Plot the cumulative distribution function for the Geometric(.5) and Geometric(.1) distribution for the values y = 1, . . . , 10. What do you notice? 8. To randomly generate from the Geometric(p) distribution (see Exercise II.5.6), we can repeatedly generate from a Bernoulli(p) and count how many times we did this until the Þrst 1 appeared. A simple way to do this in Minitab is to generate N values from the Bernoulli(p) into a column. Count the number of entries until the Þrst 1, count the number of subsequent entries until the next 1, etc. These counts are identically and independently distributed according to the Geometric(p) distribution. This is a very ineﬃcient method when p is small and much better algorithms exist. Generate a sample of 10 from the Geometric(.5) distribution. Sampling Distributions 103 9. Carry out a simulation study, with N = 2000, of the sampling distribution of the sample standard deviation when sampling from the N (0, 1) distribution, based on a sample of size n = 5. In particular, plot the histogram using cutpoints 0, 1.5, 2.0 2.5, 3.0 5.0. Repeat this for the sample coeﬃcient of variation (sample standard deviation divided by the sample mean) using the cutpoints −10, −9, ..., 0, ..., 9, 10. Comment on the shapes of the histograms relative to a N (0, 1) density curve. 10. Generate N = 1000 samples of size n = 5 from the N (0, 1) distribution. Record a histogram for x̄ using the cutpoints −3, −2.5, √ −2, ..., 2.5, 3.0. Generate a sample of size N = 1000 from the N (0, 1/ 5) distribution. Plot the histogram using the same cutpoints and compare the histograms. What will happen to these histograms as we increase N ? 11. Generate N = 1000 values of X1 , X2 , where X1 follows a N (3, 2) distribution and X2 follows a N (−1, 3) distribution. Compute Y = X1 − 2X2 for each of these pairs and plot a histogram for Y using the cutpoints −20, −15, ..., 25, 30. Generate a sample of N = 1000 from the appropriate distribution of Y and plot a histogram using the same cutpoints. 12. Plot the density curve for the Exponential(3) distribution (see Exercise II.4.7) between 0 and 15 with an increment of .1. Generate N = 1000 samples of size n = 2 from the Exponential(3) distribution and record the sample means. Standardize the sample of x̄ using µ = 3 and σ = 3. Plot a histogram of the standardized values using the cutpoints −5, −4, ..., 4, 5. Repeat this for n = 5, 10. Comment on the shapes of these histograms. 13. Plot the density of the uniform distribution on (0,1). Generate N = 1000 samples of size n = 2 p from this distribution. Standardize the sample of x̄ using µ = .5 and σ = 1/12. Plot a histogram of the standardized values using the cutpoints −5, −4, ..., 4, 5. Repeat this for n = 5, 10. Comment on the shapes of these histograms. β 14. The Weibull(β) has density curve given by βxβ−1 e−x for x > 0, where β > 0 is a Þxed constant. Plot the Weibull(2) density in the range 0 to 10 with an increment of .1 using the Calc I Probability Distributions ¯ ¯ I Weibull, command. Generate a sample of N = 1000 from this distri¯ bution using the subcommand Calc I Random Data I Weibull where β ¯ ¯ ¯ is the Shape parameter and the Scale parameter is 1. Plot a probability histogram and compare with the density curve. 104 Chapter 5 Chapter 6 Introduction to Inference New Minitab commands discussed in this chapter Stat I Basic Statistics I 1-Sample Z ¯ ¯ ¯ Power and Sample Size I 1-Sample Z ¯ ¯ In this chapter, the basic tools of statistical inference are discussed. There are a number of Minitab commands that aid in the computation of conÞdence intervals and for carrying out tests of signiÞcance. 6.1 z ConÞdence Intervals The command Stat I Basic Statistics I 1-Sample Z computes conÞdence inter√ ¯ ¯ ¯ vals of the form x̄ ± z(1+γ)/2 σ0 / n, where γ is prescribed (often γ = 0.95), σ0 is known, x̄ and n are obtained from the data, and zα is the α-th percentile of the N(0, 1) distribution. Consider the sample given by (0.8403, 0.8363, 0.8447) , which are stored in C1, and suppose that it makes sense to take σ0 = .0068. The command Stat ¯ I Basic Statistics I 1-Sample Z with the dialog boxes as in Displays 6.1.1 and ¯ ¯ 6.1.2 produces the output Variable N Mean StDev SE Mean C1 3 0.840433 0.004202 0.003926 99.0% CI (0.830321, 0.850546) in the Session window. This speciÞes (0.83032, 0.85055) as a 99% conÞdence interval for µ. Note that in the dialog box of Display 6.1.1, we specify where the data resides in the Samples in Columns box, the value of σ0 in the Standard deviation box, and clicked on the Options button to bring up the dialog box in Display 6.1.2. In this dialog box we have speciÞed the 99% conÞdence level in the ConÞdence level box. 105 106 Chapter 6 Display 6.1.1: First dialog box for producing the z conÞdence interval for µ. Display 6.1.2: Second dialog box for producing the z conÞdence interval. Here we specify the conÞdence level. The corresponding session command zinterval is zinterval V1 sigma = V2 E1 . . .Em where V1 is the conÞdence level and is any value between 1 and 99.99, V2 is the assumed value of σ, and E1 , ..., Em are columns of data. A V1 % conÞdence interval is produced for each column speciÞed. If no value is speciÞed for V1 , the default value is 95%. 6.2 z Tests The Stat I Basic Statistics I 1-Sample Z command is used when we want to as¯ ¯ ¯ sess hypotheses about the unknown mean µ. Suppose the sample (2.0, 0.4, 0.7, 2.0, −0.4, 2.2, −1.3, 1.2, 1.1, 2.3) is stored in C1, and we are asked to assess the null hypothesis H0 : µ = 0 and we know that σ0 = 1. The Stat I Basic Statistics I ¯ ¯ Introduction to Inference 107 1-Sample Z command, together with the dialog box of Display 6.2.1, where we ¯ speciÞed where the data is located, the value of σ0 , and that we want to test H0 : µ = 0 by placing 0 in the Test mean box, produces the following output. Variable N C1 10 Z P 3.23 0.001 Mean 1.02000 StDev 1.19610 SE Mean 0.31623 99% CI (0.20545, 1.83455) This gives the value of z = 3.23 for the z statistic and the P-value equal to 0.001. This is strong evidence against H0 : µ = 0. Display 6.2.1: Dialog box for assessing the hypothesis H0 : µ = 0 using a z test. Sometimes it is preferred to assess a one-sided hypothesis such√as H0 : µ ≤ µ0 . In this case,√ the relevant P-value is P (Z > (x̄ − µ0 )/(σ0 / n)) = 1 − Φ ((x̄ − µ0 )/(σ0 / n)) . Minitab also has the facility for assessing hypotheses such as H0 : µ ≤ µ0 or H0 : µ ≥ µ0 . Suppose, for the above sample, we are asked to assess the null hypothesis H0 : µ ≤ 0 and we know σ = 1. The Stat I Basic Statistics I 1-Sample ¯ ¯ Z command, together with the dialog boxes of Displays 6.2.1 and 6.2.2 (the ¯ greater than refers to the values for which the null hypothesis is false), produces the output Variable N Mean C1 10 1.02000 99.0% Lower Bound 0.28434 StDev 1.19610 Z 3.23 SE Mean 0.31623 P 0.001 in the Session window. This speciÞes the P-value for this test as .001, so we have evidence against the null hypothesis. We obtained the dialog box in Display 6.2.2 by clicking on the Options button Display 6.2.1. Here we speciÞed that 108 Chapter 6 we want to test the null hypothesis H0 : µ ≤ 0 by selecting “greater than” in the Alternative box. The other choices are “not equal,” which selects the null hypothesis H0 : µ = 0 (the default), and “less than,” which selects the null hypothesis H0 : µ ≥ 0. Display 6.2.2: Dialog box for specifying the kind of test when using a z test. Note that the P-values for assessing H0 : µ = 0 and H0 : µ ≤ 0 are both given as 0.001 in the Minitab output, but these have been rounded from the actual values 0.000619 and 0.001238, respectively. In fact, the P-value for the one-sided test is always bigger than the P-value for the point hypothesis. The general syntax of the corresponding session command ztest is ztest V1 sigma = V2 E1 . . .Em where V1 is the hypothesized value to be tested, V2 is the assumed value of σ, and E1 , ..., Em are columns of data. If no value is speciÞed for V1 , the default is 0. A P-value for the hypothesis is computed for each column. If no alternative subcommand is speciÞed, the P-value for H0 : µ = V1 is computed. If the subcommand SUBC> alternative 1. is used, the P-value for H0 : µ ≤ V1 is computed. If the subcommand SUBC> alternative -1. is used, the P-value for H0 : µ ≥ V1 is computed. 6.3 Simulations for ConÞdence Intervals When we are sampling from a N(µ, σ) distribution and know the value of σ, the conÞdence intervals constructed in Section 6.1 are exact, i.e., in repeated sampling, the long run proportion of the 95% conÞdence intervals constructed for an unknown mean µ that will contain the true value of this quantity, is equal to 95%. Of course, any given conÞdence interval may or may not contain the true value of µ, and, in any Þnite number of such intervals so constructed, some proportion other than 95% will contain the true value of µ. As the number of intervals increases, however, the proportion covering will go to 95%. We illustrate this via a simulation study based on computing 90% conÞdence intervals. The session commands Introduction to Inference 109 MTB > random 100 c1-c5; SUBC> normal 1 2. MTB > rmean c1-c5 c6 MTB > invcdf .95; SUBC> normal 0 1. Normal with mean = 0 and standard deviation = 1.00000 P( X <= x) x 0.9500 1.6449 MTB > let k1=1.6449*2/sqrt(5) MTB > let c7=c6-k1 MTB > let c8=c6+k1 MTB > let c9=c7<1 and c8>1 MTB > mean c9 Mean of C9 = 0.91000 MTB > set c10 DATA> 1:25 DATA> end MTB > delete 26:100 c7 c8 generate 100 random samples of size 5 from the N (1, 2) distribution, place the means in C6, the lower end-point of a 90% conÞdence interval in C7, and the upper end-point in C8, and record whether or not a conÞdence interval covers the true value µ = 1 by placing a 1 or 0 in C9, respectively. The mean of C9 is the proportion of intervals that cover, and this is 91%, which is 1% too high. Finally, we plotted the Þrst 25 of these intervals in a plot shown in Display 6.3.1 (note we use the features available in Minitab for producing multiple scatterplots on the same plot to produce this plot). Drawing a solid horizontal line at 1 on the y-axis indicates that most of these intervals do indeed cover the true value µ = 1 (the 2nd, 4th, 15th and 21st intervals do not contain 1). Display 6.3.1: Plot of 90% conÞdence intervals for the mean when sampling from the N (1, 2) distribution with n = 5. The lower end-point is denoted by ◦ and the upper end-point is denoted by •. 110 Chapter 6 The simulation just carried out simply veriÞes a theoretical fact. On the other hand, when we are computing approximate conÞdence intervals–i.e., we are not sampling necessarily from a normal distribution–it is good to do some simulations from various distributions to see how much reliance we can place in the approximation at a given sample size. The true coverage probability of the interval, i.e., the long-run proportion of times that the interval covers the true mean, will not in general be equal to the nominal conÞdence level. Small deviations are not serious, but large ones are. 6.4 Power Calculations It is also useful to know in a given context how sensitive a particular test of signiÞcance is. By this, we mean how likely it is that the test will lead us to reject the null hypothesis when the null hypothesis is false. This is measured by the concept of the power of a test. Typically, a level α is chosen for the P-value at which we would deÞnitely reject the null hypothesis if the P-value is smaller than α. For example, α = .05 is a common choice for this level. Suppose that we have chosen the level of .05 for the two-sided z test and we want to evaluate the power of the test when the true value of the mean is µ = µ1 , i.e., evaluate the probability of getting a P-value smaller than .05 when the mean is µ1 . The two-sided √ z test with level α rejects H0 : µ = µ0 whenever √ 2(1 − Φ (|(x̄ − µ0 )/(σ/ n)|)) ≤ α or, equivalently, whenever |(x̄ − µ0 )/(σ/ n)| ≥ Φ−1 (1 − α/2) = z1−α/2 . For example, if α = .05, then 1 − α/2 = .975 (this quantile can be obtained using the command Calc I Probability Distributions ¯ ¯ I Normal and the inverse distribution function) which gives the output ¯ Normal with mean = 0 and standard deviation = 1.00000 P( X <= x) x 0.9750 1.9600 in the Session window, i.e., the .975 √ percentile of the N (0, 1) distribution is 1.96. − µ0 )/(σ/ n) is a realized√value from the distribution If µ = µ1 , then (x̄ √ of Y = (X̄ − µ√ 0 )/(σ/ n) when X̄ ∼ N (µ1 , σ/ n). Therefore, Y follows a N ((µ1 − µ0 )/(σ/ n), 1) distribution. The power of the two-sided test at µ = µ1 is then P (|Y | > z1−α/2 ) and this can be evaluated exactly using the command Calc I Probability Distributions I Normal and the distribution function, after ¯ ¯ ¯ writing ¢ ¡ P |Y | > z1−α/2 = P (Y > z1−α/2 ) + P (Y < −z1−α/2 ) µ ¶ µ ¶ (µ1 − µ0 ) (µ1 − µ0 ) √ √ + z1−α/2 + P Z < − − z1−α/2 =P Z>− σ/ n σ/ n with Z ∼ N (0, 1). Alternatively, exact power calculations can be carried out under the assumption of sampling from a normal distribution using the Stat I Power and Sample ¯ ¯ Size I 1-Sample Z command and Þlling in the dialog box appropriately. Also, ¯ the minimum sample size required to guarantee a given power at a prescribed Introduction to Inference 111 diﬀerence |µ1 − µ0 | can be obtained using this command. For example, Þlling in the dialog box for this command as in Display 6.4.1 creates the output Testing mean = null (versus not = null) Calculating power for mean = null + difference Alpha = 0.05 Sigma = 1.3 Sample Difference Size Power 0.1 10 0.0568057 0.2 10 0.0775267 in the Session window. This gives the power for testing H0 : µ = µ0 versus H0 : µ 6= µ0 at |µ1 − µ0 | = .1 and |µ1 − µ0 | = .2 when n = 10, σ = 1.3, and α = .05. These powers are given by 0.0568057 and 0.0775267, respectively. Clicking on the Options button allows you to choose other alternatives and specify other values¯ of α in the SigniÞcance level box. Display 6.4.1: Dialog box for calculating powers and minimum sample sizes. If we had instead Þlled in Power values at .1 and .2 in the dialog box of Display 6.4.1, say as .8 and .9, and had left the Sample sizes box empty, we would have obtained the output Testing mean = null (versus not = null) Calculating power for mean = null + difference Alpha = 0.05 Sigma = 1.3 Sample Target Actual Difference Size Power Power 0.1 1327 0.8000 0.800160 0.1 1776 0.9000 0.900039 0.2 332 0.8000 0.800456 0.2 444 0.9000 0.900039 in the Session window. This prescribes the minimum sample sizes n = 1327 and n = 1776 to obtain the powers .8 and .9, respectively, at the diﬀerence .1 and the sample sizes n = 332 and n = 444 to obtain the powers .8 and .9, respectively, at the diﬀerence .2. 112 Chapter 6 This derivation of the power of the two-sided test depended on the sample coming from a normal distribution, as this leads to X̄ having an exact normal distribution. In general, however, X̄ will be only approximately normal, so the normal calculation for the power is not exact. To assess the eﬀect of the nonnormality, however, we can often simulate sampling from a variety of distributions and estimate the probability P (|Y | > z1−α/2 ). For example, suppose that we want to test H0 : µ = 0 in a two-sided z test based on a sample of 10, where we estimate σ by the sample standard deviation and we want to evaluate the power at 1. Let us further suppose that we are actually sampling from a uniform distribution on the interval (−10, 12), which indeed has its mean at 1. The simulation given by the session commands MTB > random 1000 c1-c10; SUBC> uniform -10 12. MTB > rmean c1-c10 c11 MTB > rstdev c1-c10 c12 MTB > let c13=absolute(c11/(c12/sqrt(10))) MTB > let c14=c13>1.96 MTB > let k1=mean(c14) MTB > let k2=sqrt(k1*(1-k1)/n(c14)) MTB > print k1 k2 K1 0.112000 K2 0.00997276 estimates the power to be .112, and the standard error of this estimate, as given in K2, is approximately .01. The application determines whether or not the assumption of a uniform distribution makes sense and whether or not this power is indicative of a sensitive test or not. 6.5 The Chi-Square Distribution If Z is distributed according to the N(0, 1) distribution, then Y = Z 2 is distributed according to the Chi-square(1) distribution. If X1 is distributed Chisquare(k1 ) independent of X2 distributed Chi-square(k2 ), then Y = X1 + X2 is distributed according to the Chi-square(k1 +k2 ) distribution. There are Minitab commands that assist in carrying out computations for the Chi-square(k) distribution. Note that k is any positive value and is referred to as the degrees of freedom. The values of the density curve for the Chi-square(k) distribution can be obtained using the Calc I Probability Distributions I Chi-Square command, ¯ ¯ ¯ with k as the Degrees of freedom in the dialog box, or the session command pdf ¯ with the subcommand chisquare. For example, the command MTB > pdf c1 c2; SUBC> chisquare 4. calculates the value of the Chi-square(4) density curve at each value in C1 and stores these values in C2. This is useful for plotting the density curve. The Calc ¯ Introduction to Inference 113 I Probability Distributions I Chi-Square command, or the session commands ¯ ¯ cdf and invcdf, can also be used to obtain values of the Chi-square(k) cumulative distribution function and inverse distribution function, respectively. We use the Calc I Random Data I Chi-Square command, or the session command ¯ ¯ ¯ random, to obtain random samples from these distributions. We will see applications of the chi-square distribution later in the book but we mention one here. In particular, if x1 , . . . , xn is a sample from a N (µ, σ) P distribution, then (n − 1) s2 /σ2 = ni=1 (xi − x̄)2 /σ 2 is known to follow a Chisquare(n − 1) distribution, and this fact is used as a basis for inference about σ (conÞdence intervals and tests of signiÞcance). Because of the nonrobustness of these inferences to small deviations from normality, these inferences are not recommended. 6.6 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. If your version of Minitab places restrictions such that the value of the simulation sample size N requested in these problems is not feasible, then substitute a more appropriate value. Be aware, however, that the accuracy of your results is dependent on how large N is. 1. (6.19) Use the Stat I Basic Statistics I 1- Sample Z command to compute ¯ ¯ ¯ 90%, 95%, and 99% conÞdence intervals for µ. 2. (6.19) Use the Stat I Basic Statistics I 1- Sample Z command to test the ¯ ¯ ¯ null hypothesis against the appropriate alternative. Evaluate the power of the test with level α = .05 at µ = 225. 3. Simulate N = 1000 samples of size 5 from the N(1, 2) distribution, and calculate the proportion of .90 z conÞdence intervals for the mean that cover the true value µ = 1. 4. Simulate N = 1000 samples of size 10 from the uniform distribution on (0,1), and calculate the proportion of .90 z conÞdence intervals for the √ mean that cover the true value µ = .5. Use σ = 1/ 12. 5. Simulate N = 1000 samples of size 10 from the Exponential(1) distribution (see Exercise II.4.7), and calculate the proportion of .95 z conÞdence intervals for the mean that cover the true value µ = 1. Use σ = 1. 6. The density curve for the Student(1) distribution takes the form 1 1 π 1 + x2 114 Chapter 6 for −∞ < x < ∞. This special case is called the Cauchy distribution. Plot this density curve in the range (−20, 20) using an increment of .1. Simulate N = 1000 samples of size 5 from the Student(1) distribution (see Exercise II.4.12), and calculate the proportion of .90 conÞdence intervals for the mean, using the sample standard deviation for σ, that cover the value µ = 0. It is possible to obtain very bad approximations in this example because the central limit theorem does not apply to this distribution. In fact, it does not have a mean. 7. Suppose we are testing H0 : µ = 3 versus H0 : µ 6= 3 when we are sampling from a N (µ, σ) distribution with σ = 2.1 and the sample size is n = 20. If we use the critical value α = .01, determine the power of this test at µ = 4. 8. Suppose we are testing H0 : µ = 3 versus H0 : µ > 3 when we are sampling from a N (µ, σ) distribution with σ = 2.1. If we use the critical value α = .01, determine the minimum sample size so that the power of this test at µ = 4 is .99. 9. The uniform distribution onq the interval (a, b) has mean µ = (a + b) /2 2 and standard deviation σ = (b − a) /12. Calculate the power at µ = 1 of the two-sided z test at level α = .95 for testing H0 : µ = 0 when the sample size is n = 10, σ is the standard deviation of a uniform distribution on (−10, 12), and we are sampling from a normal distribution. 10. Suppose that we are testing H0 : µ = 0 in a two-sided test based on a sample of 3. Approximate the power of the z test at level α = .1 at µ = 5 when we are sampling from the distribution of Y = 5 + W, where W follows a Student(6) distribution (see Exercise II.4.12) and we use the sample standard deviation to estimate σ. Note that the mean of the distribution of Y is 5. Chapter 7 Inference for Distributions New Minitab commands discussed in this chapter Calc I Probability Distributions I F ¯ ¯ ¯ Calc I Probability Distributions I t ¯ ¯ ¯ Calc I Random Data I F ¯ alc I R ¯ andom Data I t¯ C ¯ ¯ ¯ Power and Sample Size I 1-Sample t ¯ ¯ Power and Sample Size I 2-Sample t ¯ ¯ Stat I Basic Statistics I 1-Sample t ¯ ¯ ¯ Stat I Basic Statistics I 2-Sample t ¯ ¯ ¯ Stat I Nonparametrics I 1-Sample Sign ¯ ¯ ¯ 7.1 The Student Distribution If Z is distributed Np (0, 1) independent of X distributed Chi-square(k) (see II.6.5), then T = Z/ X/k is distributed according to the Student(k) distribution. The value k is referred to as the degrees of freedom of the Student distribution. There are Minitab commands that assist in carrying out computations for this distribution. The values of the density curve, distribution function, and inverse distribution function for the Student(k) distribution can be obtained using the Calc ¯ I Probability Distributions I t command with k as the Degrees of freedom. ¯ ¯ ¯ Alternatively, we can use the session commands pdf, cdf, and invcdf with the student subcommand. For example, the command MTB > pdf c1 c2; SUBC> student 4. calculates the value of the Student(4) density curve at each value in C1 and stores these values in C2. This is useful for plotting the density curve. To 115 116 Chapter 7 generate from this distribution we use the command Calc I Random Data I t ¯ ¯ ¯ again with k as the Degrees of freedom or use the session command random with the student subcommand. 7.2 t ConÞdence Intervals When sampling from the N (µ, σ) distribution with µ and σ unknown, an exact 1−α √ conÞdence interval for µ based on the sample x1 , . . . , xn is given by x̄ ± t∗ s/ n, where t∗ is the 1 − α/2 percentile of the Student(n − 1) distribution. These intervals can be obtained using the Stat I Basic Statistics I 1- Sample ¯ ¯ ¯ t command. For example, suppose that we have the following sample of n = 10 in C1. 0.44 3.98 4.19 2.29 0.22 1.79 4.23 6.09 1.46 3.04 Then the Stat I Basic Statistics I 1- Sample t command, with the dialog box ¯ ¯ ¯ as in Display 7.2.1, produces the output Variable C1 N 10 Mean 2.77300 StDev 1.87218 SE Mean 0.59204 95% CI (1.43372, 4.11228) in the Session window. This computes a 95% conÞdence interval for µ as (1.43372, 4.11228). To change the conÞdence level, click on the Options button and Þll in the subsequent dialog box appropriately. Display 7.2.1: Dialog box for producing t conÞdence intervals. The general syntax of the corresponding session command tinterval is tinterval V E1 . . .Em where V is the conÞdence level and is any value between 1 and 99.99 and E1 , ..., Em are columns of data. A V% conÞdence interval is produced for each column speciÞed. If no value is speciÞed for V, the default value is 95%. Inference for Distributions 7.3 117 t Tests The Stat I Basic Statistics I 1-Sample t command is used when we have ¯ ¯ ¯ a sample x1 , . . . , xn from a normal distribution with unknown mean µ and standard deviation σ and we want to test the hypothesis that the unknown mean equals a value µ0 . The test is based on computing a P -value using the observed value of x̄ − µ0 √ t= s/ n and the Student(n − 1) distribution as described in IPS. For example, suppose we want to test H0 : µ = 3 for the data presented in Section 7.2. Then the Stat I Basic Statistics I 1- Sample t command, with the ¯ ¯ ¯ dialog box as in Display 7.3.1, produces the output Test of mu = 3 vs not = 3 Variable N Mean StDev SE Mean C1 10 2.77300 1.87218 0.59204 95% CI T P (1.43372, 4.11228) -0.38 0.710 so we have the P -value as 0.710 and we have no evidence against H0 : µ = 3. To assess other hypotheses click on the Options button and Þll in the subsequent dialog box appropriately. Display 7.3.1: First dialog box for a test of hypothesis using the t statistic. The general syntax of the corresponding session command ttest is ttest V E1 . . .Em where V is the hypothesized value to be tested and E1 , ..., Em are columns of data. If no value is speciÞed for V, the default is 0. A test of the hypothesis is carried out for each column. Also, the alternative subcommand is available and works just as with the ztest command. Note that the Stat I Basic Statistics I 1-Sample t command can also be ¯ two means in a matched pairs used to carry out ¯t tests ¯for the diﬀerence of 118 Chapter 7 design. For this, store the diﬀerence of the measurements in a column and apply Stat I Basic Statistics I 1-Sample t to that column as shown previously. ¯ ¯ ¯ Exact power calculations can be carried under the assumption of sampling from a normal distribution using Power and Sample Size I 1-Sample t and Þlling ¯ in the dialog box appropriately. Further, the minimum sample size required to guarantee a given power at a prescribed diﬀerence |µ1 − µ0 | and standard deviation σ can be obtained using this command. For example, using this command with the dialog box as in Display 7.3.2, we obtain the output Testing mean = null (versus not = null) Calculating power for mean = null + difference Alpha = 0.05 Sigma = 3 Sample Difference Size Power 2 5 0.2113 in the Session window. This gives the exact power of the two-sided t test when n = 5, |µ1 − µ0 | = 2, σ = 3.0, and α = .05 as .2113. The Options button can be used to compute power for one-sided tests. Display 7.3.2: Dialog box for determining power and minimum sample sizes when using the one sample t test. 7.4 The Sign Test As discussed in IPS, sometimes we cannot sensibly assume normality or transform to normality or make use of large samples so that there is a central limit theorem eﬀect. In such a case, we attempt to use distribution free or nonparametric methods. The testing method based on the sign test statistic for the median is one of these. For example, suppose we have the data of Section 7.2 stored in column C1. Then the Stat I Nonparametrics I 1-Sample Sign command produces the ¯ ¯ ¯ Inference for Distributions 119 dialog box given in Display 7.4.1. Here we have Þlled in the ConÞdence interval button, and in the Level box we have requested a .95 conÞdence interval for the median. The following output is obtained. Sign confidence interval for median Confidence Achieved Interval N Median Confidence Lower Upper C1 10 2.665 0.8906 1.460 4.190 0.9500 1.111 4.204 0.9785 0.440 4.230 Position 3 NLI 2 As the distribution of the sign statistic is discrete, in general the exact conÞdence cannot be attained, so Minitab records the conÞdence intervals with conÞdence level just smaller and just greater than the conÞdence level requested and also records a middle interval obtained by interpolation. Display 7.4.1: Dialog box for the sign test and the sign conÞdence interval. If instead we Þll in the Test median button and enter 4.0 for the null hypothesis with the Alternative not equal, we obtain the output Sign test of median = 4.000 versus not = 4.000 N Below Equal Above P Median C1 10 7 0 3 0.3438 2.665 which gives the P -value as 0.3438 for assessing the hypothesis that the median of the population distribution equals 4.0. Also, the sample median of 2.665 is recorded. Note that the Stat I Nonparametrics I 1-Sample Sign command can also ¯ ¯ ¯ be used to construct conÞdence intervals and carry out tests for the median of a diﬀerence in a matched pairs design. For this, store the diﬀerence of the measurements in a column and apply the command to that column. The corresponding session commands are sinterval, for the sign conÞdence interval and stest, for the sign test. The general syntax of the sinterval command is 120 Chapter 7 sinterval V E1 . . .Em where V is the conÞdence level, and is any value between 1 and 99.99, and E1 , ..., Em are columns of data. A V% conÞdence interval is produced for each column speciÞed. If no value is speciÞed for V, then the default value is 95%. The general syntax of the stest command is stest V E1 . . .Em where V is the hypothesized value to be tested and E1 , ..., Em are columns of data. If no value is speciÞed for V, the default is 0. A test of the hypothesis is carried out for each column. The alternative subcommand is also available for one-sided tests. 7.5 Comparing Two Samples If we have independent samples x11 , . . . x1n1 from the N (µ1 , σ1 ) distribution and x12 , . . . x1n2 from the N(µ2 , σ2 ) distribution, where σ1 and σ2 are known, we can base inferences about the diﬀerence of the means µ1 −µ2 on the z statistic given by x̄1 − x̄2 − (µ1 − µ2 ) q 2 . z= σ1 σ22 + n1 n2 Under these assumptions, z has an N (0, 1) distribution. Therefore, a 1 − α conÞdence interval for µ1 − µ2 is given by s σ12 σ22 ∗ x̄1 − x̄2 ± + z n1 n2 where z ∗ is the 1 − α/2 percentile of the N(0, 1) distribution. We can test H0 : µ = µ0 against the alternative Ha : µ 6= µ0 by computing the P -value P (|Z| > |z0 |) = 2P (Z > z0 ), where Z is distributed N (0, 1) and z0 is the observed value of the z statistic. These inferences are also appropriate without normality, provided n1 and n2 are large and we have reasonable values for σ1 and σ2 . These inferences are easily carried out using Minitab commands we have already discussed. In general, however, we will not have available suitable values of σ1 and σ2 or large samples and will have to use the two-sample analogs of the single-sample t procedures just discussed. This is acceptable, provided, of course, that we have checked for and agreed that it is reasonable to assume that both samples are from normal distributions. These procedures are based on the two-sample t statistic given by x̄1 − x̄2 − (µ1 − µ2 ) q 2 t= s1 s22 n1 + n2 where we have replaced the population standard deviations by their sample estimates. The exact distribution of this statistic does not have a convenient Inference for Distributions 121 form, but, of course, we can always simulate its distribution. Actually, it is typical to use an approximation to the distribution of this statistic based on a Student distribution. See the discussion in IPS on this, and use Help to get more details. The Stat I Basic Statistics I 2-Sample t command is available for computing ¯ ¯ ¯ inference procedures based on t. For example, suppose that we have the data for Example 7.20 of IPS in a worksheet with the Placebo sample in C1 and the Calcium sample in C2. The Stat I Basic Statistics I 2-Sample t command ¯ ¯ ¯ with the dialog box as in Display 7.5.1 Display 7.5.1: Dialog box for two sample problems based on the two-sample t statistic. produces the output Two-sample T for C1 vs C2 N Mean StDev SE Mean C1 10 5.00 8.74 2.8 C2 11 -0.27 5.90 1.8 Difference = mu (C1) - mu (C2) Estimate for difference: 5.27273 95% CI for difference: (-1.73509, 12.28054) T-Test of difference = 0 (vs not =): T-Value = 1.60 P-Value = 0.130 DF = 15 in the Session window. This gives a 95% conÞdence interval for the diﬀerence in the means µ1 − µ2 as (−1.73509, 12.28054) and calculates the P -value .130 for the test of H0 : µ1 − µ2 = 0 versus the alternative Ha : µ1 − µ2 6= 0. In this case, we do not reject H0 . Notice we have selected the Samples in diﬀerent columns radio button, as this is how we have stored our data. Alternatively, we can store all the actual measurements in a single column with a second column providing an index of the sample to which the observation belongs. Clicking on the Options button ¯ 122 Chapter 7 of the dialog box of Display 7.5.1 produces a dialog box where we can prescribe a diﬀerent value for the conÞdence level, the diﬀerence between the means that we wish to test for, and the type of hypothesis. Notice also that, in the dialog box of Display 7.5.1, we have left the box Assume equal variances unchecked. This box is checked only when we feel that we can assume that σ1 = σ2 = σ and want to pool both samples together to estimate the common σ. Pooling is usually unnecessary and is not recommended. Exact power calculations can be carried under the assumption of sampling from a normal distribution using Power and Sample Size I 2-Sample t and ¯ Þlling in the dialog box appropriately, although this requires the assumption of a common population standard deviation σ. Further, the minimum sample size required to guarantee a given power at a prescribed diﬀerence |µ1 − µ2 |, and assuming a common standard deviation σ, can be obtained using this command. This command works the same as the one sample case. There are two corresponding session commands–twosample and twot. Each of these commands computes conÞdence intervals for the diﬀerence of the means and computes P -values for tests of signiÞcance concerning the diﬀerence of means. The only diﬀerence between these commands is that with twosample the two samples are in individual columns, while with twot the samples are in a single column with subscripts indicating group membership in a second column. The general syntax of the twosample command is twosample V E1 E2 where V is the conÞdence level and is any value between 1 and 99.99 and E1 , E2 are columns of data containing the two samples. The general syntax of the twot command is twot V E1 E2 where V is the conÞdence level and is any value between 1 and 99.99 and E1 , E2 are columns of data with E1 containing the samples and E2 containing the subscripts. The alternative subcommand is available with both twosample and twot if we wish to conduct one-sided tests. Also, the subcommand pooled is available if we feel we can assume that σ1 = σ2 = σ and want to pool both samples together to estimate the common σ. 7.6 The F Distribution If X1 is distributed Chi-square(k1 ) independent of X2 distributed Chi-square(k2 ), then X1 /k1 F = X2 /k2 is distributed according to the F (k1 , k2 ) distribution. The value k1 is called the numerator degrees of freedom and the value k2 is called the denominator Inference for Distributions 123 degrees of freedom. There are Minitab commands that assist in carrying out computations for this distribution. The values of the density curve for the F (k1 , k2 ) distribution can be obtained using the Calc I Probability Distributions I F command, with k1 speciÞed as ¯ ¯ ¯ the Numerator degrees of freedom and k2 speciÞed as the Denominator degrees of freedom in the dialog box. For example, this command with the dialog box as in Display 7.6.1 produces the output x 5.0000 P( X <= x ) 0.828826 in the Session window. This calculates the value of the F (3, 2) distribution function at 5 as .8288. Alternatively, you can use the session commands pdf, cdf, and invcdf with the F subcommand. The Calc I Random Data I F ¯ ¯ ¯ command and the session command random with the F subcommand can be used to obtain random samples from the F (k1 , k2 ) distribution. Display 7.6.1: Dialog box for probability calculations for the F (k1 , k2 ) distribution. There are a number of applications of the F -distribution. In particular, if x11 , . . . x1n1 is a sample from the N (µ1 , σ1 ) distribution and x12 , . . . x1n2 a sample from the N (µ2 , σ2 ) distribution, then F = s21 /σ12 s22 /σ22 is known to follow an F (n1 − 1, n2 − 1). This fact is used as a basis for inference about the ratio σ1 /σ2 , i.e., conÞdence intervals and tests of signiÞcance and, in particular, testing for equality of variances between the samples. Because of the nonrobustness of these inferences to small deviations from normality, these inferences are not recommended. 124 7.7 Chapter 7 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. If your version of Minitab places restrictions such that the value of the simulation sample size N requested in these problems is not feasible, then substitute a more appropriate value. Be aware, however, that the accuracy of your results is dependent on how large N is. 1. Plot the Student(k) density curve for k = 1, 2, 10, 30 and the N (0, 1) density curve on the interval (−10, 10) using an increment of .1 and compare the plots. 2. Make a table of the values of the cumulative distribution function of the Student(k) distribution for k = 1, 2, 10, 30 and the N(0, 1) distribution at the points −10, −5, −3, −1, 0, 1, 3, 5, 10. Comment on the values. 3. Make a table of the values of the inverse cumulative distribution function of the Student(k) distribution for k = 1, 2, 10, 30 and the N (0, 1) distribution at the points .0001, .001, .01, .1, .25, .5. Comment on the values. 4. Simulate N = 1000 values from Z distributed p N(0, 1) and X distributed Chi-square(3) and plot a histogram of T = Z/ X/3 using the cutpoints −10, −9, . . . , 9, 10. Generate a sample of N = 1000 values directly from the Student(3) distribution, plot a histogram with the same cutpoints, and compare the two histograms. 5. Carry out a simulation with N = 1000 to verify that the 95% conÞdence interval based on the t statistic covers the true value of the mean 95% of the time when taking samples of size 5 from the N (4, 2) distribution. 6. Generate a sample of 50 from the N (10, 2) distribution. Compare the 95% conÞdence intervals obtained via the Stat I Basic Statistics I 1-Sample ¯ ¯ ¯ t and Stat I Basic Statistics I 1- Sample Z commands using the sample ¯ ¯ ¯ standard deviation as an estimate of σ. 7. Calculate the power of the t test at µ1 = 1, σ1 = 2 for testing H0 : µ = 0 versus the alternative Ha : µ 6= 0 at level α = .05, based on a sample of 5 from the normal distribution. 8. Simulate the power of the two sample t test at µ1 = 1, σ1 = 2, µ2 = 2, σ1 = 3 for testing H0 : µ1 − µ2 = 0 versus the alternative Ha : µ1 − µ2 6= 0 at level α = .05, based on a sample of 5 from the N (µ1 , σ1 ) distribution and a sample of size 8 from the N (µ2 , σ2 ) distribution. Use the conservative Inference for Distributions 125 rule when choosing the degrees of freedom for the approximate test, i.e., the smaller of n1 − 1 and n2 − 1. 9. If Z is distributed N(µ, 1) and X is distributed Chi-square(k) independent of Z, then Z Y =p X/k is distributed according to a noncentral Student(k) distribution with noncentrality µ. Simulate samples of N = 1000 from this distribution with k = 5 and µ = 0, 1, 5, 10. Plot the samples in histograms with cutpoints −20, −19, . . . , 19, 20 and compare these plots. 10. If X1 is distributed Chi-square(k1 ) independently of X2 , which is distributed N (δ, 1), then the random variable Y = X1 + X22 is distributed according to a noncentral Chi-square(k + 1) distribution with noncentrality λ = δ 2 . Generate samples of n = 1000 from this distribution with k = 2 and λ = 0, 1, 5, 10. Plot histograms of these samples with the cut-points 0,1, ..., 200. Comment on the appearance of these histograms. 11. If X1 is distributed noncentral Chi-square(k1 ) with non-centrality λ independently of X2 , which is distributed Chi-square(k2 ), then the random variable X1 /k1 Y = X2 /k2 is distributed according to a noncentral F (k1 , k2 ) distribution with noncentrality λ. Generate samples of n = 1000 from this distribution with k1 = 2, k2 = 3, and λ = 0, 1, 5, 10. Plot histograms of these samples with the cut-points 0,1, ..., 200. Comment on the appearance of these histograms. 126 Chapter 7 Chapter 8 Inference for Proportions New Minitab commands discussed in this chapter Power and Sample Size I 1 Proportion ¯ ¯ Power and Sample Size I 2 Proportions ¯ ¯ Stat I Basic Statistics I 1 Proportion ¯ ¯ ¯ Stat I Basic Statistics I 2 Proportions ¯ ¯ ¯ This chapter is concerned with inference methods for a proportion p and for the comparison of two proportions p1 and p2 . Proportions arise from measuring a binary-valued categorical variable on population elements, such as gender in human populations. For example, p might be the proportion of females in a given population, or we might want to compare the proportion p1 of females in population 1 with the proportion p2 of females in population 2. The need for inference arises as we base our conclusions about the values of these proportions on samples from the populations rather than measuring every element in the population. For convenience, we will denote the values assumed by the binary categorical variables as 1 and 0, where 1 indicates the presence of a characteristic and 0 indicates its absence. 8.1 Inference for a Single Proportion Suppose that x1 , . . . , xn is a sample from a population where the variable is measuring the presence or absence of some trait by a 1 or 0, respectively. Let p̂ be the proportion of 1’s in the sample. This is the estimate of the true proportion p. For example, the sample could arise from coin tossing, where 1 denotes heads and 0 tails and p̂ is the proportion of heads, while p is the probability of heads. If the population we are sampling from is Þnite, then, strictly speaking, the sample elements are not independent. But if the population size is large relative to the sample size n, then independence is a reasonable approximation, and this is 127 128 Chapter 8 necessary for the methods of this chapter. So we will consider x1 , . . . , xn as a sample from the Bernoulli(p) distribution. p The standard error of the estimate p̂ is p̂(1 − p̂)/n, and because p̂ is an average, the central limit theorem gives that p̂ − p z=q p̂(1−p̂) n is approximately N(0, 1) for p large n. This leads to the approximate 1 − α conÞdence interval given by p̂ ± p̂(1 − p̂)/nz ∗ , where z ∗ is the 1 − α/2 percentile of the N(0, 1) distribution. To test a null hypothesis H0 : p = p0 , we make use of the fact that under the null hypothesis the statistic p̂ − p0 z=q p0 (1−p0 ) n is approximately N (0, 1). To test H0 : p = p0 versus Ha : p 6= p0 , we compute P (|Z| > |z|) = 2P (Z > |z|), where Z is distributed N (0, 1). For example, suppose that a coin was tossed n = 4040 times and the observed proportion of heads is x̄ = 2048/4040 = .5069. Then we have that p .5069(1 − .5069) = 0.49995 and, using the dialog box in Display 8.1.1, we obtain the output N Mean SE Mean 95% CI 4040 0.506900 0.007866 (0.491484, 0.522316) which provides an approximate .95-conÞdence interval for θ. Display 8.1.1: Dialog box for obtaining conÞdence intervals. p Similarly, if we want to assess the hypothesis H0 : θ = .5, then .5(1 − .5) = 0.5 and the dialog box in Display 8.1.2 leads to Test of mu = 0.5 vs not = 0.5 The assumed standard deviation = 0.5 N Mean SE Mean 95% CI Z P 4040 0.506900 0.007866 (0.491482, 0.522318) 0.88 0.380 Inference for Proportions 129 which gives the P -value as 0.380 and so we have no evidence against H0 : θ = .5. If we wish to use other conÞdence levels or test other hypotheses, then these options are available using the Options button in the dialog box. Display 8.1.2: Dialog box for obtaining P -values. Note that the estimate and conÞdence intervals recorded by the software are not those based on the Wilson estimate discussed in IPS. To obtain the Wilson estimate and the associated conÞdence interval, we must add four data values to the data set–two heads (or successes) and two tails (or failures). So in this case, implementing the above command with the number of trials equal to 4044 and the number of successes equal to 2050 will produce the inferences based on the Wilson estimate. Power calculations and minimum sample sizes to achieve a prescribed power can be obtained using Power and Sample Size I 1 Proportion. For example, ¯ ¯ suppose we want to compute the power of the test for H0 : p = .5 versus Ha : p 6= .5 at level α = .05 at n = 10, p = .4. This command, with the dialog box as in Display 8.1.3, Display 8.1.3: Dialog box for power calculations for test of a single proportion. produces the output 130 Chapter 8 Testing proportion = 0.5 (versus not = 0.5) Alpha = 0.05 Alternative Sample Proportion Size Power 0.400000 10 0.0918 which calculates this power as .0918. So the test is not very powerful. By contrast, at n = 100, p = .4 the power is .51633. 8.2 Inference for Two Proportions Suppose that x11 , . . . , xn1 1 is a sample from population 1 and x12 , . . . , xn2 2 is a sample from population 2, where the variable is measuring the presence or absence of some trait by a 1 or 0, respectively. We assume then that we have a sample of n1 from the Bernoulli(p1 ) distribution and a sample of n2 from the Bernoulli(p2 ) distribution. Suppose that we want to make inferences about the diﬀerence in the proportions p1 − p2 . Let p̂i be the proportion of 1’s in the ith sample. The central limit theorem gives that p̂1 − p̂2 − (p1 − p2 ) z=q p̂1 (1−p̂1 ) 2) + p̂2 (1−p̂ n1 n2 is approximately N (0, 1) for large n1 and n2 . This leads to the approximate 1 − α conÞdence interval given by s p̂1 (1 − p̂1 ) p̂2 (1 − p̂2 ) ∗ p̂1 − p̂2 ± + z n1 n2 where z ∗ is the 1 − α/2 percentile of the N (0, 1) distribution. As indicated in IPS, the Wilson estimate and its corresponding conÞdence interval are obtained by adding four data values to the data set–one success and one failure to each sample–so that the ith sample size becomes ni + 2 and the ith sample estimate becomes (ni p̂i + 1) / (ni + 2). The above formula for the conÞdence interval applied with these changes then gives the interval based on the Wilson estimates. To test a null hypothesis H0 : p1 = p2 we use the fact that under the null hypothesis the statistic p̂1 − p̂2 z=r ³ p̂(1 − p̂) n11 + 1 n2 ´ is approximately N (0, 1) for large n1 and n2 , where p̂ = n1 p̂1 + n2 p̂2 n1 + n2 Inference for Proportions 131 is the estimate of the common value of the proportion when the null hypothesis is true. To test H0 : p1 = p2 versus Ha : p1 6= p2 we compute P (|Z| > |z|) = 2P (Z > |z|) where Z is distributed N(0, 1). For example, suppose that we want to test H0 : p1 = p2 versus Ha : p1 6= p2 when n1 = 61, p̂1 = .803 = 49/61, n2 = 62, p̂2 = .613 = 38/62. The command Stat I Basic Statistics I 2 Proportions with the dialog box as in Display 8.2.1 ¯ ¯ ¯ produces the output Sample X N Sample p 1 49 61 0.803279 2 38 62 0.612903 Estimate for p(1) - p(2): 0.190375 95% CI for p(1) - p(2): (0.0333680, 0.347383) Test for p(1) - p(2) = 0 (vs not = 0): Z = 2.38 P-Value = 0.017 in the Session window. The P -value is .017, so we would deÞnitely reject. A 95% conÞdence interval for p1 − p2 is given by (0.0333680, 0.347383). If other tests or conÞdence intervals are required, then these are available via the Options ¯ button. The Wilson estimates and associated conÞdence interval are obtained from the software by modifying the data as indicated above. Power calculations and minimum sample sizes to achieve a prescribed power can be obtained using Power and Sample Size I 2 Proportions. ¯ ¯ Display 8.2.1: Dialog box for inferences comparing two proportions. 132 8.3 Chapter 8 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. Don’t forget to quote standard errors for any approximate probabilities you quote in the following problems. 1. Carry out a simulation with the Binomial(40, .3) distribution to assess the coverage of the 95% conÞdence interval for a single proportion. 2. The accuracy of a conÞdence interval procedure can be assessed by computing probabilities of covering false values. Approximate the probabilities of covering the values .1, .2, ..., .9 for the 95% conÞdence interval for a single proportion when sampling from the Binomial(20, .5) distribution. 3. Calculate the power of the two-sided test for testing H0 : p = .5 at level α = .05 at the points n = 100, p = .1, ..., 9 and plot the power curve. 4. Carry out a simulation with the Binomial(40, .3) and the Binomial(50, .4) distribution to assess the coverage of the 95% conÞdence interval for a diﬀerence of proportions. 5. Calculate the power of the two-sided test for testing H0 : p1 = p2 versus Ha : p1 6= p2 at level α = .05 at n1 = 40, p1 = .3, n2 = 50, p2 = .1, ..., 9 and plot the power curve. Chapter 9 Inference for Two-Way Tables New Minitab commands discussed in this chapter Stat I Tables I Chi-Square Test ¯ ¯ ¯ Stat I Tables I Cross Tabulation and Chi-Square ¯ ¯ ¯ In this chapter, inference methods are discussed for comparing the distributions of a categorical variable for a number of populations and for looking for relationships among a number of categorical variables deÞned on a single population. The chi-square test is the basic inferential tool, and this is implemented in Minitab via the Stat I Tables I Cross Tabulation and Chi-Square command, if ¯ ¯ ¯ the data is in the form of raw incidence data, or the Stat I Tables I Chi-Square ¯ ¯ Test command, if the data comes in the form of counts. ¯ 9.1 Tabulating and Plotting The relationship between two categorical variables is typically assessed by crosstabulating the variables in a table. For this, the Stat I Tables I Cross Tab¯ using an ¯ example ulation and Chi-Square command is available. We¯ illustrate where each categorical variable takes two values. Of course, each variable can take a number of values, and this need not be the same for each categorical variable. Suppose that we have collected data on courses being taken by students and have recorded a 1 in C2 if the student is taking Statistics and a 0 if not. If the student is taking Calculus, a 1 is recorded in C3 and a 0 otherwise. Also, we have recorded the student number in C1. These data for 10 students follow. 133 134 Chapter 9 Row 1 2 3 4 5 6 7 8 9 10 C1 12389 97658 53546 55542 11223 77788 44567 32156 33456 67945 C2 1 1 0 0 1 0 1 1 0 0 C3 0 0 1 1 1 0 1 0 1 1 We cross-tabulate the data in C2 and C3 using the Stat I Tables I Cross ¯ ¯ ¯ Tabulation and Chi-Square command and the dialog box shown in Display 9.1.1. Display 9.1.1: Dialog box for producing tables. This produces the output Rows: 0 1 All C2 Columns: C3 0 1 All 1 3 4 4 2 6 5 5 10 Cell Contents -Count in the Session window that reveals there is 1 student taking neither Statistics nor Calculus, 4 students taking Calculus but not Statistics, 3 students taking Inference for Two-Way Tables 135 Statistics but not Calculus, and 2 students taking both subjects. The row marginal totals are produced on the right, and the column marginal totals are produced below the table. We have chosen the cell entries in the table to be frequencies (counts), but we can see from Display 9.1.1 that there are other choices. For example, if we had checked the Total percents box instead, we obtain the output Rows: 0 1 All C2 Columns: 0 1 10.00 30.00 40.00 40.00 20.00 60.00 C3 All 50.00 50.00 100.00 Cell Contents -% of Tbl where each entry is the percentage that cell represents of the total number of observations used to form the table. Of course, we can ask for more than just one of these cell statistics to be produced in a table. To examine the relationship between the two variables, we compare the conditional distributions given row, by checking the Row percents box, or the conditional distributions given column, by checking the Column percents box. For example, choosing to calculate row percents gives us the table Rows: 0 1 All C2 Columns: C3 0 1 All 20.00 60.00 40.00 80.00 40.00 60.00 100.00 100.00 100.00 Cell Contents -% of Row that gives the row distributions as 20%, 80% for the Þrst row and 60%, 40% for the second row. So it looks as if there is a strong relationship between the variable indicating whether or not a student takes Statistics and the variable indicating whether or not a student takes Calculus. For example, a student who does not take Statistics is more likely to take Calculus than a student who does take Statistics. Of course, this is not a real data set, and it is small at that. So, in reality, we could expect a somewhat diﬀerent conclusion. Some graphical techniques are also available for this problem. In Figure 9.1.1, we have plotted the conditional distributions given row in a bar chart using the command Graph I Bar Chart in Version 14. This in turn leads to the ¯ where we have selected Cluster. This leads dialog box shown in ¯Display 9.1.2, 136 Chapter 9 to the dialog box shown in Display 9.1.3, where we have entered the variables C2, C3 in the Categorical variables box (note order) and then clicked on Bar Chart Options to bring up the dialog box shown in Display 9.1.4. Here we have indicated that we want to display the distributions as percents. These plots are an evocative way to display the relationship between the variables. Chart of C2, C3 90 80 70 Percent 60 50 40 30 20 10 0 C3 C2 0 1 0 0 1 1 Percent within levels of C2. Figure 9.1.1: Conditional distributions of columns given row. Display 9.1.2: Dialog box for selecting type of bar chart. Inference for Two-Way Tables 137 Display 9.1.3: Dialog box for choosing variables to graph in bar chart. Display 9.1.4: Dialog box for selecting options for the bar chart. In Version 13 we use the command Graph I Charts and Þll in the dialog box ¯ ¯ so that Function is Count, the Y -variable is C3, the X-variable is C2, Display ¯ is Bar, and under Options we selected Cluster with variable C3 and Total Y to 100% within each ¯X-category. The bars for C3 are ordered according to the increasing value of C2. If you would rather there be a single bar for each category of the X-variable and this bar be subdivided according to the conditional distribution of the Y -variable, then, rather than Cluster with variable Y , use Stack with variable Y . The corresponding session command is table and there are the subcommands totpercents, rowpercents, and colpercents to specify whether or not we want total percents, row percents, and column percents to be printed for each cell. For example, MTB > table c2 c3 138 Chapter 9 produces the table of counts shown previously. If you do not want the marginal statistics to be printed, use the noall subcommand. Any cases with missing values are not included in the cross-tabulation. If you want them to be included, use the missing subcommand and a row or column is printed, whichever is relevant, for missing values. For example, the subcommand SUBC> missing c2 c3; ensures that any cases with missing values in C2 or C3 are also tabulated. 9.2 The Chi-square Test If you have a single variable, you can use the Stat I Tables I Cross Tabulation ¯ ¯ ¯ command to form the table of counts if your data is not in this form. To carry out a chi-square goodness-of-Þt test, however, you will have to use Minitab commands to directly compute the chi-square statistic X2 = X (observed count in cell − expected count in cell)2 expected count in cell cell and the P -value given by the probability P (Y > X 2 ) where Y follows a Chi-square(k) distribution based on an appropriate degrees of freedom k as determined by the table and the model being Þtted. This is an approximate distribution result. Recall that the Chi-square(k) distribution was discussed in II.6.5. When we have more than one variable and we are interested in whether or not a relationship exists, there are Minitab commands to carry out the chisquare analysis. Recall that there is no relationship between the variables–i.e., the variables are independent–if and only if the conditional distributions of one variable given the other are all the same. So in a two-way table we can assess whether or not there is a relationship by comparing the conditional distributions of the columns given the rows. Of course, there will be diﬀerences in these conditional distributions simply due to sampling error. Whether or not these diﬀerences are signiÞcant is assessed by conducting a chi-square test. When the table has r rows and c columns and we are testing for independence, then k = (r − 1)(c −1). Note that for a cell the square of a cell’s standardized residual is that cell’s contribution to the chi-square statistic, namely 2 (observed count in cell − expected count in cell) expected count in cell For example, suppose for 60 cases we have a categorical variable in C1 taking the values 0 and 1 and a categorical variable in C2 taking the values 0, 1 and 2. Suppose further that the Stat I Tables I Cross Tabulation and Chi-Square ¯ as in ¯Display 9.2.1 ¯ command with the dialog box Inference for Two-Way Tables 139 Display 9.2.1: Dialog box for cross-tabulating categorical variables. produced the table Rows: 0 1 All C1 Columns: C2 0 1 2 All 10 9 19 13 10 23 11 7 18 34 26 60 Cell Contents -Count in the Session window. This records the counts in the 6 cells of a table, with C1 indicating row and C2 indicating column. The variable C1 could be indicating a population with C2 a categorical variable deÞned on each population (or conversely), or both variables could be deÞned on a single population. When using the Stat I Tables I Cross Tabulation and Chi-Square com¯ ¯ ¯ mand, a chi-square analysis can be carried out by clicking the Chi-Square analysis box in the dialog box of Display 9.2.1 as this brings up the dialog box shown in Display 9.2.2 where we have checked the Chi-square analysis box. Display 9.2.2: Dialog box for carrying out a chi-square analysis. 140 Chapter 9 The remaining boxes give additional options concerning what is printed in the Session window. We have chosen to have only the cell count printed for each cell in addition to the chi-square statistic and its associated P -value. Clicking on the OK button in this dialog box leads to the output Rows: C1 Columns: C2 0 1 2 All 0 10 13 11 34 1 9 10 7 26 All 19 23 18 60 Chi-Square = 0.271, DF = 2, P-Value = 0.873 Cell Contents -Count being printed in the Session window. The P -value for testing the null hypothesis that these two categorical variables are independent against the alternative that they are not independent is .873, and so we do not reject the null hypothesis. It is possible to cross-tabulate more than two variables and to test simultaneously for mutual statistical independence among the variables using the Stat ¯ I Tables I Cross Tabulation and Chi-Square command. Recall that it is also ¯ ¯ a good idea to plot the conditional distributions as well. The general syntax of the corresponding session command table command is table E1 . . . Em ; chisquare V. where E1 , ..., Em are columns containing categorical variables and V is either omitted or takes the value 1, 2, or 3. The value 1 is the default and causes the count to be printed in each cell and can be omitted. The value 2 causes the count and the expected count, under the hypothesis of independence, to be printed in each cell. The value 3 causes the count, the expected count, and the standardized residual to be printed in each cell. For example, the command MTB > table c1 c2; SUBC> chisquare. also produces the above output. 9.3 Analyzing Tables of Counts If you have a two-way cross-tabulation for which the cell counts are already tabulated, you can use the Stat I Tables I Chi-Square Test command on this ¯ ¯ ¯ data to carry out the chi-square analysis. For example, suppose we put the following data in columns C1—C3 as Inference for Two-Way Tables Row 1 2 3 C1 51 92 68 C2 22 21 9 141 C3 43 28 22 corresponding to the counts arising from the cross-classiÞcation of a row and column variable. We then use the command Stat I Tables I Chi-Square Test ¯ ¯ ¯ on this data with the dialog box as shown in Display 9.3.1. Display 9.3.1: Dialog box for chi-square test on a table of counts. This produces the output Expected counts are C1 C2 1 51 22 68.75 16.94 4.584 1.509 2 92 21 83.57 20.60 0.850 0.008 3 68 9 58.68 14.46 1.481 2.062 Total 211 52 Chi-Sq = 18.510, DF printed below observed counts C3 Total 43 116 30.30 5.320 28 141 36.83 2.119 22 99 25.86 0.577 93 356 = 4, P-Value = 0.001 in the Session window. The chi-square statistic has the value 18.51 in this case and the P -value is .001, so we reject the null hypothesis that there is no relationship between the row and column variables. 142 Chapter 9 The general syntax of the corresponding session command chisquare command is chisquare E1 . . . Em and this computes the expected cell counts, the chi-square statistic, and the associated P -value for the table in columns E1 , ..., Em . Note that there is a limitation on the number of columns; namely we must have m ≤ 7. For example, the command MTB > chisquare c1-c3 produces the above chi-square analysis. 9.4 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. Suppose that the observations in the following table are made on two categorical variables where variable 1 takes 2 values and variable 2 takes 3 values. Using the Stat I Tables I Cross Tabulation and Chi-Square com¯ ¯ ¯ mand, cross-tabulate this data in a table of frequencies and in a table of relative frequencies. Calculate the conditional distributions of variable 1, given variable 2. Plot the conditional distributions. Is there any indication of a relationship existing between the variables? How many conditional distributions of variable 2, given variable 1, are there? Obs Var 1 Var 2 1 0 2 2 0 1 3 0 0 4 1 0 5 1 2 6 0 1 7 1 2 8 0 0 9 0 1 10 1 1 2. (9.1) Use Minitab commands to calculate the marginal distributions and the conditional distributions, given Age group. Note that you cannot use Stat I Tables I Cross Tabulation and Chi-square for this. Plot the ¯ ¯ ¯ conditional distributions. 3. Use Minitab to directly compute the expected frequencies, standardized residuals, chi-square statistic, and P -value for the hypothesis of independence in the table of Example 9.16 in IPS. 4. (9.12) Carry out a chi-square analysis to determine whether or not the variables in this problem are related. Plot bar charts of the conditional distributions. Make sure you use the same scale on each plot so that they are comparable. Inference for Two-Way Tables 143 5. (9.13) Calculate and compare the conditional distributions of motivation given gender. Plot these conditional distributions in bar charts. Carry out a chi-square analysis to determine whether or not the variables in this problem are related. 6. Suppose we have a discrete distribution on the integers 1, . . . , k with probabilities p1 , . . . , pk . Further, suppose we take a sample of n from this distribution and record the counts f1 , . . . , fk , where fi records the number of times we observed i. It can be shown that P (f1 = n1 , . . . , fk = nk ) = n! pn1 · · · pnk k n1 ! · · · nk ! 1 when the ni are nonnegative integers that sum to n. This is called the Multinomial(n, p1 , . . . , pk ) distribution, and it is a generalization of the Binomial(n, p) distribution. It is the relevant distribution for describing the counts in cross-tabulations. For k = 4, p1 = p2 = p3 = p4 = .25, n = 3, calculate these probabilities and verify that it is a probability distribution. Note that the gamma function is available with the Calc I Calculator ¯ ¯ command (see Appendix B.1), and this can be used to evaluate factorials such as n! and also 0! = 1. 7. Calculate P (f1 = 3, f2 = 5, f3 = 2) for the Multinomial(10, .2, .5, .3) distribution. 8. Generate (f1 , f2 , f3 ) from the Multinomial(1000, .2, .4, .4) distribution. Hint: Generate a sample of 1000 from the discrete distribution on 1, 2, 3 with probabilities .2, .4 , .4, respectively. 144 Chapter 9 Chapter 10 Inference for Regression New Minitab command discussed in this chapter Stat I Regression I Residual Plots ¯ ¯ ¯ This chapter deals with inference for the simple regression model. A regression analysis can be carried out using the command Stat I Regression I Regression. ¯ ¯ ¯ The regression as well as a scatterplot with the least-squares line overlaid can be obtained via Stat I Regression I Fitted Line Plot. Some aspects of these ¯ ¯ ¯ commands were discussed in II.2.3. Residual plots can be obtained using Stat ¯ I Regression I Residual Plots, provided you have saved the residuals. ¯ ¯ 10.1 Simple Regression Analysis The command Stat I Regression I Regression provides a Þt of the model ¯ ¯ ¯ y = α + βx + N. Here, y is the response variable, x is the explanatory or predictor variable, N is the error variable with an N (0, σ) distribution, and α, β, and, σ are Þxed unknown constants. These assumptions imply that, given x, the distribution of y is distributed N (α + βx, σ). So the mean of y given x is α + βx, and this gives the relationship between y and x, i.e., as x changes at most the mean of the conditional distribution of y given x changes according to the linear function α + βx. The primary aim of a regression analysis is to make inferences about the unknown intercept α and the unknown slope β and to make predictive inferences about future values of y at possibly new values of x. All inferences are dependent on this model being correct. If we go ahead and report inferences when the model is incorrect, we run the risk of these inferences being invalid. So we must always check that the model makes sense in light of the data obtained. This is referred to as model checking. 145 146 Chapter 10 We let (x1 , y1 ) , . . . , (xn , yn ) denote the data on which we will base all our inferences. The basic inference method for this model is to use least-squares to estimate α and β, and we denote these estimates by a and b, respectively, i.e., a and b are the values of α and β that minimize S2 = n X i=1 (yi − α − βxi )2 . We predict the value of a future y, when the explanatory variable takes the value x, by ŷ = a + bx. The ith Þtted value ŷi is the estimate of the mean of y at xi ; i.e., ŷi = a + bxi . The ith residual is given by ri = yi − ŷi , i.e., it is the error incurred when predicting the value of y at xi by ŷi . We estimate the standard deviation σ by v v u u n n u 1 X u 1 X 2 t s= (yi − ŷi ) = t r2 n − 2 i=1 n − 2 i=1 i which equals the square root of the MSE (mean-squared error) for the regression model. Of course, the estimates a, b, and ŷ are not equal to the quantities that they are estimating. It as an important aspect of a statistical analysis to say something about how accurate these estimates are, and for this we use the standard error of the estimate. The standard error of a is given by s x̄2 1 + Pn s 2. n i=1 (xi − x̄) The standard error of b is given by s s Pn 1 i=1 (xi − x̄)2 . The standard error of the estimate a + bx of the mean α + βx is given by s (x − x̄)2 1 + Pn s 2. n i=1 (xi − x̄) To predict y at x, we must take into account the additional variation caused by the error N, and so the standard error of a + bx, as a predictor of y at x, is given by s (x − x̄)2 1 s 1 + + Pn 2. n i=1 (xi − x̄) Finally, the residual ri , as an estimate of the error incurred at xi , has standard error Inference for Regression 147 s s 1− (xi − x̄)2 1 − Pn 2. n i=1 (xi − x̄) The ith standardized residual is then given by ri divided by this quantity. We now illustrate regression analysis using Minitab. Suppose we have the following data points (x1 , y1 ) = (1966, 73.1) (x2 , y2 ) = (1976, 88.0) (x3 , y3 ) = (1986, 119.4) (x4 , y4 ) = (1996, 127.1) where x is year and y is yield in bushels per acre and that we give x the name year and y the name yield. The Stat I Regression I Fitted Line Plot ¯ year as ¯ predictor produces ¯ command with yield as the response and the plot of Display 10.1.1 Fitted Line Plot yield = - 3729 + 1.934 year S R-Sq R-Sq(adj) 130 6.84697 95.2% 92.8% 120 yield 110 100 90 80 70 1965 1970 1975 1980 1985 year 1990 1995 2000 Display 10.1.1: Scatterplot of the data together with the least-squares line. The Stat I Regression I Fitted Line Plot command also produces some of ¯ ¯ ¯ the Session window output below in the Session window. Because we wanted more features of a regression analysis than this command provides, we resorted to the Stat I Regression I Regression command together with the dialog boxes ¯ ¯ ¯ as in Displays 10.1.2, 10.1.3, 10.1.4, and 10.1.5. 148 Chapter 10 Display 10.1.2: Dialog box for simple regression analysis. Display 10.1.3: Dialog box for selecting graphs to be plotted in regression analysis. Display 10.1.4: Dialog box for selecting predictive inferences in a regression analysis. Inference for Regression 149 Display 10.1.5: Dialog box for selecting quantities to be stored in a regression analysis. These entries in the dialog boxes produce the output Regression Analysis The regression equation is yield = - 3729 + 1.93 year Predictor Coef StDev T P Constant -3729.4 606.6 -6.15 0.025 year 1.9340 0.3062 6.32 0.024 S = 6.847 R-Sq = 95.2% R-Sq(adj) = 92.8% Analysis of Variance Source DF SS MS F P Regression 1 1870.2 1870.2 39.89 0.024 Residual Error 2 93.8 46.9 Total 3 1963.9 Predicted Values Fit StDev Fit 95.0% CI 95.0% PI 150.25 8.39 (114.17, 186.33) (103.67, 196.83) X X denotes a row with X values away from the center in the Session window. The dialog box of Display 10.1.2 establishes that yield is the response and year is the explanatory variable. The output from this gives the least-squares line as y = −3729 + 1.93x. Further, the standard error of b0 = −3729.4 is 606.6, the standard error of b1 = 1.934 is 0.3062, the t statistic for testing H0 : β0 = 0 versus Ha : β0 6= 0 is −6.15 with P -value 0.025, and the t statistic for testing H0 : β1 = 0 versus Ha : β1 6= 0 is 6.32 with P -value 0.024. The estimate of σ is s = 6.847 and the squared correlation–coeﬃcient of determination–is R2 = .952, indicating that 95% of the observed variation in y is explained by the changes in x. The Analysis of Variance table indicates that the F statistic for testing H0 : β1 = 0 versus Ha : β1 6= 0 is 39.89 with P -value 0.024 and the MSE is 46.9. So we deÞnitely reject the null hypothesis that there is no relationship between the response and the predictor. 150 Chapter 10 Before clicking on the OK button of the dialog box of Display 10.1.2, however, we clicked on the Graphs button to bring up the dialog box of Display 10.1.3, the Options button to bring up the dialog box of Display 10.1.4, and the Storage ¯ button to bring up the dialog box of Display 10.1.5. In the Graphs dialog box, we speciÞed that we want the standardized residuals plotted in a normal probability plot and plotted against the variable year. These plots appear in Displays 10.1.6 and 10.1.7, respectively, and don’t indicate that any model assumptions are being violated. Normal Probability Plot of the Residuals (response is yield) 99 95 90 Percent 80 70 60 50 40 30 20 10 5 1 -3 -2 -1 0 1 Standardized Residual 2 3 Display 10.1.6: Normal probability plot of the standardized residuals. Residuals Versus year (response is yield) Standardized Residual 1.5 1.0 0.5 0.0 -0.5 -1.0 1965 1970 1975 1980 1985 1990 1995 2000 year Display 10.1.7: A plot of the standardized residuals versus the explanatory variable. In the Options dialog box, we speciÞed that we wanted to estimate the mean value of y at x = 2006 and report and store this value together with a 95% conÞdence interval for this quantity and a 95% prediction interval for this quantity. The output above gives the estimated mean value at x = 2006 as 150.25 with standard error 8.39, and the 95% conÞdence and prediction intervals for this quantity are (114.17, 186.33) and (103.67, 196.83), respectively. The estimate is stored in the worksheet in a variable called pfit1, and the endpoints of the conÞdence and prediction intervals are stored in the worksheet with the Inference for Regression 151 names clim1, clim2, plim1, plim2, respectively. In the Storage dialog box, we speciÞed that we wanted to store the values of a and b, the Þtted values, the residuals and the standardized residuals. The residuals are stored in a variable called resi1, the standardized residuals are stored in a variable called sres1, the values of a and b are stored consecutively in a variable named coefs1, and the Þtted values are stored in a variable called fits1. All of the stored quantities are available for further use. Suppose we want a 95% conÞdence interval for b. The commands MTB > invcdf .975; SUBC> student 2. Student’s t distribution with 2 DF P( X <= x) x 0.9750 4.3027 MTB > let k2=4.3027*.3062 MTB > let k3=coef1(2)-k2 MTB > let k4=coef1(2)+k2 MTB > print k3 k4 K3 0.616513 K4 3.25149 gives this interval as (0.617, 3.251). The general syntax of the corresponding session command regress command for Þtting a line is regress E1 1 E2 where E1 contains the values of the response variable y and E2 contains the values of the explanatory variable x. There are a number of subcommands that can be used with regress, and these are listed and explained below. coeﬃcients E1 – stores the estimates of the coeﬃcients in column E1 . constant (noconstant) – ensures that β0 is included in the regression equation, while noconstant Þts the equation without β0 . Þts E1 – stores the Þtted values ŷ in E1 . ghistogram – causes a histogram of the residuals speciÞed in rtype to be plotted. gÞts – causes a plot of the residuals speciÞed in rtype versus the Þtted values to be plotted. gnormal – causes a normal quantile plot of the residuals speciÞed in rtype to be plotted. gorder – causes a plot of the residuals speciÞed in rtype versus order to be plotted. gvariable E1 – causes a plot of the residuals speciÞed in rtype versus the explanatory variable in column E1 to be plotted. 152 Chapter 10 mse E1 – stores the mean squared error in constant E1 . predict E1 . . . Ek – (k is the number of explanatory variables where k = 1 with simple linear regression) computes and prints the predicted values at E1 , ..., Ek , where these are columns of the same length or constants with Ei corresponding to the ith explanatory variable. Also, this prints the estimated standard deviations of these values, conÞdence intervals for these values, and prediction intervals. The subcommand predict in turn has a number of subcommands. conÞdence V – V speciÞes the level for the conÞdence intervals. pÞts E1 – stores the predicted values in E1 . psdÞts E1 – stores the estimated standard deviations of the predicted values in E1 . climits E1 E2 – stores the lower and upper conÞdence limits for the predicted values in E1 and E2 , respectively. plimits E1 E2 – stores the lower and upper prediction limits for the predicted values in E1 and E2 , respectively. residuals E1 – stores the regular residuals in E1 . rtype V – indicates what type of residuals are to be used in the plotting subcommands, where V = 1 is the default and speciÞes regular residuals, V = 2 speciÞes standardized residuals, and V = 3 speciÞes Studentized deleted residuals. sresiduals E1 – stores the standardized residuals–the residuals divided by their estimated standard deviations–in E1 . For example, the session commands MTB > SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> regress ’yield’ 1 ’year’; coefficients c3; mse k1; fits c4; residuals c5; sresiduals c6; rtype 2; gnormal; gvariable ’year’; predict 2006; pfits c7; climits c8 c9; plimits c10 c11. produce the same results as the menu commands with the dialog boxes as in Displays 10.1.2, 10.1.3, 10.1.4, and 10.1.5 for the example of this section. Inference for Regression 10.2 153 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. In C1, place the x values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N(0, 2). In C3, store the values y = β0 + β1 x + N = 1 + 3x + N. Calculate the least-squares estimates of β0 and β1 and the estimate of σ 2 . Repeat this example but take 5 observations at each value of x. Compare the estimates from the two situations and their estimated standard deviations. 2. In C1, place the x values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N(0, 2). In C3, store the values y = β0 + β1 x + N = 1 + 3x + N. Plot the least-squares line. Repeat your computations twice after changing the Þrst y observation to 20 and then to 50, and make sure the scales on all the plots are the same. What eﬀect do you notice? 3. In C1, place the x values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N(0, 2). In C3, store the values y = β0 + β1 x + N = 1 + 3x + N. Plot the standardized residuals in a normal quantile plot against the Þtted values and against the explanatory variable. Repeat this, but in C3 place the values of y = 1 + 3x − 5x2 + N. Compare the residual plots. 4. In C1, place the x values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N (0, 2). In C3, store the values y = β0 + β1 x + N = 1 + 3x + N. Plot the standardized residuals in a normal quantile plot against the Þtted values and against the explanatory variable. Repeat this, but in C2 place the values of a sample of 13 from the Student(1) distribution. Compare the residual plots. 5. In C1, place the x values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N(0, 2). In C3, store the values y = β0 + β1 x + N = 1 + 3x + N. Calculate the predicted values and the lengths of .95 conÞdence and prediction intervals for this quantity at x = .1, 1.1, 2.1, 3.5, 5, 10, and 20. Explain the eﬀect that you observe. 6. In C1, place the x values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N(0, 2). In C3, store the values y = β0 + β1 x + N = 1 + 3x + N. Calculate the least-squares estimates and their estimated standard deviations. Repeat this, but for C1 the x values are to be 12 values of −3 and one value of 3. Compare your results and explain them. 154 Chapter 10 Chapter 11 Multiple Regression In this chapter, we discuss multiple regression; i.e., we have a single numeric response variable y and k > 1 explanatory variables x1 , . . . , xk . There are no real changes in the behavior of the Stat I Regression I Regression command, ¯ and the descriptions we gave in Chapter 10¯ apply to this¯ chapter as well. We present an example of a multiple regression analysis using Minitab. A multiple regression analysis can be carried out using Stat I Regression ¯ ¯ I Regression and Þlling in the dialog box appropriately. Residual plots can be ¯ obtained using Stat I Regression I Residual Plots provided you have saved ¯ ¯ ¯ the residuals. Also available in Minitab are stepwise regression using Stat I ¯ Regression I Regression I Stepwise and best subsets regression using Stat I ¯ ¯ ¯ ¯ Regression I Regression I Best Subsets. ¯ ¯ ¯ 11.1 Example of a Multiple Regression We consider a generated multiple regression example to illustrate the use of the Stat I Regression I Regression command in this context. Suppose that k = 2 ¯ ¯ ¯ and y = β0 + β1 x1 + β2 x2 + N = 1 + 2x1 + 3x2 + N, where N is distributed N(0, σ) with σ = 1.5. We generated a sample of 16 from the N(0, 1.5) distribution and placed these values in C1. In C2 we stored the values of x1 and in C3 stored the values of x2 . Suppose that these variables take every possible combination of x1 = −1, −.5, .5, 1 and x2 = −2, −1, 1, 2. In C4, we placed the values of the response variable y. We then proceeded to analyze this data as if we didn’t know the values of β0 , β1 , β2 , and σ. The Stat I Regression I Regression command as implemented ¯ ¯ ¯ in Display 11.1.1, together with Displays 11.1.2 and 11.1.3, 155 156 Chapter 11 Display 11.1.1: Dialog box for the Stat IRegression IRegression command in the ¯ ¯ ¯ example. Display 11.1.2: Dialog box obtained by clicking on the Storage button in the dialog ¯ box depicted in Display 11.1.1. We have requested that the least-squares coeﬃcients be stored. Display 11.1.3: Dialog box obtained by clicking on the Options button in the dialog box depicted in Display 11.2.1. We have requested that a value be predicted at the settings x1 = 0, x2 = 0. produces the output Multiple Regression 157 The regression equation is C4 = 1.00 + 2.38 C2 + 2.50 C3 Predictor Constant C2 C3 Coef 1.0014 2.3807 2.4964 StDev 0.3307 0.4183 0.2092 T 3.03 5.69 11.94 P 0.010 0.000 0.000 S = 1.323 R-Sq = 93.1% R-Sq(adj) = 92.0% Analysis of Variance Source DF Regression 2 Residual Error 13 Total 15 Source C2 C3 DF 1 1 SS 305.95 22.75 328.70 MS 152.98 1.75 F 87.42 P 0.000 Seq SS 56.68 249.28 Unusual Observations Obs C2 C4 Fit StDev Fit Residual St Resid 6 -0.50 -5.574 -2.685 0.444 -2.889 -2.32R R denotes an observation with a large standardized residual Predicted Values Fit StDev Fit 1.001 0.331 95.0% CI (0.287, 1.716) 95.0% PI (-1.944, 3.947) Values of Predictors for New Observations New Obs 1 C2 0.000000 C3 0.000000 This speciÞes the least-squares equation as y = 1.00 + 2.38x1 + 2.50x2 . For example, the estimate of β1 is b1 = 2.3807 with standard error 0.4183 and the t statistic for testing H0 : β1 = 0 versus Ha : β1 6= 0 is 5.69 with P -value 0.000. The estimate of σ is s = 1.323 and R2 = .931. The Analysis of Variance table indicates that the F statistic for testing H0 : β1 = β2 = 0 versus Ha : β1 6= 0 or β2 6= 0 takes the value 87.42 with P -value 0.000 so we would deÞnitely reject the null hypothesis. Also, the MSE is given as 1.75. The table after the Analysis of Variance table is called the Sequential Analysis of Variance table and is used when we want to test whether or not explanatory variables are in the model in a prescribed order. For example, the table that contains the rows labeled C2 and C3 allows for the testing of the sequence of hypotheses H0 : β2 = 0 versus Ha : β2 6= 0 and–if we reject this (and only if we do) – then testing the hypothesis H0 : β1 = 0 versus Ha : β1 6= 0. To test these hypotheses, we Þrst compute F = 249.28/s2 = 249.28/1.75 = 142.45 and then compute the P -value P (F (1, 13) > 142.45) = 0.00, and so we reject and go no further. If we had not rejected this null hypothesis, the second null hypothesis would be tested in exactly the same way. Obviously, the order in which we put variables into the model matters with these sequential tests. Sometimes, it 158 Chapter 11 is clear how to do this; e.g., in Þtting a quadratic model y = β0 + β1 x + β2 x2 + N we put x1 = x and x2 = x2 and test for the existence of the quadratic term Þrst and, if no quadratic term is found, test for the existence of the linear term. Sometimes, the order for testing is not as clear and the sequential tests are not as appropriate. The dialog box in Display 11.1.2 is obtained by clicking on the Storage button in the dialog box of Display 11.1.1. We stored the values of the least-squares estimates in C5, as the dialog box in Display 11.1.2 indicates, and so these are available for forming conÞdence intervals. Then, for example, the commands MTB > invcdf .95; SUBC> student 13. Student’s t distribution with 13 DF P(X <= x) x 0.9500 1.7709 MTB > let k1=1.7709*.2092 MTB > let k2=c5(3)-k1 MTB > let k3=c5(3)+k1 MTB > print k2 k3 K2 2.12590 K3 2.86685 compute a 90% conÞdence interval for β2 as (2.126, 2.869), which we note does not cover the true value in this case. The dialog box in Display 11.1.3 is obtained by clicking on the Options button in the dialog box of Display 11.1.1. The dialog box in Display 11.1.3 indicates that we requested that the program compute the predicted value at x1 = 0, x2 = 0 as well as the conÞdence and prediction intervals for this value. We obtained the predicted value as 1.001 with standard error .331 and as well the 95% conÞdence and prediction intervals given by (0.287, 1.716) and (−1.944, 3.947), respectively. Further, these limits were stored in the columns C6—C9. The dialog box in Display 11.1.4 is obtained by clicking on the Graphs button in the dialog box of Display 11.1.1. Here we requested a normal quantile plot of the standardized residuals, which we show in Display 11.1.5, and also requested plots of the standardized residuals against each of the explanatory variables, which we don’t show. All of these plots look reasonable although we note that the software has identiÞed the sixth observation as having a large standardized residual even though we know that the model is correct. Of course, 16 is not many data points so we can expect inference to be somewhat unreliable in this case. Multiple Regression 159 Display 11.1.4: Dialog box obtained by clicking on the Graphs button in the dialog box depicted in Display 11.1.1. Display 11.1.5: Normal probability plot of the standardized residuals for the example. The following session commands produce the above output for the example of this section. MTB > SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> SUBC> regress c4 2 c2 c3; coefficients c5; rtype 2; gnormal; gvariable C2 C3; predict 0 0; climits c6 c7; plimits c8 c9. 160 Chapter 11 We can also control the amount of output obtained from the Stat I Regression ¯ ¯ I Regression command. This is accomplished by clicking on the Results button ¯ of the dialog box shown in Display 11.1.1 bringing up Display 11.1.6. Display 11.1.6: Dialog box obtained by clicking on the Results button in the dialog box depicted in Display 11.1.1. We have requested that, in addition to the Þtted regression equation, least squares coeﬃcients, s, R2 , and ANOVA table, the table of sequential sums of squares (for the order in which the variables appear in the model) and a table of unusual observations be printed. The session command to control the amount output from the regress and other Minitab commands is brief . The general syntax of the brief command is brief V where V is a nonnegative integer that controls the amount of output. For any given command the output is dependent on the speciÞc command although V = 0 suppresses all output, for all commands, beyond error messages and warnings. The default level of V is 2. When V = 3, the regress command produces the usual output and in addition prints x, y, ŷ, the standard deviation of ŷ, y − ŷ and the standardized residual. When V = 1, the regress command gives the same output as when V = 2 but the sequential analysis of variance table is not printed. Don’t forget that after you set the level of brief, this may aﬀect the output of all commands you subsequently type and therefore it may need to be reset. 11.2 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. Multiple Regression 161 1. In C1, place the x1 values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N(0, 2). In C3, store the values of x2 = x2 . In C4 store the values of y = β0 + β1 x1 + β2 x2 + N = 1 + 3x + 5x2 + N. Calculate the least-squares estimates of β0 , β1 , and β2 and the estimate of σ2 . Carry out the sequential F tests testing Þrst for the quadratic term and then, if necessary, testing for the linear term. 2. In C1, place the x values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N(0, 2). Fit the model y = 1 + 3 cos(x) + 5 sin(x) + N. Calculate the least-squares estimates of β0 , β1 , and β2 and the estimate of σ 2 . Carry out the F test for any eﬀect due to x. Are the sequential F tests meaningful here? 3. In C1, place the x1 values −3.0, −2.5, −2.0, . . . , 2.5, 3.0. In C2, store a sample of 13 from the error N, where N is distributed N(0, 2). In C3, store the values of x2 = x2 . In C4, store the values of y = 1+3 cos(x)+5 sin(x)+ N. Next Þt the model y = β0 + β1 x1 + β2 x2 + N and plot the standardized residuals in a normal quantile plot and against each of the explanatory variables. 162 Chapter 11 Chapter 12 One-Way Analysis of Variance New Minitab commands discussed in this chapter Stat I ANOVA I One-way ¯ ¯ ¯ Stat I ANOVA I One-way (Unstacked) ¯ ¯ ¯ This chapter deals with methods for making inferences about the relationship existing between a single numeric response variable and a single categorical explanatory variable. The basic inference methods are the one-way analysis of variance (ANOVA) and the comparison of means. There are two commands for carrying out a one-way analysis of variance, namely Stat I ANOVA I One-way ¯ ¯ ¯ and Stat I ANOVA I One-way (Unstacked). They diﬀer in the way the data ¯ ¯ ¯ must be stored for the analysis. We write the one-way ANOVA model as xij = µi + Nij , where i = 1, . . . , I indexes the levels of the categorical explanatory variable and j = 1, . . . , ni indexes the individual observations at each level, µi is the mean response at the ith level, and the errors Nij are a sample from the N(0, σ) distribution. Based on the observed xij , we want to make inferences about the unknown values of the parameters µ1 , . . . , µI , σ 12.1 A Categorical Variable and a Quantitative Variable Suppose that we have two variables, one variable is categorical and one is quantitative, and we want to examine the form of the relationship between these variables. Of course there may not even be a relationship between the variables. We treat the situation where the categorical variable is explanatory and 163 164 Chapter 12 the quantitative variable is the response and examine some basic techniques for addressing this question. To illustrate, we use the data in the following table. Here, we have four diﬀerent colors of insect trap–lemon yellow, white, green, and blue–and the number of insects trapped on six diﬀerent instances of each trap. Board Color Lemon Yellow White Green Blue Insects Trapped 45 59 48 46 38 47 21 12 14 17 13 17 37 32 15 25 39 41 16 11 20 21 14 7 We have read these data into a worksheet so that C1 contains the trap color, with 1 indicating lemon yellow, 2 indicating white, 3 indicating green, and 4 indicating blue, and in C2 we have put the numbers of insects trapped. We calculate the mean number of insects trapped for each trap using the Stat I ¯ Tables I Descriptive Statistics command with the dialog boxes as in Displays ¯ ¯ 12.1.1 and 12.1.2. In the dialog box of Display 12.1.1, we have put C1 into the ClassiÞcation variables box and clicked on the Summaries button to bring up ¯ ¯ the dialog box of Display 12.1.2. In this box, we have put C2 into the Associated variables box and selected Means to indicate that we want the mean of C2 to ¯ be computed for each value of C1. Display 12.1.1: First dialog box for tabulating a quantitative variable by a categorical variable. Display 12.1.2: Second dialog box for tabulating a quantitative variable by a categorical variable. One-Way Analysis of Variance 165 Clicking on the OK buttons produces the output Rows: BoardColor InsectsTrapped Mean 1 2 3 4 All 47.17 15.67 31.50 14.83 27.29 in the Session window. The fact that the means change from one level of C1 to another seems to indicate that there is some relationship between the color of insect trap and the number of insects trapped. As indicated in Display 12.1.1, there are many other statistics, besides the mean, that we could have chosen to tabulate. In Version 13, we use the Stat I Tables I Cross Tabulation command to ¯ ¯ ¯ produce this output. We place BoardColor into the ClassiÞcation variables box and click on the Summaries button to bring up the dialog box of Display 12.1.2 and Þll it in just as we have done there. It is also a good idea to look at a scatterplot of the quantitative variable versus the categorical variable. We can do this with Graph I Scatterplot (Graph ¯ ¯ ¯ I Plot in version 13) and obtain the plot shown in Display 12.1.3. ¯ Display 12.1.3: Scatterplot of number of InsectsTrapped versus BoardColor. Another useful plot in this situation is to create side-by-side boxplots. This can be carried out using the Graph I Boxplot command. In Version 14, the ¯ ¯ dialog box of Display 12.1.4 does this for this data producing the plot shown in Display 12.1.5. In Version 13, the Graph I Boxplot command leads to a dialog ¯ ¯ box like Display 12.1.6, which has been Þlled in appropriately to produce a plot like that shown in Display 12.1.4. 166 Chapter 12 Display 12.1.4: Dialog box for creating side-by-side boxplots. Display 12.1.5: Side-by-side boxplots. Display 12.1.6: Dialog box for creating side-by-side boxplots (Version 13). One-Way Analysis of Variance 167 The session command table can also be used for creating the tables we have described in this section. For example, for the example as described above, the commands MTB > table c1; SUBC> means c2. produce the mean number of insects trapped for each color of trap as given above. Besides the means subcommand, we have medians, sums, minimums, maximums, n (count of the nonmissing values), nmiss (count of the missing values), stdev, stats (equivalent to n, means and stdev), and data (lists the data for each cell). In addition, there is a subcommand proportion with the syntax proportion = V E1 ; which gives the proportion of cases that have the value V in column E1 . 12.2 One-Way Analysis of Variance The data in the table below arose from a study of reading comprehension designed to compare three methods of instruction called basal, DRTA, and strategies. The data comprise scores on a test attained by children receiving each of the methods of instruction. There are 22 observations in each group. This study was conducted by Baumann and Jones of the Purdue School of Education. Method Basal DRTA Strat Scores 4 6 9 12 16 15 14 12 12 8 13 9 12 12 12 10 8 12 11 8 7 9 7 7 12 10 16 15 9 8 13 12 7 6 8 9 9 8 9 13 10 8 8 10 11 7 4 7 7 6 11 14 13 9 12 13 4 13 6 12 6 11 14 8 5 8 We now carry out a one-way analysis of variance on this data to determine if there is any diﬀerence between the mean performances of students exposed to the three teaching methods. For this, we use the Stat I ANOVA I One¯ ¯ ¯ way command. For this example, there are I = 3 levels corresponding to the values Basal, DRTA, and Strat and n1 = n2 = n3 = 22. Suppose that we have the values of the xij in C1 and the corresponding values of the categorical explanatory variable in C2, where Basal is indicated by 1, DRTA by 2, and Strat by 3. The Stat I ANOVA I One-way command together with the dialog ¯ ¯ ¯ boxes shown in Displays 12.2.1, 12.2.2, and 12.2.3 (described below) produce the output Analysis of Variance for C1 Source DF SS MS F P C2 2 20.58 10.29 1.13 0.329 Error 63 572.45 9.09 Total 65 593.03 S = 3.014 R-Sq = 3.47% R-Sq(adj) = 0.41% 168 Chapter 12 Individual 95% CIs For Mean Based on Pooled StDev Level N Mean StDev -----+---------+---------+---------+1 22 10.500 2.972 (---------*----------) 2 22 9.727 2.694 (----------*----------) 3 22 9.136 3.342 (----------*----------) -----+---------+---------+---------+Pooled StDev = 3.014 8.4 9.6 10.8 12.0 Fisher’s pairwise comparisons Family error rate = 0.121 Individual error rate = 0.0500 Critical value = 1.998 Intervals for (column level mean) - (row level mean) 1 2 2 -1.043 2.589 3 -0.452 -1.225 3.180 2.407 in the Session window. The F test in the ANOVA table with a P -value of 0.329 indicates that the null hypothesis H0 : β1 = β2 = β3 would not be rejected. Also, the estimate of σ is given by s = 3.014 and 95% conÞdence intervals are plotted for the individual βi . The dialog box of Display 12.2.1 carries out a one-way ANOVA for the data in C1, with the levels in C2, and puts the ordinary residuals in a variable called resi1 and the Þtted values in a variable called fits1. Note that because we assume a constant standard deviation and the number of observations is the same in each group, the ordinary residuals can be used in place of standardized residuals. Note also that the ith Þtted value in this case is given by the mean of the group to which the observation belongs. Display 12.2.1: Dialog box for one-way ANOVA. The dialog box of Display 12.2.2 is obtained by clicking on the Comparisons button in the dialog box of Display 12.2.1. We use this dialog box to select a One-Way Analysis of Variance 169 multiple comparison procedure. Here we have chosen to use the Fisher multiple comparison method with an individual error rate on the comparisons of 5%. This gives conÞdence intervals for the diﬀerences between the means using s ȳi − ȳj ± s 1 ∗ 1 + t ni nj where s is the pooled standard deviation and t∗ is the 0.975 percentile of the Student distribution with the error degrees of freedom. Note that with an individual 95% conÞdence interval, the probability of not covering the true diﬀerence (the individual error rate) is .05 but the probability of at least one of these three not covering the diﬀerence (the family error rate) is 0.121. If you want a more conservative family error rate, specify a lower individual error rate. For example, an individual error rate of 0.02 speciÞes a family error rate of 0.0516 in this example. We refer the reader to Help for details on the other available multiple comparison procedures. In the output above, we see that a 95% conÞdence interval for β1 − β2 is given by (−1.043, 2.589), and because this includes 0, we conclude that there is no evidence against the null hypothesis H0 : β1 = β2 . We get the same result for the other two comparisons. Given that the F test has already concluded that there is no evidence of any diﬀerences among the means, there is no reason for us to carry out these individual comparisons, and we do it only for illustration purposes here. Display 12.2.2: Dialog box for selecting a multiple comparison procedure in a one-way ANOVA. The dialog box of Display 12.2.3 is obtained by clicking on the Graphs button in the dialog box of Display 12.2.1. We have requested a plot of side-by-side boxplots of the data by level, which results in Display 12.2.4, the normal probability plot of the residuals that appears in Display 12.2.5 and a plot of the residuals against the index in C2 that appears in Display 12.2.6. The residual plots don’t indicate any problems with the model assumptions. 170 Chapter 12 Display 12.2.3: Dialog box for producing plots in a one-way ANOVA. Display 12.2.4: Boxplots for the example. Display 12.2.5: Normal probability plot for the example of this section after Þtting a one-way ANOVA model. Display 12.2.6: Plot of residuals against level for the example of this section after Þtting a one-way ANOVA model. One-Way Analysis of Variance 171 A one-way ANOVA can also be carried out using Stat I ANOVA I One-way ¯ ¯ (Unstacked) and Þlling in the dialog box appropriately. This command is much ¯ more limited in its features than Stat I ANOVA I One-way, however. So if ¯ ¯ ¯ you have a worksheet with the samples for each level in columns, it would seem better in general to use the Data I Stack command (Manip I Stack in Version ¯ ¯ then use Stat I ¯ ANOVA ¯ I One-way. 13) to place the data in one column and ¯ ¯ ¯ Also available are analysis of means (ANOM) plots via Stat I ANOVA I ¯ ¯ Analysis of Means (see Help for details on these) and plots of the means with ¯ error bars (± one standard error of the observations at a level) via Stat I ¯ ANOVA I Interval Plots. Further, we can plot the means joined by lines using ¯ ¯ Stat I ANOVA I Main Eﬀects plots as in Display 12.2.7. The dotted line is ¯ ¯ ¯ the grand mean. Power calculations can be carried out using Stat I Power and ¯ ¯ Sample Size I One-way ANOVA and Þlling in the dialog box appropriately. ¯ Display 12.2.7: Main eﬀects plot for the example of this section. The corresponding session command is given by onewayaov and has the general syntax onewayaov E1 E2 E3 E4 where E1 is a variable containing the responses, E2 is a variable containing indices that indicate group membership, E3 is a variable to hold the residuals, and E4 is a variable to hold the Þtted values. Of course, E3 and E4 can be dropped if they are not needed. There are various subcommands that can be used. The gboxplot subcommand produces side-by-side boxplots. The gnormal subcommand produces a normal probability plot of the residuals. The gvariables E1 subcommand results in a plot of the residuals against the variable E1 . We could also obtain side-by-side dotplots of the data using the gdotplot subcommand, a histogram of the residuals using the ghistogram subcommand, a plot of the residuals against observation order using the gorder subcommand, and a plot of the residuals against the Þtted values using the gÞts subcommand. The Þsher V1 subcommand gives conÞdence intervals for the diﬀerences between the means, where V1 is the individual error rate. Also available for multiple comparisons are the tukey, dunnett, and mcb subcommands. For example, the commands 172 Chapter 12 MTB > onewayaov c1 c2 c3 c4; SUBC> gboxplot; SUBC> gnormal; SUBC> gvariable c2; SUBC> fisher. result in the same output as we produced for the example of this section using the menu commands. Here the Þts are stored in C4 and the residuals are stored in C3. The aovoneway command can be used for a one-way ANOVA when the data for each level is in a separate column. For example, suppose that the three samples for the example of this section are in columns C3—C5. Then the command MTB > aovoneway c3-c5 produces the same ANOVA table and conÞdence intervals for the means as onewayaov. Only a limited number of subcommands are available with this command, however. 12.3 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab, and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. Generate a sample of 10 from each of the N(µi , σ) distributions for i = 1, . . . , 5, where µ1 = 1, µ2 = 1, µ3 = 1, µ4 = 1, µ5 = 2, and σ = 3. Carry out a one-way ANOVA and produce a normal probability plot of the residuals and the residuals against the explanatory variable. Compute .95 conÞdence intervals for the diﬀerences between the means. Compute an approximate set of .95 simultaneous conÞdence intervals for the diﬀerences between the means. 2. Generate a sample of 10 from each of the N (µi , σi ) distributions for i = 1, . . . , 5, where µ1 = 1, µ2 = 1, µ3 = 1, µ4 = 1, µ5 = 2, σ1 = σ2 = σ3 = σ4 = 3, and σ5 = 8. Carry out a one-way ANOVA and produce a normal probability plot of the residuals and the residuals against the explanatory variable. Compare the residual plots with those obtained in Exercise II.12.1. 3. The F statistic in a one-way ANOVA, when the standard deviation σ is constant from one level to another, is distributed noncentral F (k1 , k2 ) with noncentrality λ, where k1 = I − 1, k2 = n1 + · · · nI − I, PI ni (µi − µ̄)2 λ = i=1 σ2 One-Way Analysis of Variance 173 P P and µ̄ = Ii=1 ni µi / Ii=1 ni . Using simulation, approximate the power of the test in Exercise II.12.1 with level .05 and the values of the parameters speciÞed and compared your results with exact results obtained from Stat ¯ I Power and Sample Size I One-way ANOVA. ¯ ¯ 174 Chapter 12 Chapter 13 Two-Way Analysis of Variance New Minitab command discussed in this chapter Stat I ANOVA I Two-way ¯ ¯ ¯ This chapter deals with methods for making inferences about the relationship existing between a single numeric response variable and two categorical explanatory variables. The Stat I ANOVA I Two-way command is used to carry out ¯ ¯ ¯ a two-way ANOVA. We write the two-way ANOVA model as xijk = µij + Nijk , where i = 1, . . . , I and j = 1, . . . , J index the levels of the categorical explanatory variables and k = 1, . . . , nij indexes the individual observations at each treatment (combination of levels), µij is the mean response at the ith level and the jth level of the Þrst and second explanatory variable, respectively, and the errors Nijk are a sample from the N (0, σ) distribution. Based on the observed xijk , we want to make inferences about the unknown values of the parameters µ11 , . . . , µIJ , σ. 13.1 The Two-Way ANOVA Command We consider a generated example, where I = J = 2, µ11 = µ21 = µ12 = µ22 = 1, σ = 2, and n11 = n21 = n12 = n22 = 5. The Nijk are generated as a sample from the N(0, 2) distribution, and we put xijk = µij + Nijk for i = 1, . . . , I and j = 1, . . . , J and k = 1, . . . , nij . Note that the Stat I ANOVA I Two-way ¯ ¯ ¯ command requires balanced data; i.e., all the nij must be equal. We pretend that we don’t know the values of the parameters and carry out a two-way analysis of variance. If the xijk are in C1, the values of i in C2 and the values of j in C3, the dialog box of Display 13.1.1. 175 176 Chapter 13 Display 13.1.1: Dialog box for producing a two-way analysis of variance. produces the following output. Analysis of Source C2 C3 Interaction Error Total C2 1 2 C3 1 2 Variance for C1 DF SS MS 1 0.39 0.39 1 3.43 3.43 1 4.01 4.01 16 84.44 5.28 19 92.26 F 0.07 0.65 0.76 P 0.790 0.432 0.396 Individual 95% CI Mean -+---------+---------+---------+---------+ 1.49 (-------------------*------------------) 1.77 (------------------*------------------) -+---------+---------+---------+---------+ 0.00 0.80 1.60 2.40 3.20 Mean 2.05 1.22 Individual 95% CI ----+---------+---------+---------+------(--------------*---------------) (--------------*---------------) ----+---------+---------+---------+------0.00 1.00 2.00 3.00 We see from this that the null hypothesis of no interaction is not rejected (P value = .396) and neither is the null hypothesis of no eﬀect due to the C2 factor (P -value = .790) nor the null hypothesis of no eﬀect due to factor C3 (P -value = .432). Note that by checking the Display means boxes in the dialog box of Display 13.1.1 we have caused 95% conÞdence intervals to be printed for the response means at each value of C2 and each value of C3, respectively. These cell means are relevant only when we decide that there is no interaction, as is the case here, and we note that all the intervals contain the true value 1 of these means. Two-Way Analysis of Variance 177 We also checked the Store residuals and Store Þts in the dialog boxes of Display 13.1.1. This results in the (ordinary) residuals being stored in C4 and the Þtted values (cell means) being stored in C5. If these columns already had entries the next two available columns would be used instead. If we want to Þt the model without any interaction, supposing we know this to be true, we can check the Fit additive model box in the dialog box of Display 13.1.1. This is acceptable only in rare circumstances, however, as it is unlikely that we will know that this is true. Various graphs are also available via the Graphs button in the dialog box of Display 13.1.1. Clicking on this results in the Dialog box shown in Display 13.1.2. Here we have asked for a normal probability plot of the (ordinary) residuals and a plot of the (ordinary) residuals versus the variables C2 and C3. Recall that with balance it is acceptable to use the ordinary residuals rather than the standardized residuals. We haven’t reproduced the corresponding plots here but, as we might expect, they gave no grounds for suspecting the correctness of the model. Display 13.1.2: Dialog box for producing various residual plots obtained via the Graphs button in the dialog box of Display 13.1.1. If we conclude that there is an interaction then we must look at the individual IJ cell means to determine where the interaction occurs. A plot of these cell means is often useful in this regard. Also available are analysis of means (ANOM) plots via Stat I ANOVA I Analysis of Means. In addition, we can ¯ ¯ ¯ plot the marginal means joined by lines using Stat I ANOVA I Main Eﬀects ¯ ¯ ¯ Plot and plot the cell means joined by lines using Stat I ANOVA I Interaction ¯ ¯ ¯ Plot using the dialog box of Display 13.1.3 with the output in Display 13.1.4. Note that while the plot seems to indicate an interaction, this is not conÞrmed by the statistical test. Power calculations can be carried out using Stat ¯ I Power and Sample Size I 2-Level Factorial Design and Þlling in the dialog ¯ ¯ box appropriately. Commands are available in Minitab for analyzing unbalanced data and for situations where there are more than two factors where some factors are continuous and some categorical, and so on. 178 Chapter 13 Display 13.1.3: Dialog box for obtaining the interaction plot of Display 13.1.4. Interaction Plot - Data Means for C1 C2 1 2 2.3 Mean 1.8 1.3 0.8 1 2 C3 Display 13.1.4: Plot of cell means in two-way ANOVA simulated example. The corresponding session command for carrying out a two-way ANOVA is given by twowayaov. For example, the command MTB > SUBC> SUBC> SUBC> twowayaov c1 c2 c3 c4 c5; gnormal; gvariable c2 c3; means c2 c3.’ results in the same output as above. The gnormal subcommand results in a normal probability plot of the residuals being plotted while the gvariables subcommand results in a plot of the residuals against each of the factors C2 and C3. The ghistogram, gÞts, and gorder subcommands are also available for a histogram of the residuals, the residuals against the Þtted values, and the residuals against observation order, respectively. The means subcommand causes the estimates of marginal means for each level of C2 and C3 to be printed together with 95% conÞdence intervals. If we want to Þt the model without any interaction, supposing we know this to be true, then the additive subcommand is available to do this. Two-Way Analysis of Variance 13.2 179 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. Suppose I = J = 2, µ11 = µ21 = 1, µ12 = µ22 = 2, σ = 2, and n11 = n21 = n12 = n22 = 10. Generate the data for this situation, and carry out a two-way analysis. Plot the cell means (an interaction eﬀect plot). Do your conclusions agree with what you know to be true? 2. Suppose I = J = 2, µ11 = µ21 = 1, µ12 = 3, µ22 = 2, σ = 2, and n11 = n21 = n12 = n22 = 10. Generate the data for this situation, and carry out a two-way analysis. Plot the cell means (an interaction eﬀect plot). Do your conclusions agree with what you know to be true? 3. Suppose I = J = 2, µ11 = µ21 = 1, µ12 = µ22 = 2, σ = 2, and n11 = n21 = n12 = n22 = 10. Generate the data for this situation, and carry out a two-way analysis. Form 95% conÞdence intervals for the marginal means. Repeat your analysis using the additive model and compare the conÞdence intervals. Can you explain your results? 180 Chapter 13 Chapter 14 Bootstrap Methods and Permutation Tests This chapter is concerned with computationally intensive inference methods that are sometimes applicable when methods based on strong assumptions, such as normality, cannot be used because it is clear that the assumptions are not satisÞed. These methods are based on repeated sampling from a column of Þxed data. Bootstrap sampling requires that we sample this column with replacement and permutation tests require that we sample the column without replacement. In the next sections we describe how to use Minitab to accomplish this. At this point Minitab does not have built-in commands to implement bootstrap sampling or permutation tests. For this we need some of the programming features of Minitab as discussed in Appendix D. Actually you will not have to learn how to program as we will provide the necessary code and explain how to use it in the following sections. It is a simple matter to modify this code so that diﬀerent statistics can be used. A Minitab program is called a macro and must start with the statement gmacro and end with the statement endmacro. The Þrst statement after gmacro gives a name to the program. Comments in a program, put there for explanatory purposes, start with note. If the Þle containing the program is called prog.txt and this is stored in the root directory of a disk drive called c, then the Minitab command MTB> %c:/prog.txt will run the program. Any output will either be printed in the Session window (if you have used a print command) or stored in the Minitab worksheet. Basically, this is all you need to know to run the programs discussed in this chapter. 181 182 14.1 Chapter 14 Bootstrap Sampling Suppose the data in the following table of n = 15 values is stored in C1 and we wish to calculate the bootstrap distribution of the sample median that we are using to estimate the mean of the population distribution. 0.2 0.5 5.8 3.0 2.3 0.4 2.2 −1.3 1.3 1.0 3.1 −2.7 4.0 −1.0 −8.6 The sample median for this data is given by 1.00. The following Minitab code generates 1000 bootstrap samples from the data in C1, calculates the median of each of these samples, and then calculates the sample mean and variance of these medians. gmacro bootstrapping base 34256734 note - original sample is stored in c1 note - bootstrap sample is placed in c2 (each one overwritten) note - medians of bootstrap samples are stored in c3 note - k1 = size of data set (and bootstrap samples) let k1=15 do k2=1:1000 note - the upper bound for k2 = the number of bootstrap note - samples generated, here this is 1000 and can be changed sample 15 c1 c2; replace. note - you must replace the following line with the Minitab note commands for whatever statistic you want to bootstrap let c3(k2)=median(c2) enddo note - k2 equals the mean of the bootstrapped median let k2=mean(c3) note - k3 equals the sample variance of the bootstrapped median let k3=(stdev(c3))**2 print k2 k3 endmacro To change the number of bootstrap samples we generate we must change the ninth line. Currently it reads do k2=1:1000 so that we are generating 1000 bootstrap samples. If we want to generate 10,000 bootstrap samples, then we must change this to do k2=1:10000 Bootstrap Methods and Permutation Tests 183 and of course any other number can be substituted. Be careful though, as the bigger we choose this number the longer we have to wait for the computations to be carried out. The entire bootstrap sample of medians is stored in C3. So we can plot this in a histogram to get some idea of what the distribution looks like that the bootstrap procedure is sampling from. We put the above code in a Þle bootstrap.txt and stored this in the main directory of the c drive. Then the command MTB > %c:/bootstrap.txt runs these commands and produces the output K2 1.06890 K3 0.687270 which gives the estimate bootstrap mean and bootstrap variance as 1.06890 and 0.687270, respectively. So the bias is 1.06890−1.00 = 0.0689, which is relatively small. Using the Graph I Histogram command on the values stored in C3 we ¯ ¯ produced the plot in Display 14.1.1. We can see from this that the bootstrap distribution of the median is not very normal looking. Histogram of C3 0.9 0.8 0.7 Density 0.6 0.5 0.4 0.3 0.2 0.1 0.0 -3 -2 -1 0 1 2 3 4 C3 Display 14.1.1: Histogram of 1000 bootstrap sample medians. There are a number of built-in Minitab functions, such as median, whose bootstrap distribution we are often interested in. There are others, however, for which we must do a bit of programming. For example, we must program the various trimmed means. If we want an α-trimmed mean, where α ∈ [0, 1] , then we remove the m smallest observations and the m largest observations from the sample and calculate the mean of the rest, where m is the closest integer to αn. We now provide an example of obtaining the bootstrap distribution of a 25%-trimmed mean of the data given above. Note that in this case, since (.25)(15) = 3.75, we take m = 4, and this implies that we remove the observations −8.6, −2.7, −1.3, 3.1, 4.0 and 5.8 from the sample. The .25-trimmed 184 Chapter 14 mean is then given by 1.10. We then used the following code to estimate the bootstrap distribution of the .25-trimmed mean. gmacro bootstrapping base 34256734 note - original sample is stored in c1 note - bootstrap sample is placed in c2 (each one overwritten) note - the sorted bootstrap sample is then put in c2 note - 25% trimmed means of bootstrap samples are computed and note - stored in c3 for more analysis do k2=1:1000 sample 15 c1 c2; replace. sort c2 c2 let k4=0 do k3=4:12 let k4=k4+c2(k3) enddo let c3(k2)=k4/9 enddo let k2=mean(c3) let k3=(stdev(c3))**2 print k2 k3 endmacro Note that the code let k4=0 do k3=4:12 let k4=k4+c2(k3) enddo let c3(k2)=k4/9 calculates the .25-trimmed mean for this data and needs to be changed appropriately for other trimmed means and other data sets. Running this program we obtained the estimated mean of the bootstrap distribution as 1.05517 and the estimated bootstrap variance as 0.531869. So in this case the bias is 1.05517 − 1.10 = −0.04483, which is reasonably small. Using the Graph I Histogram command on the values stored in C3 we ¯ ¯ produced the plot in Display 14.1.2. We can see from this that the bootstrap distribution of the median is much more normal looking, although still somewhat skewed to the left. Bootstrap Methods and Permutation Tests 185 Histogram of C3 0.7 0.6 Density 0.5 0.4 0.3 0.2 0.1 0.0 -3 -2 -1 0 C3 1 2 3 Display 14.1.2: Histogram of 1000 bootstrap sample .25-trimmed means. Ignoring the skewness of the bootstrap distribution, an approximate .95conÞdence interval for the population mean based on the t distribution is then given by √ √ 1.10 ± t.975 (14) 0.531869 = 1.10 − (2.14479) 0.531869 = [−0.46418, 2.6642]. To calculate the bootstrap percentile conÞdence intervals we Þrst sort the bootstrap distribution values in C3 and Þnd the .025 and the .975 percentiles of this sample. The commands MTB > MTB > DATA> DATA> MTB > sort c3 c4 set c5 1:1000 end let c5=c5/1000 place the sorted values in C4 and then calculates the proportion of values less than or equal to each value and places these proportions in C5. We then record the values in C4 that correspond to .025 and .975 in C5. In this case we obtained (−1.0, 3.0) as the .95-bootstrap percentile conÞdence interval. We note that this interval is somewhat wider than the interval based on the t distribution. 14.2 Permutation Tests As with bootstrapping Minitab does not have built-in commands to carry out permutation tests. Again, however, it is very easy to program Minitab to implement these tests. 186 Chapter 14 We illustrate how to implement a permutation test using Example 14.11 in IPS. as given in the following table (T stands for Treatment and C for Control). T 24 43 58 71 43 49 T 61 44 67 49 53 56 T 59 52 62 54 57 33 T 46 43 57 C 42 43 55 26 62 37 C 33 41 19 54 20 85 C 46 10 17 60 53 42 C 37 42 55 28 48 We want to test the null hypothesis that the mean of the distribution for the treatment group is the same as the mean of the distribution for the control group. Now suppose that we have the values stored in C2 with an index stored in C1 that indicates whether the value is from the Treatment group or from the Control group. Then the commands MTB > unstack c2 c3 c4; SUBC> subscripts c1. MTB > let k1=mean(c3) MTB > let k2=mean(c4) MTB > let k3=k1-k2 MTB > print k3 Data Display K3 9.95445 calculate the means of the T group and the C group, the diﬀerence of the two means and then prints this quantity. We obtain 9.95445 as the diﬀerence of the means. The following commands compute the P -value based on permutation distribution of the diﬀerence of means to test the null hypothesis that the means of the T and C groups are the same against the alternative that the mean of the T group is greater than the mean of the C group gmacro permutation base 468798 note - index is stored in c1 note - original samples are stored in c2 note - the following commands compute the difference of the note means for the original samples note - and stores this difference in k10 unstack c2 c4 c5; subscripts c1. let k2=mean(c4) let k3=mean(c5) let k10=k2-k3 note - permuted samples are stored in c3 Bootstrap Methods and Permutation Tests 187 note - unstacked permuted samples are stored in c4 and c5 note - the difference in means is stored in c6 note - the value 1 is stored in c7 if difference in means of note - these samples is greater than k10 and the value 0 is note - stored there otherwise do k1=1:1000 sample 44 c2 c3 unstack c3 c4 c5; subscripts c1. let k2=mean(c4) let k3=mean(c5) let k4=k2-k3 let c6(k1) = k4 let c7(k1) = k4 >= k10 enddo note - the mean of c7 is the proportion of the differences of note - means in the permutation distribution that are greater note - than or equal to the observed difference let k5=mean(c7) print k10 k5 endmacro. The output from the above program is K10 9.95445 K5 0.0210000 and this tells us that the P -value is .021 and so we can conclude that we have evidence against the null hypothesis. Note that the above program stores the sample from the permutation distribution in C6 so we can analyze this further. For example, Display 14.2.1 gives a histogram of the 1000 diﬀerences of means as obtained in the above program. We see that this is reasonably normal looking. Histogram of C6 90 80 Frequency 70 60 50 40 30 20 10 0 -12 -8 -4 0 C6 4 8 12 Display 14.2.1: Histogram of 1000 diﬀerences of means obtained by randomly permuting the samples. 188 Chapter 14 A two-sided permutation test can be carried out in this case by simply computing the proportion of diﬀerences in are greater in absolute value than the absolute value of the observed diﬀerence, which in this case equals |9.95445| = 9.95445. The following commands accomplish this. do k1=1:1000 sample 44 c2 c3 unstack c3 c4 c5; subscripts c1. let k2=mean(c4) let k3=mean(c5) let k4=k2-k3 let c6(k1) = k4 let c7(k1) = abs(k4) >= abs(k10) enddo let k5=mean(c7) This produced the output K5 0.0330000 so the results are signiÞcant when using the two-sided alternative as well. For the matched pairs permutation test for comparing treatment A to treatment B we randomly assign an individual’s A measurement to A or B, and the B measurement is assigned the other label. We then compare the observed mean diﬀerence with the distribution of these diﬀerences obtained from all possible random assignments. The following code carries out the two sided matched pair permutation test when we have 10 observations with the A measurements stored in C1 and the B measurements stored in C2. gmacro permutationmatched base 468798 note - first measurement is stored in c1 note - second measurement is stored in c2 note - differences stored in c3 note - k2 = observed mean difference let c3=c1-c2 let k2=mean(c3) note - randomly choose which observations in c1 will be note - labelled A (10 values generated from Bernoulli(.5)) note - whenever a 1 occurs in c4 multiply entry in c3 by 1 note - otherwise multiply by -1, store in c6 note - and put mean difference in k4 and store in c7 do k1=1:1000 random 10 c4; bernoulli .5. let c5=-1+2*c4 Bootstrap Methods and Permutation Tests 189 let c6=c5*c3 let k3=mean(c6) let c7(k1) = k3 let c8(k1) = abs(k3) >= abs(k2) enddo let k4=mean(c8) print k2 k4 endmacro 14.3 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. Generate a sample of n = 20 from the N (0, 1) distribution. Approximate the bootstrap distribution of x̄ by generating 1000 bootstrap samples. Estimate the bias, estimate the bootstrap variance and plot the 1000 values of the sample mean in a density histogram. Calculate, and compare, .95 conÞdence intervals for the population mean based on the t distribution and bootstrap distribution. 2. Generate a sample of n = 20 from the Chi-squared(1) distribution. Approximate the bootstrap distribution of x̄ by generating 1000 bootstrap samples. Estimate the bias, estimate the bootstrap variance and plot the 1000 values of the sample mean in a density histogram. Calculate, and compare, .95 conÞdence intervals for the population mean based on the t distribution and bootstrap distribution. 3. Generate a sample of n = 20 from the N (0, 1) distribution. Approximate the bootstrap distribution of the .1-trimmed mean by generating 1000 bootstrap samples. Estimate the bias, estimate the bootstrap variance and plot the 1000 values of the .1-trimmed mean in a density histogram. Calculate, and compare, .95 conÞdence intervals for the population .1trimmed mean based on the t distribution and bootstrap distribution. 4. Generate a sample of n = 20 from the Chi-squared(1) distribution. Approximate the bootstrap distribution of the .1-trimmed mean by generating 1000 bootstrap samples. Estimate the bias, estimate the bootstrap variance and plot the 1000 values of the .1-trimmed mean in a density histogram. Calculate, and compare, .95 conÞdence intervals for the population .1-trimmed mean based on the t distribution and bootstrap distribution. 190 Chapter 14 5. Generate a sample of 10 from the N(0, 1) distribution and a sample of 15 from the N(2, 1) distribution and carry out a two-sided permutation test that the diﬀerence of means is 0. Compare the P -value obtained with that obtained from a two-sided t test. 6. Generate a sample of 10 from the Student(1) distribution and a sample of 15 from the Student(1) + 2 distribution (generate a sample from the Student(1) and add 2 to each sample element) and carry out a two-sided permutation test that the diﬀerence of means is 0. Compare the P -value obtained with that obtained from a two-sided t test. 7. Generate a sample of 10 from the N (0, 1) distribution and a sample of 10 from the N(2, 1) distribution and carry out a two-sided matched pair permutation test that the diﬀerence of means is 0. Compare the P -value obtained with that obtained from a two-sided matched pair t test. Chapter 15 Nonparametric Tests New Minitab commands discussed in this chapter Stat I Nonparametrics I Kruskal-Wallis ¯ ¯ ¯ Stat I Nonparametrics I Mann-Whitney ¯ ¯ ¯ Stat I Nonparametrics I 1-Sample Wilcoxon ¯ ¯ ¯ This chapter deals with inference methods that do not depend upon the assumption of normality. These methods are sometimes called nonparametric or distribution free methods. Recall that we discussed a distribution-free method in Section 7.4, where we presented the Stat I Nonparametrics I 1-Sample Sign ¯ ¯ ¯ command for the sign conÞdence interval and sign test for the median. Recall also the Data I Rank command in I.10.6, which can be used to compute the ¯ ¯ ranks of a data set. 15.1 The Wilcoxon Rank Sum Procedures The Mann-Whitney test for a diﬀerence between the locations of two distributions is equivalent to the Wilcoxon rank sum test in the following sense. Suppose that we have two independent samples y11 , . . . , y1n1 and y21 , . . . , y2n2 from two distributions that diﬀer at most in their locations as represented by their medians. The Mann-Whitney statistic U is the number of pairs (y1i , y2j ) where y1i > y2j , while the Wilcoxon rank sum test statistic W is the sum of the ranks from the Þrst sample when the ranks are computed for the two samples considered as one sample combined. It can be shown that W = U + n1 (n1+1 )/2 and so the test procedures based on these statistics are equivalent. For Example 15.1 of IPS, we store the four values 166.7, 172.2, 165.0, and 176.9 of sample 1 in C1 and the four values 158.6, 176.4, 153.1, and 156.0 of sample 2 in C2. The Stat I Nonparametrics I Mann-Whitney command, ¯ box¯of Display 15.1, ¯ implemented as in the dialog 191 192 Chapter 15 Display 15.1: Dialog box for implementing the Mann-Whitney command. leads to the output Mann-Whitney Confidence Interval and Test C1 N = 4 Median = 169.45 C2 N = 4 Median = 157.30 Point estimate for ETA1-ETA2 is 11.30 93.9 Percent CI for ETA1-ETA2 is (-9.70,20.90) W = 23.0 Test of ETA1 = ETA2 vs ETA1 > ETA2 is significant at 0.0970 Cannot reject at alpha = 0.05 which indicates that the test of H0 : the medians of the two distributions are identical versus Ha : the median of the Þrst distribution is greater than the median of the second gives a P -value of .0970. Also, an estimate of 11.3 is produced for the diﬀerence in the medians, and we asked for a 90% conÞdence interval for this diﬀerence by placing 90 in the ConÞdence level box. Note that exact conÞdences cannot be attained due to the discrete distribution followed by the statistic U. The Mann-Whitney test requires the assumption that the two distributions we are sampling from have the same form. The corresponding session command is given by mann-whitney. For example, the command MTB > mann-whitney 90 c1 c2; SUBC> alternative 1. leads to the above output. Note that we have placed 90 on the command line to indicate that we want a 90% conÞdence interval. If this value is left out, a default 95% conÞdence interval is computed. Also available are the one-sided test of H0 : the medians of the two distributions are identical versus Ha : the median of the Þrst distribution is smaller than the median of the second, using the subcommand alternative −1 and the two-sided test is obtained if no alternative subcommand is employed. Nonparametric Tests 15.2 193 The Wilcoxon Signed Rank Procedures The Wilcoxon signed rank test and conÞdence interval are used for inferences about the median of a distribution. The Wilcoxon procedures are based on ranks, which is not the case for the sign procedures discussed in Section 7.4. Consider the data of Example 15.8 in IPS where the diﬀerences between two scores have been recorded as .37, −.23, .66, −.08, −.17 in C1. The Stat I Nonparametrics ¯ ¯ I 1-Sample Wilcoxon command, implemented as in the dialog box in Display ¯ 15.2, Display 15.2: Dialog box for implementing the Wilcoxon signed rank test. leads to the output Test of median = 0.000000 versus median > 0.000000 N for Wilcoxon Estimated N Test Statistic P Median C1 5 5 9.0 0.394 0.1000 which gives the P -value .394 for testing H0 : the median of the diﬀerence is 0 versus Ha : the median of the diﬀerence is greater than 0. If instead we had Þlled in the ConÞdence interval button and placed 90 in the Level box of the dialog box in Display 15.2, we would have obtained the output C1 N 5 Estimated Median 0.100 Achieved Confidence 89.4 Confidence Interval (-0.200, 0.515) which provides a 90% conÞdence interval for the median. Note that the Wilcoxon signed rank procedures for the median require an assumption that the response values (in this case the diﬀerence) come from a distribution symmetric about its median. The corresponding session commands are given by wtest and winterval for tests and conÞdence intervals respectively. The general syntax of the wtest command is wtest V E1 194 Chapter 15 where V is the hypothesized value of the median, with 0 being the default value, and E1 is the column containing the data. For example, the command MTB > wtest c1; SUBC> alternative 1. produces the above output for the test. The general syntax of the winterval command is winterval V E1 where V is the conÞdence level, with 0.95 being the default value, and E1 is the column containing the data. 15.3 The Kruskal-Wallis Test The Kruskal-Wallis test is the analog of the one-way ANOVA in the nonparametric setting. Suppose the data for Example 15.13 in IPS are in C1 and C2, where C1 contains the corn yield in bushels per acre and C2 is number of weeds per meter. The Stat I Nonparametrics I Kruskal-Wallis command, as imple¯ ¯ ¯ mented in Display 15.3, Display 15.3: Dialog box for implementing the Kruskal-Wallis test. produces the output Kruskal-Wallis Test on C1 C2 N Median Ave Rank Z 0 4 169.4 13.1 2.24 1 4 163.6 8.4 -0.06 3 4 157.3 6.2 -1.09 9 4 162.6 6.2 -1.09 Overall 16 8.5 H = 5.56 DF = 3 P = 0.135 H = 5.57 DF = 3 P = 0.134 (adjusted for ties) * NOTE * One or more small samples Nonparametric Tests 195 which gives a P -value of .135 for testing H0 : each sample comes from the same distribution versus Ha : at least two of the samples come from diﬀerent distributions. Note that the validity of the Kruskal-Wallis test relies on the assumption that the distributions being sampled from all have the same form. The corresponding session command is given by kruskal-wallis. For example, the command MTB > kruskal-wallis c1 c2 also produces the above output. The general syntax of the kruskal-wallis command is kruskal-wallis E1 E2 where E1 contains the data and E2 contains the levels of the factor. 15.4 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. Generate a sample of n = 10 from the N (0, 1) distribution and compute the P -value for testing H0 : the median is 0 versus Ha : the median is not 0, using the t test and the Wilcoxon signed rank test. Compare the P -values. Repeat this with n = 100. 2. Generate a sample of n = 10 from the N (0, 1) distribution and compute 95% conÞdence intervals for the median, using the t conÞdence interval and the Wilcoxon signed rank conÞdence intervals. Compare the lengths of the conÞdence intervals. Repeat this with n = 100. 3. Generate two samples of n = 10 from the Student(1) distribution and add 1 to the second sample. Test H0 : the medians of the two distributions are identical versus Ha : the medians are not equal using the two sample t test and using the Mann-Whitney test. Compare the results. 4. Generate a sample of 10 from each of the N (1, 2), N (2, 2), and N(3, 1) distributions. Test for a diﬀerence among the distributions using a oneway ANOVA and using the Kruskal-Wallis test. Compare the results. 5. Generate 10 scores for 10 brands from the N (µij , σ) distributions for i = 1, 2 and j = 1, 2, where µ11 = µ21 = 1 and µ12 = µ22 = 2, and treat each test for no eﬀect due to brand using a two-way ANOVA with the assumption of no interaction and also using the Friedman test. Compare the results. 196 Chapter 15 Chapter 16 Logistic Regression New Minitab commands discussed in this chapter Stat I Regression I Binary Logistic Regression ¯ ¯ ¯ Stat I Regression I Nominal Logistic Regression ¯ ¯ ¯ Stat I Regression I Ordinal Logistic Regression ¯ ¯ ¯ This chapter deals with the logistic regression model. This model arises when the response variable y is binary, i.e., takes only two values, and we have a number of explanatory variables x1 , . . . , xk . 16.1 The Logistic Regression Model The regression techniques discussed in Chapters 10 and 11 require that the response variable y be a continuous variable. In many contexts, however, the response is discrete and in fact binary; i.e., taking the values 0 and 1. Let p denote the probability of a 1. This probability is related to the values of the explanatory variables x1 , . . . , xk . We cannot, however, write this as p = β0 + β1 x1 + . . . + βk xk because the right-hand side is not constrained to lie in the interval [0, 1], which it must if it is to represent a probability. One solution to this problem is to employ the logit link function, which is given by ln µ p 1−p ¶ = β0 + β1 x1 + · · · + βk xk and this leads to the equations p = exp {β0 + β1 x1 + · · · + βk xk } 1−p 197 198 Chapter 16 and exp {β0 + β1 x1 + · · · + βk xk } 1 + exp {β0 + β1 x1 + · · · + βk xk } for the odds p/(1 − p) and probability p, respectively. The right-hand side of the equation for p is now always between 0 and 1. Note that logistic regression is based on an ordinary regression relation between the logarithm of the odds in favor of the event occurring at a particular setting of the explanatory variables and the values of the explanatory variables x1 , . . . , xk . The quantity ln (p/(1 − p)) is referred to as the log odds. The procedure for estimating the coeﬃcients β0 , β1 , . . . , βk using this relation and carrying out tests of signiÞcance on these values is known as logistic regression. Typically, more sophisticated statistical methods than least squares are needed for Þtting and inference in this context, and we rely on software such as Minitab to carry out the necessary computations. In addition, other link functions are available in Minitab are often used. In particular, the probit link function is given by p= Φ−1 (p) = β0 + β1 x1 + · · · + βk xk where Φ is the cumulative distribution function of the N (0, 1) distribution, and this leads to the relation p = Φ (β0 + β1 x1 + · · · + βk xk ) which is also always between 0 and 1. Choice of the link function can be made via a variety of goodness-of-Þt tests available in Minitab, but we restrict our attention here to the logit link function. 16.2 Example Suppose that we have the following 10 observations in columns C1—C3 Row 1 2 3 4 5 6 7 8 9 10 C1 0 0 1 1 1 0 1 1 0 1 C2 -0.65917 0.69408 -0.28772 0.76911 1.44037 0.52674 0.38593 -0.00027 1.15681 0.60793 C3 0.43450 0.48175 0.08279 0.59153 2.07466 0.27745 0.14894 0.00000 1.33822 0.36958 where the response y is in C1, x1 is in C2, and x2 is in C3 and note that x2 = x21 . We want to Þt the model µ ¶ p ln = β0 + β1 x1 + β2 x2 1−p Logistic Regression 199 and conduct statistical inference concerning the parameters of the model. Fitting and inference is carried out in Minitab using Stat I Regression I ¯ ¯ Binary Logistic Regression and Þlling in the dialog box as in Display 16.1. ¯ Display 16.1: Dialog box for implementing a binary logistic regression. Here, the Response box contains c1 and the Model box contains C2 and C3. Clicking on the Results button brings up the dialog box in Display 16.2. Display 16.2: The dialog box resulting from clicking on the Results button in the ¯ dialog box of Display 16.1. We have Þlled in the radio button Response information, regression table, etc., as this controls the amount of output. The default output is more extensive and we chose to limit this. The following output is obtained. 200 Chapter 16 Link Function: Logit Response Information Variable Value Count C1 1 6 (Event) 0 4 Total 10 Logistic Regression Table Predictor Coef StDev Z P Constant 0.522797 0.903136 0.58 0.563 C2 0.739948 1.60504 0.46 0.645 C3 -0.779605 1.58437 -0.49 0.623 Log-Likelihood = -6.598 Test that all slopes are zero: G = 0.265, DF Odds 95% CI Ratio Lower Upper 2.10 0.46 0.09 48.71 0.02 10.23 = 2, P-Value = 0.876 This gives estimates of the coeﬃcients and their standard errors and the P -value for H0 : β0 = 0 versus Ha : β0 6= 0 as 0.563, the P -value for H0 : β1 = 0 versus Ha : β1 6= 0 as 0.643, and the P -value for H0 : β2 = 0 versus Ha : β2 6= 0 as 0.623. Further, the test of H0 : β1 = β2 = 0 versus Ha : β1 6= 0 or β2 6= 0 has P -value .876. In this example, there is no evidence of any nonzero coeﬃcients. Note that p = .5 when β0 = β1 = β2 = 0 Also provided in the output is the estimate 2.10 for the odds ratio for x1 (C2) and a 95% conÞdence interval (.09, 48.71) for the true value. The odds ratio for x1 is given by exp (β1 ) , which is the ratio of the odds at x1 + 1 to the odds at x1 when x2 is held Þxed or when β2 = 0. Because there is evidence that β2 = 0 (P -value = .623), the odds ratio has a direct interpretation here. Note, however, that if this wasn’t the case the odds ratio would not have such an interpretation as it doesn’t makes sense for x2 to be held Þxed when x1 changes in this example as they are not independent variables. Similar comments apply to the estimate 0.46 for the odds ratio for x2 (C3) and the 95% conÞdence interval (.02, 10.23) for the true value of this quantity. Many other aspects of Þtting logistic regression models are available in Minitab and we refer the reader to Help for a discussion of these. Also available in Minitab are ordinal logistic regression, when the response takes more than two values and these are ordered, and nominal logistic regression, when the response takes more than two values and these are unordered. These can be accessed via Stat I Regression I Ordinal Logistic Regression and Stat I ¯ ¯ ¯ ¯ Regression I Nominal Logistic Regression, respectively. ¯ ¯ 16.3 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab and the exercises are designed to ensure that you have Logistic Regression 201 a reasonable understanding of the Minitab material in this chapter. Generally, you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. Generate a sample of 20 from the Bernoulli(.25) distribution. Pretending that we don’t know p, compute a 95% conÞdence interval for this quantity. Using this conÞdence interval, form 95% conÞdence intervals for the odds and the log odds. 2. Let x take the values −1, −.5, 0, .5, and 1. Plot the log odds ¶ µ p = β0 + β1 x ln 1−p against x when β0 = 1 and β1 = 2. Plot the odds and the probability p against x. 3. Let x take the values −1, −.5, 0, .5, and 1. At each of these values, generate a sample of four values from the Bernoulli(px ) distribution where px = exp {1 + 2x} 1 + exp {1 + 2x} and let these values be the y response values. Carry out a logistic regression analysis of this data using the model. µ ¶ px ln = β0 + β1 x 1 − px Compute a 95% conÞdence interval for β1 and determine if it contains the true value. Similarly, form a 95% conÞdence interval for the odds ratio when x increases by 1 unit and determine if it contains the true value. 4. Let x take the values −1, −.5, 0, .5, and 1. At each of these values, generate a sample of four values from the Bernoulli(px ) distribution where px = exp {1 + 2x} 1 + exp {1 + 2x} and let these values be the y response values. Carry out a logistic regression analysis of this data using the model µ ¶ px ln = β0 + β1 x + β2 x2 1 − px Test the null hypothesis H0 : β2 = 0 versus Ha : β2 6= 0. Form a 95% conÞdence interval for the odds ratio for x. Does it make sense to make an inference about this quantity in this example? Why or why not? 202 Chapter 16 5. Let x take the values −1, −.5, 0, .5, and 1. At each of these values, generate a sample of four values from the Bernoulli(.5) distribution. Carry out a logistic regression analysis of this data using the model ¶ µ px = β0 + β1 x + β2 x2 ln 1 − px Test the null hypothesis H0 : β1 = β2 = 0 versus Ha : β1 6= 0 or β2 6= 0. Chapter 17 Statistics for Quality: Control and Capability New Minitab commands discussed in this chapter Stat I Control Charts I Attributes Charts I P... ¯ ¯ ¯ ¯ Stat I Control Charts I Variables Charts for Subgroups I S... ¯ ¯ ¯ ¯ bar... Stat I Control Charts I Variables Charts for Subgroups I X ¯ ¯ ¯ ¯ Control charts are used to monitor a process to ensure that it is under statistical control. There is a wide variety of such charts depending on the statistic used for the monitoring and the test used to detect when a process is out of control. 17.1 Producing x̄ Charts Suppose we have placed a random sample of 100 from the N(5, 2) distribution in C1 and we want an x̄ chart of this data. Then the command Stat I Control ¯ ¯ Charts I Variables Charts for Subgroups I Xbar... brings up the dialog box ¯ ¯ shown in Display 17.1.1. Here we have indicated that the data is in C1 and that we want the sample averages to be based on 5 observations (so there are 20 means). To control the placement of the LCL and UCL limits we clicked on Xbar Options ... to bring up the dialog box shown in Display 17.1.2. Here we asked that the center line be √ be set to 2 √ drawn at 5 and the standard deviation so that the LCL is 5 − 3(2/ 5) = 2.3167 and the UCL is 5 + 3(2/ 5) = 7.6833. If we do not specify these values, then Minitab will estimate them from the data using the sample mean for the center line and the average of the sample standard deviations for the subgroups to determine the LCL and UCL. In particular, if s̄ denotes the average standard deviation then the LCL equals x̄ − 3s̄/c4 and the UCL equals x̄ + 3s̄/c4 , where c4 is the constant deÞned in IPS that corrects for the bias in s, as an estimator of σ. 203 204 Chapter 17 Display 17.1.1: Dialog box to create an x̄ chart. Display 17.1.2: Dialog box to control placement of center line and limits in an x̄ chart. Clicking on OK in both of these dialog boxes produces the x̄ chart shown in Display 17.1.3. As expected, all the sample means lie within the limits. Statistics for Quality: Control and Capability 205 Xbar Chart of C1 8 UCL=7.683 Sample Mean 7 6 _ _ X=5 5 4 3 LCL=2.317 2 1 3 5 7 9 11 Sample 13 15 17 19 Display 17.1.3: An x̄ chart for a random sample of 100 from the N (5, 2) distribution. We observe that the dialog box in Display 17.1.2 contains a tab labelled Tests. Clicking on this produces the dialog box shown in Display 17.1.4 where we have indicated that we want two tests to be carried out, namely, 1 point > 3 standard deviations from center line and 9 points in a row on same side of center line. Clearly, the control chart shown in Display 17.1.3 passes both of these tests. Suppose, however, that we change the Þrst sample observation to the value 30. Then using the dialog boxes shown in Displays 17.1.1, 17.1.2 and 17.1.4 produces the x̄ chart shown in Display 17.1.5. Note that the Þrst sample mean fails the Þrst test and this is indicated on the chart by placing a 1 above that plotted mean. If any points had failed the second test, this would have been indicated by placing the number 2 above those plotted means, etc. Display 17.1.4: Dialog box to choose tests to be performed in an x̄ chart. 206 Chapter 17 Xbar Chart of C1 11 1 10 Sample Mean 9 8 UCL=7.683 7 6 _ _ X=5 5 4 3 LCL=2.317 2 1 3 5 7 9 11 Sample 13 15 17 19 Display 17.1.5: An x̄ chart for a random sample of 100 from the N (5, 2) distribution where the Þrst observation has been changed to be equal to 30. The syntax of the corresponding session command xbarchart is xbarchart E1 E2 where E1 is a column containing the data and E2 is either a constant, indicating how many observations are used to deÞne a subgroup, or a column of values, indicating how the elements of E1 are to be grouped for the calculation of the means. Minitab then produces the center line and control limits based on the data in E1 . When E2 equals 1, σ cannot be estimated using standard deviations and an alternative estimator is used. There are various subcommands that can be used with xbarchart. In particular, we can provide mu and sigma to specify the population mean and standard deviation. For example, the commands MTB > xbarchart c1 5; SUBC> mu 5; SUBC> sigma 2. produce the chart shown in Display 17.1.3. Using the test subcommand, various tests for control can be carried out. For example, MTB > xbar c1 5; SUBC> test 1. breaks the data into subgroups of size 5 and checks to see if any of the points are outside the control limits. The subcommand test 2 checks to see if there are 9 points in a row on the same side of the center line, test 3 checks to see if there are 6 points in a row all increasing or all decreasing. There are a total of 8 tests like this, all looking for patterns. The subcommand test 1:8 performs all 8 tests. Statistics for Quality: Control and Capability 17.2 207 Producing S Charts Suppose we have placed a random sample of 100 from the N(5, 2) distribution in C1 and we want an S chart of this data. Then the command Stat I Control ¯ ¯ Charts I Variables Charts for Subgroups I S... brings up the dialog box shown ¯ ¯ in Display 17.2.1. Here we have indicated that the data is in C1 and that we want the sample standard deviations to be based on 5 observations (so there are 20 standard deviations). To control the placement of the LCL and UCL limits we clicked on S Options ... to bring up the dialog box shown in Display 17.2.2. Here we set σ = 2 so that the center line and the LCL and UCL limits are determined by this. If we don’t specify the value for σ, then this parameter is estimated from the data. Display 17.2.1: Dialog box to create an S chart. Display 17.2.2: Dialog box to control center line and limits in an S chart. Clicking on OK in both of these dialog boxes produces the S chart shown in Display 17.2.3. As expected, all the standard deviations lie within the limits. 208 Chapter 17 S Chart of C1 4 UCL=3.927 Sample StDev 3 _ S=1.880 2 1 LCL=0 0 1 3 5 7 9 11 Sample 13 15 17 19 Display 17.2.3: An S chart for a random sample of 100 from the N (5, 2) distribution. We observe that the dialog box in Display 17.2.2 contains a tab labelled Tests. As with x̄ charts (Display 17.1.4) we can select several tests to be performed to assess whether or not the process is in control. The syntax of the corresponding session command schart is schart E1 E2 where E1 is a column containing the data and E2 is either a constant, indicating how many observations are used to deÞne a subgroup, or a column of values, indicating how the elements of E1 are to be grouped for the calculation of the standard deviations. Minitab then produces the center line and control limits based on the data in E1 . When E2 equals 1, σ cannot be estimated using standard deviations and an alternative estimator is used. There are various subcommands that can be used with schart. For example, the commands MTB > schart c1 5; SUBC> sigma 2. produces the control chart of Display 17.2.3. 17.3 Producing p Charts A p chart is appropriate when a response is coming from a Binomial(n, p) distribution, e.g., the count of the number of defectives in a batch of size n, and we use the proportion of defectives p̂ to control the process. For example, suppose we have placed a random sample of 50 from the Binomial(10, .3) distribution in C1 and we want a p chart of this data. Then the command Stat I Control ¯ ¯ Charts I Attributes Charts I P... brings up the dialog box shown in Display ¯ ¯ Statistics for Quality: Control and Capability 209 17.3.1. Here we have indicated that the data is in C1 and that these counts are based on 10 observations. To control the placement of the LCL and UCL limits we clicked on P Chart Options ... to bring up the dialog box shown in Display 17.3.2. Here we asked that limits be determined by setting p = .3 so that the center line is at .3, the LCL is o n p max .3 − 3 .3(.7)/10, 0 = 0.0 and the UCL is p .3 + 3 .3(.7)/10 = 0.73474. If we don’t specify the value for p then this parameter is estimated from the data and the center line and limits depend on the data. Display 17.3.1: Dialog box to create a p chart. Display 17.3.2: Dialog box to control center line and limits in a p chart. 210 Chapter 17 Clicking on OK in these dialog boxes produces the p chart shown in Display 17.3.3. We see from this that the process seems to be in control as we might expect. P Chart of C1 0.8 UCL=0.7347 0.7 Proportion 0.6 0.5 0.4 _ P=0.3 0.3 0.2 0.1 0.0 LCL=0 1 6 11 16 21 26 Sample 31 36 41 46 Display 17.3.3: A p chart for a random sample of 50 from the Binomial(10, .3) distribution. The syntax of the corresponding session command pchart is pchart E1 E2 where E1 is a column containing the data and E2 is a constant, indicating how many observations the counts are based on. Minitab then produces the center line and control limits based on the data in E1 . There are various subcommands that can be used with pchart. For example, the commands MTB > pchart C1 10; SUBC> P .3. produces the plot shown in Display 17.3.3. 17.4 Exercises When the data for an exercise come from an exercise in IPS, the IPS exercise number is given in parentheses ( ). All computations in these exercises are to be carried out using Minitab and the exercises are designed to ensure that you have a reasonable understanding of the Minitab material in this chapter. More generally you should be using Minitab to do all the computations and plotting required for the problems in IPS. 1. Generate a sample of 100 from a Student(1). Make an x̄ chart for this data based on subgroups of size 5 with µ = 0 and σ = 1. What tests for control are failed? Statistics for Quality: Control and Capability 211 2. For the data in Exercise 1, make an x̄ chart based on subgroups of size 5 using estimates of µ and σ. What tests for control are failed? 3. For the data in Exercise 1, make an S chart based on subgroups of size 5 using σ = 1. What tests for control are failed? 4. For the data in Exercise 1, make an S chart based on subgroups of size 5 using an estimate of σ. What tests for control are failed? 5. Generate a sample of 100 from a Binomial(15, .1) distribution. Make a p chart for this data. What tests for control are failed? 6. Generate a sample of 50 from a Binomial(15, .1) distribution followed by a sample of 50 from a Binomial(15, .8) distribution. Make a p chart for this data. What tests for control are failed? 212 Chapter 17 Appendix A Projects The basic structural component of Minitab is the worksheet. When working on a project, it may make sense to have your data in several worksheets so that similar variables are grouped together. Also, you may wish to save plots associated with the worksheets so that everything can be obtained via a single reference. Worksheets and graphs can be grouped together into projects. Projects are given names and are stored in a Þle with the supplied name and the Þle extension .mpj. To open a new project use File I New and choose Minitab Project and click ¯ ¯ OK. If you want to open a previously saved project, use File I Open Project ¯ ¯ and choose the relevant project from the list. To save a project use File I Save ¯ ¯ Project if the project already has a name (or you wish to use the default of minitab) or File I Save Project As if you wish to give the project a name. Not ¯ ¯ only are the contents of all worksheets and graphs saved, but the contents of the History folder in the Project window are saved as well and are available when the project is reopened. You can also supply a description of the project using File ¯ I Project Description and Þlling in the dialog box. Note that a description of ¯ a worksheet can also be saved using Editor I Worksheet I Description. When ¯ ¯ you attempt to open a new project or exit Minitab, you will be asked if you wish to save the contents of the current project. Now suppose that in the project evans we have a single worksheet containing 100 numeric values in each of C1 and C2 and have produced a scatterplot of C2 against C1. We open a new worksheet using File I New and choose Minitab ¯ Worksheet and click OK. There are now two ¯worksheets associated with the project called Worksheet1 and Worksheet2. Suppose that we also place 100 numeric values in C1 and C2 in Worksheet 2 and again plot C2 against C1. We then have two plots associated with the project evans called Worksheet 1: Plot C2*C1 and Worksheet 2: Plot C2*C1. These will all appear as individual windows on your screen, perhaps with some hidden, and any one in particular can be made active by clicking in that window or by clicking on the relevant entry in the list obtained when you use Window. You can also save individual ¯ worksheets in the project to Þles outside the project when a particular worksheet 213 214 Appendix A is active using File I Save Current Worksheet As. Similarly, when a graph ¯ ¯ window is active a graph in the project can be saved to a Þle outside the project using File I Save Graph As. ¯ ¯ With multiple worksheets in a project, it is easy to move data between worksheets using cut, copy, and paste operations. For example, suppose that we want to copy C1 and C2 of Worksheet 1 into C3 and C4 of Worksheet 2. With Worksheet 1 active, highlight the entries in C1 and C2, use Edit I Copy ¯ ¯ Cells, make Worksheet 2 active, click in the Þrst cell of C3, and use Edit I ¯ Paste Cells. ¯ It is possible to see what a project contains without opening it. To do this use File I Open Project, click on the project to be previewed and click ¯ ¯ on the Preview button. Similarly, worksheets can be previewed using File I ¯ Open Worksheet, clicking on the worksheet to be previewed and clicking on the ¯ Preview button. Appendix B Functions in Minitab B.1 Mathematical Functions Here is a list and description of the mathematical and statistical functions available in Minitab. All of these functions operate on each element of a column and return a column of the same length. Let (x1 , . . . , xn ) denote a column of length n. These functions can be applied only to numerical variables. absolute - Computes the absolute value, (|x1 | , . . . , |xn |) . antilog - Computes the inverse of the base 10 logarithm, (10x1 , . . . , 10xn ) . acos - Computes the inverse cosine function, (arccos (x1 ) , . . . , arccos (xn )) . asin - Computes the inverse sine function, (arcsin (x1 ) , . . . , arcsin (xn )) . atan - Computes the inverse tangent function, (arctan (x1 ) , . . . , arctan (xn )) . cos - Computes the cosine function when angle is given in radians, (cos (x1 ) , . . . , cos (xn )) . ceiling - Computes the smallest integer bigger than a number, (dx1 e , . . . , dxn e) . degrees - Computes the degree measurement of an angle given in radians. exponentiate - Computes the exponential function, (ex1 , . . . exn ) . ßoor - Computes the greatest integer smaller than a number, (bx1 c , . . . , bxn c). gamma - Computes the gamma function, (Γ (x1 ) , . . . , Γ (xn )) ; note that for nonnegative integer x, Γ (x + 1) = x!. lag - Computes the column (∗, x1, . . . , xn−1 ) . log-gamma - Computes the log-gamma function, P (ln Γ (x1 ) , . . . , ln Γ (xn )) ; note that for nonnegative integer x, ln Γ (x + 1) = xi=1 ln (i). loge - Computes the natural logarithm function, (ln (x1 ) , . . . , ln (xn )) . logten - Computes the base 10 logarithm function, (log10 (x1 ) , . . . , log10 (xn )) . nscore - Computes the normal scores function; see help. parsums - Computes the column of partial sums, (x1 , x1 + x2 , . . . , x1 + · · · xn ) . 215 216 Appendix B parproducts - Computes the column of partial products, (x1 , x1 x2 , . . . , x1 · · · · · xn ) . radians - Computes the radian measurement of an angle given in degrees. rank - Computes the ranks of the column entries, (r1 , . . . rn ) . round - Computes the nearest integer function i(x) with rounding up at .5, (i(x1 ), . . . , i(xn )) ; see help for more details on this function. signs - Computes the sign function −1 if x < 0 0 if x = 0 s(x) = 1 if x > 0 (s(x1 ), . . . , s(xn )) . sin - Computes the sine function when the angle is given in radians, (sin (x1 ) , . . . , sin (xn )) . sort¡ - Computes the ¢ column consisting of the sorted (ascending) column entries, x(1) , . . . , x(n) . ¡√ √ ¢ sqrt - Computes the square root function, x1 , . . . , xn . tan - Computes the tangent function when the angle is given in radians, (tan (x1 ) , . . . , tan (xn )) . B.2 Column Statistics Let (x1 , . . . , xn ) denote a column of length n. Output is written on the screen or in the Session window and can be assigned to a constant. The general syntax for column statistic commands is column statistic name(E1 ) where the operation is carried out on the entries in column E1 and output is written to the screen unless it is assigned to a constant using the let command. max - Computes the maximum of a column, x(n) . mean - Computes the mean of a column, x̄ = (x1 + · · · xn ) /n. median - Computes the median of a column (see Chapter 1). min - Computes the minimum of a column, x(1) . n - Computes the number of nonmissing values in the column. nmiss - Computes the number of missing values in the column. range - Computes the diﬀerence between the smallest and largest value in a column, x(n) − x(1) . ssq - Computes the sum of squares of a column, x21 + · · · + x2n . stdev - Computes the standard deviation of a column, r i 1 h (x1 − x̄)2 + · · · + (xn − x̄)2 . s= n−1 sum - Computes the sum of the column entries, x1 + · · · xn . Functions in Minitab B.3 217 Row Statistics Let (x1 , . . . , xn ) denote a row of length n. The general syntax is row statistic name E1 . . .Em Em+1 where the operations are carried out on the rows in columns E1 , . . ., Em and the output is placed in column Em+1 . rmax - Computes the maximum of a row, x(n) . rmean - Computes the mean of a row, x̄ = (x1 + · · · xn ) /n. rmiss - Computes the number of missing values in the row. rn - Computes the number of nonmissing values in the row. rrange - Computes the diﬀerence between the smallest and largest value in a row, x(n) − x(1) . rssq - Computes the sum of squares of a row, x21 + · · · + x2n . rstdev - Computes the standard deviation of a row, r i 1 h (x1 − x̄)2 + · · · + (xn − x̄)2 . s= n−1 rsum - Computes the sum of the row entries, x1 + · · · xn . Appendix C More Minitab Commands In this section, we discuss some commands that can be very helpful in certain applications. We will make reference to these commands at appropriate places throughout the manual. It is probably best to wait to read these descriptions until such a context arises. C.1 Coding The Data I Code command (Manip I Code in Version 13) is used to recode ¯ ¯ ¯ ¯ columns. By this we mean that data entries in columns are replaced by new values according to a coding scheme that we must specify. You can recode numeric into numeric, numeric into text, text into numeric, or text into text by choosing an appropriate subcommand. For example, suppose in the marks worksheet (Display I.4) we want to recode the grades in C2, C3, and C4 so that any mark in the range 0—39 becomes an F, every mark in the range 40—49 becomes an E, every mark in the range 50—59 becomes a D, every mark in the range 60—69 becomes a C, every mark in the range 70—79 becomes a B, every mark in the range 80—100 becomes an A, and the results are placed in columns C6, C7, and C8, respectively. Then the command Data I Code I Numeric ¯ ¯ ¯ to Text brings up the dialog box shown in Display C.1.1. The ranges for the numeric values to be recoded to a common text value are typed in the Original values box, and the new values are typed in the New box. Note that we have used a shorthand for describing a range of data values. Because the sixth entry of C4 is *, i.e., it is missing, this value is simply recoded as a blank. You can also recode missing values by including * in one of the Original values boxes. If a value in a column is not covered by one of the values in the Original values boxes, then it is simply left the same in the new column. 219 220 Appendix C Display C.1.1: Dialog box for recoding numeric values to text values. Note that this menu command restricts the number of new code values to 8. The session command code allows up to 50 new codes. For example, suppose in the marks worksheet we want to recode the grades in C2, C3, and C4 so that any mark in the range 0—9 becomes a 0, every mark in the range 10—19 becomes 10, etc., and the results are placed in columns C6, C7, and C8. The following command MTB >code(0:9) to 0 (10:19) to 10 (20:29) to 20 (30:39) to 30 & CONT>(40:49) to 40 (50:59) to 50 (60:69) to 60 (70:79) to 70 & CONT>(80:89) to 80 (90:99) to 90 for C2-C4 put in C6-C8 accomplishes this. Note the use of the continuation symbol &, as this is a long command. The general syntax for the code command is code (V1 ) to code1 ... (Vn ) to coden for E1 ... Em put in Em+1 ... E2m where Vi denotes a set of possible values and ranges for the values in columns E1 ... Em that are all coded as the number codei , and the results of this coding are placed in the columns Em+1 ... E2m , i.e., the recoded E1 is placed in Em+1 , etc. C.2 Concatenating Columns The Data I Concatenate command (Manip I Concatenate in Version 13) com¯ ¯ ¯ ¯ bines two or more text columns into a single text column. For example, if C6 contains m, m, m, f, f, reading Þrst to last entry, and C7 contains to, ta, ti, to, ta, then the entries in the Data I Concatenate dialog box shown in Display ¯ ¯ C.2.1 result in a new text column C8 containing the entries mto, mta, mti, fto, fta. More Minitab Commands 221 Display C.2.1: Dialog box for concatenating text columns. In the session environment, the concatenate command is available for this operation. The general syntax of the concatenate command is concatenate E1 ... Em in Em+1 where E1 , ..., Em , are text columns, and Em+1 is the target text column. C.3 Converting Data Types The Data I Code I Use Conversion Table command (Manip I Code I Use ¯ ¯ ¯ ¯ ¯ ¯ Conversion Table in Version 13) is used to change text data into numeric data and vice versa. As dealing with text data is a bit more diﬃcult in Minitab, we recommend either converting text data to numeric before input or using this command after input to do this. For example, in the worksheet marks (Display I.4) suppose we want to change the gender variable from text, with male and female denoted by m and f, respectively, to a numerical variable with male denoted by 0 and female by 1. To do this, we must Þrst set up a conversion table. The conversion table comprises two columns in the worksheet, where one column is text and contains the text values used in the text column, and the second column is numeric and contains the numerical values that you want these changed into. For example, suppose we have entered columns C6 and C7 in the marks worksheet, as shown in Display C.3.1. The Data I Code I Use Conversion Table command produces the dialog ¯ ¯ ¯ box shown in Display C.3.2, where we have indicated that we want to convert the text column C5 into a numeric column and that each m should become a 0 and each f should become a 1. 222 Appendix C Display C.3.1: Columns C6 and C7 in the marks worksheet as a conversion table. Display C.3.2: Dialog box for converting text column C5 of the marks worksheet into a numeric column with the conversion table given in columns C6 and C7. The general syntax for the corresponding session command convert is convert E1 E2 E3 E4 where E1 , E2 are the columns containing the conversion table, E3 is the column to be converted, and E4 is the column containing the converted column. C.4 History Minitab keeps a record of the commands you have used and the data you have input in a session. This information can be obtained in the History folder of the Project Manager window. The commands can be copied from wherever they are listed and pasted into the Session window to be reexecuted, so that a number of commands can be executed at once without retyping. These commands can be edited before being executed again. This is very helpful when you have implemented a long sequence of commands and realize that you made an error early on. Note that even if you use the menu commands, a record is kept only of the corresponding session commands. The journal command is available in the Session window if you want to keep a record of the commands in an external Þle. For example, More Minitab Commands 223 MTB >journal ’comm1’ Collecting keyboard input(commands and data)in file: comm1.MTJ MTB >read c1 c2 c3 DATA>1 2 3 DATA>end 1 rows read. MTB >nojournal puts read c1 c2 c3 1 2 3 end nojournal into the Þle comm1.mtj. The history is turned oﬀ as soon as the nojournal command is typed. C.5 Stacking and Unstacking Columns The Data I Stack command (Manip I Stack in Version 13) is used to literally ¯ ¯ ¯ ¯ stack columns one on top of the other. For example, in the marks worksheet (Display I.4) the Data I Stack I Stack Columns command brings up the dialog ¯ ¯ ¯ box shown in Display C.5.1, which has been Þlled in to stack columns C2, C3, and C4 into C6 with the values in C2 Þrst, followed by the values in C3 and then the values in C4. In C7, we have stored an index which indicates that column each value in C6 came from with a 1 every time a value came from C2, a 2 every time a value came from C3, and a 3 every time a value came from C4. It is not necessary to create such an index. Display C.5.1: Dialog box for stacking columns. 224 Appendix C In the Session window, this same result can be obtained using the stack command. The general syntax for the stack command is given by stack E1 E2 . . .Em into Em+1 where E1 , E2 , ..., Em denote the columns or constants to be stacked one on top of the other, starting with E1 , and with the result placed in column Em+1 . If we want to keep an index of where the values came from, then use the subcommand subscripts Em+2 which results in index values being stored in column Em+2 . To unstack values in a column by the values in an index column we use the Data I Unstack command (Manip I Unstack in Version 13). For example, ¯ ¯ ¯ ¯ given the columns C6 and C7 of the marks worksheet as described above, the dialog box shown in Display C.5.2 unstacks C6 into three columns by the values in C7. The three columns are C8, C9, and C10. Note that they are identical to columns C2, C3, and C4, respectively. We must always specify a column containing the subscripts when unstacking a column. Display C.5.2: Dialog box for unstacking columns. The general syntax for the corresponding session command unstack is unstack E1 into E2 . . .Em ; subscripts Em+1 . where E1 is the column to be unstacked, E2 , ..., Em are the columns and constants to contain the unstacked column, and Em+1 gives the subscripts 1, 2, ... that indicate how E1 is to be unstacked. Note that it is also possible to simultaneously unstack blocks of columns. We refer the reader to help or Help for information on this. ¯ Appendix D Programming in Minitab We can store Minitab commands in Þles that can be called on to execute these commands without having to type them. Also, we can program Minitab to carry out iterative calculations. These aspects involve us in a discussion of macros in Minitab. We present a very brief overview of this topic and refer the reader to the online manual for a more extensive discussion. There are two types of macros, global and local. Note that because it is possible to write a macro that will loop endlessly, it is important to know how to stop the execution if you feel it is running too long. To do this, simultaneously press the Control and Break keys. If the macro processor in Minitab Þnds an error in a macro, this is indicated in the Session window by **ERROR**. If there is an error in a Minitab command in the macro, this is indicated by *ERROR*. Minitab also provides a message that attempts to diagnose what has caused the problem. D.1 Global Macros A global macro is a set of commands in a Þle with the structure gmacro template body endmacro where template is a name for the macro, consisting of any characters but starting with a letter, and body is a set of Minitab commands, macro statements, or other macro names. In general, it is good form to use the Þle name for template, but this is not necessary. If the Þle has the extension .mac, then only the Þle name, immediately preceded by %, needs to be used to invoke it. Otherwise, the full Þle name must be used immediately preceded by %. Also, the full path name must be used unless the Þle is in the Macros subfolder of the default Minitab folder (where the program is stored). The statements gmacro and endmacro must always start and end the Þle, respectively. 225 226 Appendix D Suppose that we have placed the following statements gmacro generate note This macro generates 50 samples of size 20 from the Uniform[0,1] distribution do k1=1:50 random 20 c1; uniform 0 1. let c2(k1)=mean(c1) enddo histogram c2 endmacro in a Þle called generate.txt that is in the Macros subfolder of the Minitab folder. The macro is then invoked via the Minitab command MTB > %generate.txt and causes 50 samples of size 20 to be generated from the uniform distribution on the interval (0, 1), with each sample stored in C1 overwriting the preceding one, and causes the sample mean to be computed for each of these and to be stored in the corresponding element of C2. Finally, a histogram is produced of these 50 means. Clearly, this is a much more powerful method for carrying out simulations than the one we discussed earlier, as that was in essence limited by the size of the worksheet. Note the use of the do, enddo statements to perform the calculations iteratively. The note command is used to display the text on the same line, in the Session window. The note command can also be used to place comments in the code that explain how a program works. Otherwise, there is nothing printed in the Session window beyond the output from any commands that print to this window. If you want the code to be printed in the Session window, place an echo command before the code you want printed and a noecho command when you want to turn this oﬀ. Macros can be nested; i.e., a macro may have in its body a statement of the form %file where file contains a macro. D.2 Control Statements There are a number of statements that allow for control over the order of execution of Minitab commands in a macro. IF, ELSEIF, ELSE, ENDIF The if, elseif, else, endif command appears in the following structure if expression1 block1 Programming in Minitab 227 elseif expression2 block2 else block3 endif where expression1 and expression2 are logical expressions and block1, block2, and block3 are blocks of Minitab code. If expression1 is true, block1 is executed, if expression1 is false and expression2 is true, block2 is executed; and if both expression1 and expression2 are false, block3 is executed. Note that if one of the expressions is a column of logical values, the expression evaluates as false if all entries are false and as true otherwise. There can be up to 50 elseif statements between if and endif. A logical expression is any expression involving comparison and logical operators that evaluates to true (1) or false (0). For example, the code gmacro uniform random 100 c1; uniform -1 1. let k1=mean(c1) if k1<=-.5 let k2=0 elseif k1>-.5 and k1<=0 let k2=1 elseif k1>0 and k1<=.5 let k2=2 else let k2=3 endif print k2 endmacro generates a sample of 100 from the uniform distribution on the interval (−1, 1), computes the mean, and outputs 0 if the mean is in (−1, −.5], outputs 1 if the mean is in (−.5, 0], outputs 2 if the mean is in (0, .5], and outputs 3 if it is in (.5, 1). DO, ENDDO We saw an example of do, enddo in Section D.1. These statements appear in the following structure do Ki = list block enddo where list is a list of numbers, perhaps a patterned list such as −8 : 8/2, or stored constants. The Minitab code in block is executed for each value in the 228 Appendix D list with the constant Ki taking on that value. The numbers in the list can be in increasing or decreasing order. WHILE, ENDWHILE The while, endwhile statements appear in the following structure while expression block endwhile where expression is a logical expression and the code in block is executed as long as expression is true. For example, the code gmacro stuff random 2 c1; uniform 0 1. let k2=1 let k1=c1(k2) while k1<.5 let k2=k2+1 if k2<=2 let k1=c1(k2) else break endif endwhile print k2 endmacro generates a sample of 2 from the Uniform[0, 1], Þnds the Þrst value in the sample greater than or equal to .5, prints its location in the sample, and prints 3 if no such value is found. Note that the break statement transfers control to the Þrst statement following the end of the while-loop (this statement also works this way with do-loop). NEXT The next command can appear in a do, enddo or while, endwhile and passes control to the Þrst statement after the do or while, whichever is relevant, and the loop variable is set to the next value in the list. BREAK The break command can appear in a do, enddo or while, endwhile and passes control to the Þrst statement after the enddo or endwhile, whichever is relevant. Programming in Minitab 229 GOTO, MLABEL The goto command allows the macro to skip over a number of statements in the Þle. This takes the following form goto V .. . mlabel V where the goto V statement passes control to the statement following mlabel V and V is a number. CALL, RETURN Macros can be invoked from within macros by using statements of the form %file. This requires that the macros are in diﬀerent Þles. In fact, the macros can be in the same Þle, all having their own gmacro and endmacro statements and templates. When the Þle is invoked, the Þrst macro is processed. If the Þrst macro needs to refer to the other macros in the Þle, this is done via the call and return commands. For example, suppose that a Þle contains two macros and the Þrst macro needs to use the second one. This is implemented via the structure gmacro template1 body1 endmacro gmacro template2 body2 endmacro where somewhere in body1 there is the statement call template2 which transfers control from the Þrst macro to the second macro and somewhere in body2 there is the statement return which returns control to the Þrst macro. EXIT The exit command stops the macro. A typical use would be as part of an if, elseif, else, endif, where if a certain condition was satisÞed no further statements in the macro are executed. 230 Appendix D PAUSE, RESUME The pause command returns control to the Session window and session commands can then be invoked. Control is returned to the macro after a resume command is issued in the Session window. D.3 Startup Macro You can place commands that you want to be executed every time you start Minitab in a Þle called startup.mac in the Macro subfolder of default Minitab directory. For example, you can use the print command in such a Þle to send yourself reminders or the outÞle command if you always want to record your work in a particular Þle. D.4 Interactive Macros A macro can write data to the Session window and accept input from the user. We have already discussed the note command, which allows you to write comments to the Session window. The write command can be used to write the contents of columns and constants to the Session window. For example, the code gmacro stuff random 10 c1; uniform 0 1. write c1; file ’terminal’. endmacro generates a sample of 100 from the Uniform[0,1] distribution into C1 and then writes this on the Session window. Of course, we also could have accomplished this using the print command but recall that write allows for formatted output. Input can be provided to a macro from the keyboard while the macro is running. This is carried out using the special Þle name terminal with the read, set, or insert commands. For example, the code gmacro stuff echo note Read 10 observations into C1. set c1; file ’terminal’. print c1 endmacro allows us to enter data into C1 (stopping when we type end), and then prints C1 in the Session window. Note the use of the subcommand Þle for the set Programming in Minitab 231 command. You can also use the read, set, and insert commands in a macro with an end statement provided you place the data in the Þle as well. Also, data can be read in from an external Þle but the name of the external Þle must be on the same line as the Þle subcommand and not on the same line as the command as in the session command and, of course, enclosed in single quotes. The yesno command allows you to decide which commands you would like executed perhaps based on what the exec has already computed. For example, the code gmacro stuff note : Would you like to execute the macro random.txt? yesno k1 if k1=1 %random.txt endif endmacro asks whether or not you wish to execute the macro in random.txt. If you answer y, K1 is given the value 1 and the macro random.txt is executed; if you answer n, K1 is given the value 0 and the macro random.txt is not executed. D.5 Local Macros Local macros are more sophisticated than global macros. Basically, all the features we have discussed for global macros can also be used in local macros. The major diﬀerence is that global macros operate only on the worksheet while local macros create temporary local worksheets, which are used for computations without disturbing the global worksheet. The contents of local worksheets are not seen in the Session window. Also, local macros can have arguments and subcommands. It is through arguments, such as columns, constants, etc., which are passed to and passed out of the macro, that a local macro operates on the global worksheet. Subcommands to a local macro modify the behavior of the macro. Perhaps local macros are most useful when you want to create a truly new command in Minitab that behaves like the other commands we have been discussing throughout this manual. Because of their considerably more sophisticated nature, we do not discuss local macros any further here. Appendix E Matrix Algebra in Minitab Some versions of Minitab also have the facility for carrying out matrix algebra. This is useful sometimes as matrices can simplify some complicated algebra and numerical work. In particular, the computations associated with Þtting the regression models can be easily handled using matrix algebra. In this section, we assume that you have been introduced to the basic operations and concepts of matrix algebra. As an example, consider Þtting a quadratic polynomial β1 + β2 x + β3 x2 to n data points (x1 , y1 ), . . . , (xn , yn ). To do this, we must Þrst create the matrices and 1 x1 .. .. X= . . 1 xn x21 .. . x2n y1 y = ... . yn The matrix X is called the design matrix . In a more advanced statistics course, it is shown that best Þtting quadratic (least-squares quadratic) is given by b1 + b2 x + b3 x2 , where b1 −1 b = b2 = (X 0 X) X 0 y, b3 the vector of predicted values is given by ŷ = Xb, the residuals are given by r = y − ŷ, 233 234 Appendix E and s2 = (y − ŷ)0 (y − ŷ) n−3 is the estimate of σ 2 . For the general linear model E[y] = β1 x1 +β2 x2 +· · ·+βk xk , where x1 , . . . , xk are the explanatory variables and we observe the data (yi , x1i , . . . , xki ) for i = 1, . . . , n, we present the data in matrix form as x11 · · · x1k .. .. X = ... . . xn1 ··· xnk y1 y = ... . yn The best-Þtting linear model is b1 x1 + b2 x2 + · · · + bk xk , where b = (X0X)−1 X 0 y, ŷ = Xb, r = y − ŷ, and s2 = (y − ŷ)0 (y − ŷ) . n−k Notice that these formulas are the same for every linear model. Many other useful quantities associated with the linear model can be deÞned in terms of matrices. E.1 Creating Matrices In this section, we illustrate some commands for creating and operating on matrices. We describe the session commands and note the corresponding menu commands. Matrices in Minitab are denoted by M1, M2, ...., M100. Note that there can be at most 100 matrices. The name command can be used to give alternative names to matrices. For example, the command MTB > name m1 ’design’ assigns the name design to the matrix M1, and it can be referred to as such afterward with the name in single quotes. If we are going to use matrices, the Þrst step is to create them. This can be done in a number of ways. For example, we can use the Calc I Matrices I ¯ ¯ Matrix Algebra in Minitab 235 Read command. For example suppose we want to create the 5 × 3 matrix given ¯ by 1 1 1 1 2 4 X= 1 3 9 . 1 4 16 1 5 25 The Calc I Matrices I Read command brings up the dialog box shown in ¯ ¯ ¯ Display E.1.1. Here we have indicated that the number of rows is 5 and the number of columns is 3, the matrix is called M1 and we are going to input the entries from the keyboard. When we click on OK the corresponding session command appears in Session window and we can begin to input the matrix. Display E.1.1: Dialog box for creating a matrix. The corresponding session command is to use the read command as in MTB > read 5 3 m1 DATA> 1 1 1 DATA> 1 2 4 DATA> 1 3 9 DATA> 1 4 16 DATA> 1 5 25 5 rows read. MTB > print m1 Matrix m1 1 1 1 1 2 4 1 3 9 1 4 16 1 5 25 236 Appendix E which creates the 5 × 3 matrix M1 equal to X as displayed above. Note that the dimensions of the matrix accompany the read command with the number of rows followed by the number of columns and no end statement is required. Matrices can also be directly read in from a Þle using Calc I Matrices I Read ¯ ¯ ¯ by clicking on read from Þle in the dialog box of Display E.1.1. Sometimes, you want a matrix with constant entries. The Calc I Matrices ¯ ¯ I Define Constant command is available for this. For example, this command ¯ brings up the dialog box in Display E.1.2 and we use this to create a 3×3 matrix with a 1 in each entry. Display E.1.2: Dialog box to create a matrix with constant entries. The session command to create a matrix of constants is the deÞne command. The general syntax of this command is deÞne V D1 D2 E1 which creates a matrix E1 with D1 rows, D2 columns and every entry is the number V. Often, you want to create a matrix with given entries along its diagonal and 0’s in all the oﬀ-diagonal elements. Suppose we want the n entries in the column C1 to appear in an n × n diagonal matrix. Then the Calc I Matrices ¯ ¯ I Diagonal command with the dialog box Þlled in as in Display E.1.3 creates ¯ such a matrix M3. The session command to create a diagonal matrix is the diagonal command. The command diagonal E1 E2 creates a square matrix E2 with column E1 in the diagonal and all other entries 0. The matrix E2 is square with dimension equal to the length of E1 . If instead E1 is a matrix and E2 is a column, the diagonal of E1 is placed into the column E2 . Matrix Algebra in Minitab 237 E.1.3: Dialog box for creating a diagonal matrix. It is often convenient to copy the content of columns in a worksheet directly into a matrix and vice versa. For this we can use the Data I Copy I Columns ¯ ¯ ¯ to Matrix command. For example, the dialog box in Display E.1.4 creates a matrix containing the elements of columns C1, C2, C3, and C4. Note that the columns have to be of the same length. We can also copy the columns of a matrix into the columns of a worksheet using the Data I Copy I Matrix ¯ ¯ ¯ to Columns command. For large patterned matrices, this is probably the best way to create the matrix. Also, if the matrix is in an external Þle we can read the matrix into a set of columns and then use the Data I Copy I Matrix to ¯ ¯ ¯ Columns command to create the matrix. Display E.1.4: Dialog box for creating a matrix from columns in a worksheet. We can also use the session command copy to copy columns in a worksheet to a matrix. For example, the commands 238 Appendix E MTB > set c1 DATA> 5(1) DATA> end MTB > set c2 DATA> 1:5 DATA> end MTB > let c3=c2*c2 MTB > copy c1 c2 c3 m1 create the matrix M1, equal to X. If M1 is as above the command MTB > copy m1 c1-c3 copies the Þrst column of M1 into C1, the second column of M1 into C2, etc. Also, we can create copies of matrices using the copy command. For example, MTB > copy m1 m2 creates a matrix M2 with the same entries as M1. To delete matrices, use the erase command. For example, MTB > erase m1 deletes the matrix M1. E.2 Commands for Matrix Operations There are a variety of commands for performing calculations with matrices. Adding, Subtracting, and Multiplying Matrices The command Calc I Matrices I Arithmetic brings up the dialog box in Display ¯ ¯ ¯ E.2.1. We have Þlled this in so that we add the matrices M1 and M2 and place the result in matrix M3. We can use this command to subtract matrices and to multiply matrices. Note that dimensions must be appropriate to carry out these operations. Display E.2.1: Dialog box for carrying out matrix arithmetic. Matrix Algebra in Minitab 239 The corresponding session commands are given by add E1 E2 E3 which puts E1 + E2 into E3 where E1 , E2 , E3 , are matrices of the same dimension, subtract E1 E2 E3 which puts E1 − E2 into E3 , where E1 , E2 , E3 are matrices of the same dimension, and multiply E1 E2 E3 which puts E1 E2 into E3 , where E1 is a constant and E2 , E3 are matrices of the same dimension or E1 is a matrix with the same number of columns as the number of rows in matrix E2 . Inverting Matrices The command Calc I Matrices I Invert brings up the dialog box in Display ¯ ¯ ¯ E.2.2. We have Þlled this in so that we invert the matrix M1 and place the result in M4. Display E.2.2: Dialog box for inverting a matrix. The corresponding session command is given by invert E1 E2 which puts (E1 )−1 into E2 . Eigenvalues The command Calc I Matrices I Eigen Analysis brings up the dialog box in ¯ ¯ ¯ Display E.2.3. We have Þlled this in so that we place the eigenvalues of the matrix M1 in C1 and the corresponding eigenvectors in the matrix M2. 240 Appendix E Display E.2.3: Dialog box for an eigen analysis of a matrix. The corresponding session command is given by eigen E1 E2 E3 which puts the eigenvalues of symmetric matrix E1 into column E2 and the eigenvectors into matrix E3 . Transposing Matrices The command Calc I Matrices I Transpose brings up the dialog box in Display ¯ ¯ ¯ E.2.4. We have Þlled this in so that we transpose the matrix M1 and place the result in M2. Display E.2.4: Dialog box for transposing a matrix. Matrix Algebra in Minitab 241 The corresponding session command is given by transpose E1 E2 which puts (E1 )0 into E2 for matrix E1 . Example As an example, suppose we consider Þtting the least-squares quadratic when we have observed the data (1, 7.2365), (2, 17.2625), (3, 33.6455), (4, 55.4614), and (5, 82.2756). We construct the X matrix as M1 as indicated above, and the y values are placed in the matrix M2. The session commands MTB > transpose m1 m3 MTB > multiply m3 m1 m4 MTB > inverse m4 m4 MTB > multiply m4 m3 m5 MTB > multiply m5 m2 m6 MTB > print m6 Matrix M6 2.19780 2.10946 2.78638 compute the least-squares quadratic as 2.19780 + 2.10946x + 2.78638x2 . The session commands MTB > multiply m1 m6 m7 MTB > subtract m2 m7 m8 MTB > transpose m8 m9 MTB > multiply m9 m8 m10 Answer = 0.1880 MTB > let k1=.1880/2 MTB > print m7 m8 k1 store the predicted values in M7, the residuals in M8, and s2 in K1. Index Calc I Matrices I Read, 235 ¯ ¯ ¯ Calc I Matrices I Transpose, 240 ¯ ¯ ¯ Calc I Probability Distributions I ¯ ¯ Binomial, 96 ¯ Calc I Row Statistics, 31 ¯ ¯ call, return, 229 case, 8 cdf, 59 ceiling, 215 cell’s standardized residual, 138 chi-square distribution, 112 chi-square statistic, 138 chi-square test, 138 chisquare, 112, 140 climits, 152 code, 220 coeﬃcients, 151 colpercents, 137 column statistics, 31, 216 command line editor, 12 commands, 9 comparison operators, 29 concatenate, 221 conÞdence, 152 connection lines, 67, 68 constant, 151 constants, 8 continuation symbol, 12 control charts, 203 conversion table, 221 convert, 222 copy, 23, 237 copying cells, 22 copying columns, 23 correlate, 69 cos, 215 count, 40 abort, 12 absolute, 215 acos, 215 add, 239 additive, 178 adjacent values, 51 alternative, 108 and, 29 antilog, 215 aovoneway, 172 areas, 67, 68 arithmetic, 27 asin, 215 atan, 215 bar chart, 55 bernoulli, 81 binomial distribution, 96 body, 225 bootstrap distribution, 182 bootstrap percentile conÞdence interval, 185 boxplot, 51, 53 break, 228 brief, 160 by, 33 Calc I Calculator, 27 ¯ ¯ Calc I Column Statistics, 31 ¯ ¯ Calc I Make Patterned Data, 17 ¯ ¯ Calc I Matrices I Arithmetic, 238 ¯ ¯ ¯ Calc I Matrices I Define Constant, ¯ ¯ ¯ 236 Calc I Matrices I Diagonal, 236 ¯ ¯ ¯ Calc I Matrices I Eigen Analysis, ¯ ¯ ¯ 239 Calc I Matrices I Invert, 239 ¯ ¯ ¯ 243 244 coverage probability, 110 cumcnts, 42 cumpcts, 42 cumulative, 51 cumulative distribution, 40 cutpoints, 49 cutpoints, 51 cutting cells, 22 data, 167 Data I Copy, 23 ¯ ¯ Data I Copy I Columns to Matrix, ¯ ¯ ¯ 237 Data I Copy I Matrix to Columns, ¯ ¯ ¯ 237 Data I Delete Rows, 23 ¯ ¯ data direction arrow, 13 Data I Display Data, 18 ¯ ¯ data entry direct data entry, 12 importing data, 13 Data I Erase Variables, 23 ¯ ¯ Data window, 4, 12 date data, 7 deÞne, 236 degrees, 215 delete, 23 deleting rows, 23 density, 51 density curve of the N (µ, σ), 58 density histogram, 46 depths, 46 describe, 44 design matrix, 233 diagonal, 236 dialog box or window, 10 distribution free, 118, 191 do, enddo, 227 dunnett, 171 echo, 226 Edit I Command Line Editor, 12 ¯ ¯ Edit I Copy Cells, 22 ¯ ¯ Edit I Cut Cells, 22 ¯ ¯ Edit I Paste, 22 ¯ ¯ Edit I Undo Cut, 22 ¯ ¯ Index Edit I Undo Paste, 22 ¯ ¯ Editor I Insert Cells, 22 ¯ ¯ Editor I Insert Columns, 22 ¯ ¯ Editor I Insert Rows, 22 ¯ ¯ Editor I Worksheet I Description, ¯ ¯ 213 eigen, 240 empirical distribution function, 40, 42 endmacro, 225 eq, 29 erase, 23 erase, 238 erasing variables, 23 error variable, 145 exit, 5, 229 exiting Minitab, 5 explanatory variable, 145 exponentiate, 215 F, 123 F distribution, 122 family error rate, 169 Þle, 230 Þle extensions, 6 .mtw, 6 File I New, 13 ¯ ¯ File I Open Graph, 45 ¯ ¯ File I Open Project, 213 ¯ ¯ File I Open Worksheet, 25 ¯ ¯ File I Other Files I Export Special ¯ ¯ ¯ Text, 25 File I Other Files I Import Special ¯ ¯ ¯ Text, 13 File I Print Worksheet, 25 ¯ ¯ File I Project Description, 213 ¯ ¯ File I Save Current Worksheet, 24 ¯ ¯ File I Save Current Worksheet As, ¯ ¯ 24 File I Save Graph As, 45 ¯ ¯ File I Save Project, 213 ¯ ¯ File I Save Project As, 213 ¯ ¯ Þsher, 171 Þts, 151 Þtted value, 146 ßoor, 215 Index formatted input, 15 frequency, 40 frequency, 51 frequency histogram, 46 gamma, 215 gboxplot, 171 gdotplot, 171 ge, 29 geometric distribution, 102 gÞts, 151, 171, 178 ghistogram, 151, 171, 178 global macro, 225 gmacro, 225 gnormal, 151, 171 gorder, 151, 171, 178 goto, 229 Graph I Boxplot, 51 ¯ ¯ Graph I Chart, 55 ¯ ¯ Graph I Histogram, 46 ¯ ¯ Graph I Probability Plot, 60 ¯ ¯ Graph window, 45 gt, 29 gvariable, 151 gvariables, 171, 178 Help, 7 ¯ help, 7 Help I Help, 7 ¯ ¯ histogram, 51 if, elseif, else, endif, 226 individual error rate, 169 info, 21 inner fences, 51 inserting cells in a worksheet, 22 inserting columns in a worksheet, 22 inserting rows in a worksheet, 22 interactive macros, 230 interquartile range, 51 invcdf, 60 invert, 239 journal, 222 kruskal-wallis, 195 Kruskal-Wallis test, 194 245 lag, 215 le, 29 leaf unit, 46 leaves, 46 let, 20 local macros, 231 log odds, 198 log-gamma, 215 loge, 215 logical operators, 29 logistic regression, 197 logit link function, 197 logten, 215 lower hinge, 51 lower limit, 51 lt, 29 macro, 181 mann-whitney, 192 Mann-Whitney statistic, 191 matched pairs permutation test, 188 mathematical functions, 28 matrix algebra, 233 max, 216 maximums, 167 mcb, 171 mean, 216 means, 167, 178 median, 216 medians, 167 menu bar, 4 menu commands, 3, 9 midpoints, 51 min, 216 minimums, 167 missing, 138 missing values, 13 model checking, 145 mse, 152 mu, 59 multiply, 239 n, 167, 216 name, 21, 234 names for variables and constants, 21 246 ne, 29 next, 228 nintervals, 51 nmiss, 167, 216 noall, 138 noconstant, 151 noecho, 226 nominal logistic regression, 200 noncentral chi-square, 125 noncentral F , 125 nonparametric, 118, 191 nopvalues, 69 normal, 82 normal, 59 normal probability plot, 60 not, 29 note, 226 nscore, 215 nscores, 62 numeric data, 7 numeric variable, 8 observation, 8 odds, 198 onewayaov, 171 or, 29 ordinal logistic regression, 200 outer fences, 51 p chart, 208 parproducts, 216 parsums, 215 pasting cells, 22 patterned data, 17 pause, resume, 230 pchart, 210 pdf, 59 percent, 51 percents, 42 permutation test, 185 pÞts, 152 pie chart, 55 plimits, 152 plot, 69 pooled, 122 population distribution, 80 Index power, 110 predict, 152 predictor variable, 145 printing data in the Session window, 18 probit link function, 198 project, 8 Project manager window, 21 projection lines, 67, 68 projects, 213 proportion, 40 proportion, 167 psdÞts, 152 pth percentile, 58 radians, 216 random, 81 random permutations, 79 range, 216 rank, 216 ranks, 34 read, 16 regress, 73 relative frequency, 40 relative frequency histogram, 46 repeated sampling, 80 replace, 79 residual, 146 residuals, 152 response variable, 145 restart, 23 retrieve, 27 rmax, 217 rmean, 217 rmiss, 217 rn, 217 round, 216 row statistics, 31, 217 rowpercents, 137 rrange, 217 rssq, 217 rstdev, 217 rsum, 217 rtype, 152 S chart, 207 Index sample, 79 sample with replacement, 79 save, 27 scatterplot, 65 schart, 208 Search I Help, 7 ¯ sequential analysis of variance, 157 session command, 4 session commands, 11 session subcommand, 4 Session window, 4 set, 18 sigma, 59 sign conÞdence interval, 119 sign test, 118 signs, 216 sin, 216 sinterval, 119 sort, 33, 216 sorting, 33 sqrt, 216 sresiduals, 152 ssq, 216 stack, 224 standard error of the estimate, 90 standardized residual, 147 startup macro, 230 Stat I ANOVA I Main Eﬀects, 171 ¯ ¯ ¯ Stat I Basic Statistics I 1-Sample ¯ ¯ Z, 105 ¯ Stat I Basic Statistics I Display ¯ ¯ ¯ Descriptive Statistics, 43 Stat I Basic Statistics I Store De¯ ¯ ¯ scriptive Statistics, 43 Stat I Tables I Tally, 41 ¯ ¯ ¯ stats, 167 stdev, 167, 216 stemplots, 45 stems, 46 stest, 119 store, 43 student, 115 Student distribution, 115 subcommands, 12 subtract, 239 sum, 216 247 sums, 167 t conÞdence interval, 116 t test, 117 table, 137, 140 tally, 42 tan, 216 taskbar, 6, 22 template, 225 text data, 7 text variable, 8 tinterval, 116 toolbar, 12 totpercents, 137 transpose, 241 tsplot, 58 ttest, 117 tukey, 171 two-sample t conÞdence interval, 120 two-sample t test, 120 two-sample z conÞdence interval, 120 two-sample z test, 120 twosample, 122 twowayaov, 178 undoing cutting or pasting, 22 uniform, 89 upper hinge, 51 upper limit, 51 Version 14, 3 Weibull distribution, 103 while, endwhile, 228 whiskers, 51 Wilcoxon rank sum statistic, 191 Wilcoxon signed rank statistic, 193 Wilson estimate, 129 Window I Project Manager, 21 ¯ Window I Session, 4 ¯ ¯ winterval, 193 worksheet, 7 wtest, 193 x̄ chart, 203 xbarchart, 206 248 yesno, 231 z conÞdence interval, 105 z test, 106 zinterval, 106 ztest, 108 Index