Chapter 5 Exercise: Graphing and Least Squares Fitting in Quattro Pro 5.1 Purpose The purpose of this experiment is to become familiar with using Quattro Pro to produce graphs and analyze graphical data. 5.2 Introduction While Quattro Pro has a lot of useful features for data analysis, etc. it was designed primarily for use by people in business rather than for scientists, and so there are some things which scientists wish to do which require a little effort in Quattro Pro. Graphical analysis is one of the areas where this is true, as you shall see. (Even with the extra work, it s a lot more convenient than doing it all by hand.) 5.3 Theory: Graphing 5.3.1 Graph Type The graph type mainly used by scientists is an x-y graph. However, since it is not the most common type used by business people, it is listed as a specialty graph in Quattro Pro. Do not choose a line graph!
5-2 Exercise: Graphing and Least Squares Fitting in Quattro Pro 5.3.2 Text The main text of a graph consists of x and y titles, a main title and perhaps a sub title. All of these may be set in Quattro Pro. (If you want to place these text fields in the spreadsheet itself, and have them show up on the graph, you can do that by giving \ cellname instead of the actual text itself when prompted for the text.) 5.3.3 Series Quattro Pro allows you to plot up to 6 different series of y data, although you are only allowed 1 x series. This takes a while to get used to; it means that to plot several different sets of (x, y) data requires you to arrange the data in a certain way. Each series can be customized, with choices for many things, including the following: 1. Formats Each series can be plotted with lines, symbols, or both. 2. Markers There are many possible symbols which can be used for each series. 3. Lines There are several line types available for each series.one important fact about how lines are used to connect points in a series; only points which are in adjacent cells are joined by lines. This is actually useful as you can use one series to produce a whole bunch of lines, as long as you set up the data with blank spaces between points which you do not want joined. 5.3.4 Error Bars Some spreadsheets now allow some use of error bars; however they are usually quite restricted. Either all error bars must be the same size, or they must all be a fixed percentage of x or y values. This only covers a small subset of actual circumstances, so the following explains how to handle the general case. 1. What are error bars? Uncertainties in quantities plotted on a graph are shown by error bars. Figure 5.1 shows a point with its error bars. (Error bars may be in one or both directions, and they may
5.3 Theory: Graphing 5-3 Figure 5.1: Point with Error Bars even be different in the positive and negative directions.) The range of possible values for the data point in question actually includes any point bounded by the rectangle whose edges fall on the error bars.(actually, the point s true value is most likely to fall within the ellipse whose extents fall on the error bars. This is because it is unlikely that the x and y measurements are both in error by the maximum amount at the same time.) 2. Setting up graph to display error bars The way we can plot points with error bars in Quattro Pro is to realize that a point with an error bar can be seen as 5 points. See Figure 5.2. The single data point shown can actually be thought of as two sets of three data points, with the three points in each set connected by lines; (the lines are the error bars in this case.) One set is plotted with a and consists of the points (x x, y), (x, y), (x + x, y) and the other set is plotted with a and consists of the points (x, y y), (x, y), (x, y + y) as shown in Figure 5.3. The way to arrange these points in a spreadsheet to accomplish this is shown in Figure 5.4. Note the placement of the blank cells which limit the lines drawn to only include each set of 3 points to make an
5-4 Exercise: Graphing and Least Squares Fitting in Quattro Pro Figure 5.2: Endpoints of Error Bars Figure 5.3: Generating Error Bars with Quattro Pro error bar. (This makes use of the fact that points in a series are not connected by lines if they are not in adjacent cells.) Note also that all three series are the same length; otherwise the x and y values would not properly correspond. Plotting the points this way in Quattro Pro can be done by setting the format for these two series to both symbols and lines and picking the appropriate symbol for each series. This may seem like a lot of work for one data point, but the advantage to using the spreadsheet is that you can copy the block you ve created as many times as you need for the number of data points you have. So once you ve set
5.4 Theory: Least Squares Fitting 5-5 Figure 5.4: Series to Create Error Bars it up properly for ONE point, doing several is not much more work. You don t necessarily have to put markers on the ends of the error bars; the value in doing so is to make it clear that you re not just using + symbols for plotting the data points. Also, if you are including a grid on your graph, error bars without markers on the end may be hard to distinguish. However if the error bars will be clearly identifiable without markers, you don t need to use them. 5.4 Theory: Least Squares Fitting The point of plotting a graph in an experiment is usually to extract information from the graph; often the data is plotted in such a manner that the model being tested suggests that the data should fit a straight line. If it does, then getting the slope and y intercept of the line of best fit along with their associated uncertainties is necessary. One of the two usual ways to determine the uncertainty in a graphical quantity is to calculate the standard error. (The other involves finding lines of maximum and minimum slope.) The following sections discuss using Quattro Pro to do least squares fitting and to calculate standard errors.
5-6 Exercise: Graphing and Least Squares Fitting in Quattro Pro 5.4.1 By formulae Elsewhere the lab manual explains how to calculate a least squares fit to a set of data. This can be done in Quattro Pro by creating additional cells corresponding to each data point which contain, respectively, x 2, y 2 and xy. At the end of the data, these quantities can be totaled to give the sums necessary to do the least squares fit. 5.4.2 Using Regression the Wrong Way (Like with error bars, spreadsheets sometimes by default do not do calculations precisely as we might like. This is another example, and later you will again be shown the right way.) Quattro Pro has a menu option which allows the user to do a least squares fit to your data. It can be found under Tools Numerical Tools. The Independent variable is your x data block, the Dependent variable is your y data block, and the Output block should point to a blank area in the spreadsheet where Quattro Pro can put the results. Y-intercept indicates whether or not the y intercept should be computed, (it should for scientists), and Go actually starts the calculation. This is an important difference between using menu items in Quattro Pro as opposed to setting up formulas yourself to do something; formulas automatically recalculate whenever a data value changes; menu commands do not. 5.4.3 Meaning of Regression Output The output of a typical regression is shown in Figure 5.5. Comparing the result given by the least squares fit using your formulas with your regression output should indicate what several of the quantities are. Constant is the y intercept, a 0. Std Err of Y Est is σ, the standard deviation of the data. R 2 is a quantity which is a measure of how well the data fits the line. We will not use it, but you may see it in a statistics class or text. No. of Observations is the number of data points, N.
5.4 Theory: Least Squares Fitting 5-7 Figure 5.5: Ordinary Regression Output Degrees of Freedom is the number of extra data points, and is equal to N 2 for a straight line fit. X Coefficient is the slope, a 1. Std Err of Coef is the standard error of the slope, a 1. Note that S, the sum of squares error, and a 0, the standard error of the y intercept are not given. S can be calculated given that S σ = N 2 (If you use regression to do least squares fitting for a lab report, quote the quantities given with the names used in the lab manual. The somewhat cryptic names used by Quattro Pro are not very meaningful.) 5.4.4 Using Regression to get Standard Errors; ie. the Right Way A normal regression in Quattro Pro gives the standard error of the slope, but not the standard error of the y intercept. To get the standard error of the y-intercept proceed as follows:
5-8 Exercise: Graphing and Least Squares Fitting in Quattro Pro Figure 5.6: Series for Modified Regression 1. Modify your x data as follows: Put a column of 1 s to the left of your x column and make your independent variable include BOTH columns as in Figure 5.6. 2. Set your y block as the dependent, as usual. 3. Set the y intercept to Zero and do the regression. This will produce a result with 2 x-coefficients; one is the slope and one is the y intercept and the standard errors of both are now given, as shown in Figure 5.7. 5.4.5 Displaying Lines To display a line on the graph, such as a best fit line, one can use a series which has not yet been used. When one knows the equation of a line, all one needs is two endpoints so that a line can be drawn between them. To allow this, include 2 values at the end of your x series, x min and x max which are the minimum and maximum values from the x data, respectively. Placing the y values calculated from the line equation in the corresponding cells of one of the unused series (3 to 6) will allow a line to be plotted between those points. (Set the format for that series to lines only.) Having calculated the slope and y intercept of the line of best fit using formulas or Quattro Pro s built in regression, you can now calculate the y values corresponding to x min and x max and enter them in one of the unused plotting series as mentioned before. Set the weight of the markers on the
5.5 Procedure 5-9 Figure 5.7: Series for Modified Regression line to zero so that they will not show up; ie. the endpoints of the line of best fit have no special significance, so you don t want them highlighted. 5.5 Procedure 5.5.1 Plotting a Graph 1. Create a spreadsheet with the data from Table 1 which will plot the data points with their associated error bars. 2. Set up the series, etc. so that you can view the graph. 3. Show the TA your graph. 4. Fill in columns in your spreadsheet containing x, y, x 2, y 2 and xy for each of the data points. Remember that the least squares fit gives values for b, the y-intercept,
5-10Exercise: Graphing and Least Squares Fitting in Quattro Pro i x i x i y i y i 1 0.40 0.03 0.0 0.1 2 0.77 0.04 2.0 0.1 3 1.35 0.04 2.7 0.1 4 1.72 0.05 4.3 0.1 Table 5.1: Sample Experimental Data and m, the slope, as follows: b = ( y i ) ( x 2 i ) ( x i ) ( x i y i ) N ( x 2 i ) ( x i ) 2 (5.1) and m = N ( x i y i ) ( x i ) ( y i ) N ( x 2 i ) ( x i ) 2 (5.2) Also, the standard error in the intercept is and the standard error in the slope is σ b = σ x 2 i N ( x 2 i ) ( x i ) 2 (5.3) N σ m = σ N ( x 2 i ) ( x i ) 2 (5.4) 5. Sum the columns and use the results to calculate the slope, y intercept, and their standard errors. 6. Modify your data as explained above and perform a regression. 7. Make a table to show what field (if any) in the regression output corresponds to each of the following quantities from your least squares fit:s, σ, N, m, b, σ m, σ b. (Show how to calculate the one quantity not given from the rest. Hint:if you know S you can get σ and vice versa.)
5.5 Procedure 5-11 8. Modify the data as just described so that you can display the line of best fit on your graph. 9. Print the graph with appropriate labels, etc. If the y errors were all 0.7 instead of 0.1 then one would have to use lines of maximum and minimum slope to determine the uncertainties in the slope and y intercept. 10. Bonus: Make the change just mentioned, plot the lines of maximum and minimum slope on the graph, print the graph, and give the uncertainties for the slope and y intercept.