Physics 120/130

The Least Squares Fit of a Straight Line and Newton's Laws

I. Theory

A. The Null Test

Now that we understand how to combine errors in order to report a 90% confidence interval for a calculated value, we can proceed to investigate the procedure for comparing a measured value with an accepted value, or two measured values with each other, to determine whether they are equal. In other words, let's suppose that the area of your block in Lab 1 was given as 134.0 +/- 0.3 cm2 and that your measurement was 133.4 +/- 0.4 cm2. Can we say that there is a significant difference between these two areas? To put the question another way, is the difference between these two figures due to random effects only?

At first glance you might suspect that the two figures do not differ significantly, since the difference between them is 0.6 cm2 and this difference is less than the sum of the confidence intervals, which is 0.7 cm2.  Once again, this simple conclusion is wrong for the same reason - the odds don't favor being too low on one measurement while simultaneously being too high on the other.  Theory tells us that to 90% confidence the difference between the two figures, if due to random effects only, can be expected to be no larger than the square root of the sum of the squares of the individual confidence intervals given above:


This is an example of using statistical methods to test a null hypothesis In the present case, our hypothesis might be stated in the form of a question: Is

Aaccepted - Ameasured = 0?;

that is, are the two areas different from one another.  When we subtract these two numbers, the presence of random error makes it unlikely that we would get exactly zero. Another way to state this question is: Is the number 0 contained in the appropriate 90% confidence interval when you subtract the two areas? For our example (134.0 +/- 0.3 cm2) - (133.4 +/- 0.4 cm2) = (0.6 +/- 0.5 cm2) does not include 0. In the present case, since the two values for the area differ by more than can be accounted for due to random effects only, the conclusion that the two areas are the same is probably false.

Suppose that your two numbers for the area had differed from one another by an amount that could easily be attributed to random error, or even agreed with one another exactly.  Would this "prove" the hypothesis that the areas are equal?  No.  The agreement might be only a statistical anomaly.  Even if repeated experiments always agreed with one another within the interval expected due to random error, we would have to admit the possibility that continued improvement in the precision of the experiment might ultimately lead to detecting a statistically significant difference.  This approach illustrates an important philosophical principle concerning experimental results.  Although we can be reasonably sure (60% confident, 90% confident) that a given hypothesis is false (i.e, two numbers differ by more than we can account for due to random effects only), we can never prove with equal assurance that it is true.

B. The Least Squares Fit

In many experiments there is a linear relationship between the measured variables. For example, the velocity of an object in free fall changes linearly with time, in the absence of air resistance. When we plot a set of data and find that it approximates a straight line, the next question is how to find the slope and the intercept of the line which seems to provide the best fit. In last week's lab, our plot of average speed versus time showed us an excellent example of how real data is scattered around a straight line. We do not expect to find an exact fit because we know that the presence of random error causes this scatter away from an ideal straight line. We can find approximate values for slope and intercept by using a straight edge to draw a line which seems to "split the difference" between the scattered points. A more exact answer is given by the Method of Least Squares, to which we now turn.

Just as in our earlier statistical procedures, the underlying model in this case is the normal, or Gaussian, distribution. We assume that, for each given value of x, repeated measurements of y would yield results distributed about some mean with some standard deviation. Although different mean values of y would be obtained for different choices of x, the model assumes that the standard deviation in the values of y is the same for every x. This assumption makes it possible for us to find the best fit even if we measure only one value of y for each value of x.

The process of finding this best fit proceeds as follows: If there were no random errors present, all of our experimental results y would fall exactly on a line given by the equation

For a given value of x (denoted by xi), the value y that we actually obtain (denoted yi) will differ from the ideal (error-free) value of y by an amount given by

Based on the mathematics of the Gaussian distribution that we discussed in the first lab, the probability that this value of y occurs is given by


A similar statement can be made for each of the y values we have obtained. Now, in general, the overall probability for the occurrence of successive events is given by the product of the individual probabilities for each event. The probability P that N measurements will yield the N experimental values of y that we have obtained is

Our problem then is this: find values for the slope m and intercept b which will make this probability as large as possible. In other words, find m and b such that the values of y which we have obtained from our measurements represent a set of values of y which is most likely to occur.

The maximum value of P will occur when the exponent has its minimum value, i.e., when the sum of the squares of the deviations of your measured points from the fitted line is a minimum. This minimum value may be found using standard techniques from the differential calculus, and occurs when m and b are given by




Pretty clearly, the computations involved in finding m and b will get tiresome even for a small number of experimental points. And just as clearly, the procedure can be carried out systematically by a computer. The use of the computer to find the best-fit line has already been demonstrated for you.  It is called a "trend-line" in Excel.

In addition to computing the slope and intercept, Excel can perform the mathematical operations to give estimates of the standard errors in the slope and the intercept. These are given by the linest command described in the online help or the Excel Hints sheet provided. Provided your computations are based upon at least five data points, you may expect that the odds are approximately 9 out of 10 that the slope computed from an infinite number of measurements will fall within 2 standard errors of the slope you have obtained, and similarly for the intercept. (Since we have only one estimate of the slope and one estimate of the intercept, the standard error and the standard deviation are identical.) Thus, to 90% confidence, your slope is m " 2*Std Err of m and your intercept is b " 2* Std Err of b, where m, b, and the standard error of each are given by the linest command.

In order to use the computer program intelligently, keep in mind the following points:

  1. In your experimental procedure always fix one variable (x) then measure the other (y).
  2. You must enter at least three data points or the least squares procedure will not work. You need at least five data points to get approximate 90% confidence intervals in the slope and intercept.
  3. The x,y data you enter might not be simply the experimental values you have obtained. For example, when you were entering the data from last week's experiment to measure g, you entered for y the average velocity calculated from measured position and for x time found from using the data point number.
  4. No matter how wildly scattered your data may be, or even if the variables are not linearly related, the computer can always come up with a slope and an intercept which is a best fit in the least squares sense. It's a good idea to make at least a crude plot of your data to be sure that your chosen method of plotting does yield something reasonably close to a straight line. (The smaller the standard error in the slope, the closer your points come to fitting a straight line exactly.)