Table of ContentsNext


Linear Fit: Basic Usage

Here we describe fitting a dataset to a polynomial. We assume that the files containing the variable names and the data itself have been selected from the File Selection system: the document describing the usage of this system may be found here.

There are two main screens to the interface:

  1. The Fit Setup Screen
  2. The Fit Results Screen

The Fit Setup Screen

Selecting the Variables

Let us assume that the dataset contains three variables, which you have named temp, voltage, and errVoltage: we shall not make any assumptions about what these variables may be, although the names are somewhat suggestive.

The first step is to tell the fitter which variables correspond to the dependent variable, independent variable, etc. to be used in the fit. In a graph, the "independent variable" is the one that is graphed on the horizontal axis, and the "dependent variable" is graphed on the vertical axis. the screen to do this selection looks like this:

Step 1: Select the variables for the fit

Using the choices below, fill in the blanks in this phrase describing the fit:

Fitting  with error  versus  with error
for each variable, you may choose a predefined expression
Dependent variable
Error in the dependent variable
Independent variable
Error in the independent variable

We shall choose the dependent variable to be voltage whose error is errVoltage; the independent variable is temp and we shall assume that the error in the temperature is zero.

The easy way to do this is to click on the variable names corresponding to the dependent and independent variables of the fit and their corresponding errors. You may also type directly in the blank fields in the line that begins with:

Fitting

Notice that there is a button labelled DataPoint in the list of possibilities for the independent variable. This will use the line number in the data file as the value of the independent variable. When you click on this button, if there is no value for the error in the independent variable, it will be set to zero. If there is already a value for the error in the independent variable it will not be changed.

Either way, when we are done this part of the Fit Setup screen looks like this:

Step 1: Select the variables for the fit

Using the choices below, fill in the blanks in this phrase describing the fit:

Fitting  with error  versus  with error
for each variable, you may choose a predefined expression
Dependent variable
Error in the dependent variable
Independent variable
Error in the independent variable

Warning logoBecause of the meaning of independent and dependent in describing variables for a fit, it is an error to have an explicit error in the independent variable but not the dependent one. Thus you cannot fit temp with error zero versus voltage with error errVoltage.

If you are typing directly in the blank fields to define one of the variables for the fit, you may type in any valid Mathematica expression involving the variables. For example, if you wanted the error in the independent variable to be 10% of the value of temp, you could type directly in the final field, ending up with:

Step 1: Select the variables for the fit

Using the choices below, fill in the blanks in this phrase describing the fit:

Fitting  with error  versus  with error

An introduction to simple Mathematica commands and syntax may be found here.

Selecting the Powers

By default, the fitter fits to polynomials in the independent variable. The next section of the Fit Setup screen allows you to choose the order of the polynomial. Initially the screen looks like this:

Step 2: Select the powers for the fit

Next, select which powers of the independent variable you wish to use in the fit:
Enter them directly, separated by commas or spaces:
Or use these buttons to toggle:
0 1 2 3 4 5 6 7 8 9

Recall that in our example, we have chosen the dependent variable to be named voltage and the independent variable to be named temp. If we wanted the voltage versus temp to be fit to a straight line:

voltage = m * temp + b

where m is the slope and b is the intercept, this corresponds to a polynomial with powers of 0 and 1 of the independent variable. Thus you could click the button labelled 0 and then the button labelled 1 to set up this straight line fit. This part of the screen would then look like:

Step 2: Select the powers for the fit

Next, select which powers of the independent variable you wish to use in the fit:
Enter them directly, separated by commas or spaces:
Or use these buttons to toggle:
0 1 2 3 4 5 6 7 8 9

You may also type the 0 and the 1 directly if you prefer, separated by commas or just spaces. This allows you to select a power, such as -2 for which we have not provided a button.

If you select a power such as -2 by typing it directly into the field, then by pressing Tab or Enter while the cursor is still in the field will cause a checkbox corresponding to that power to be added to the row of checkboxes.

Say you wish to fit to a straight line with the intercept forced to be zero. This corresponds to not having a zero power in the fit. If you have already chosen a zero power, as above, clicking on the 0 button deselects it, producing:

Step 2: Select the powers for the fit

Next, select which powers of the independent variable you wish to use in the fit:
Enter them directly, separated by commas or spaces:
Or use these buttons to toggle:
0 1 2 3 4 5 6 7 8 9

The final section of the Fit Setup screen looks like this:

Step 3: Execute the fit

Finally, click on the Perform the fit button below. To enlarge the text boxes so that all expressions are visible, click on Refresh. To start this fit from scratch, click on Clear. Click on Advanced Options to change the basis functions and certain parameters of the fitting algorithm. To send a message to the maintainers of this software, click on Comment. To switch to terse mode, click on Terse. If you're done with the fitter, click on End.

The meanings of the buttons should be fairly self-evident.

If you have already performed a fit with this session of the program, you will have the option or returning to this Fit Setup screen to perform another fit. In this case the screen will have one and possibly two differences from as shown above:

  1. The buttons on the bottom of the screen will include a Results button, which will return you to the Fit Results screen for the previous fit.
  2. If you have typed an expression to be used as a variable or error in the fit directly into the corresponding field, a button will now appear corresponding to that expression.

Click here to go to the top of this page.


The Fit Results Screen

When you perform a fit, the results are summarised by a single screen which presents both numerical and graphical information about the results of the fit, plus a section for deciding what to do next.

Imagine you have fit a dataset of voltage with error errVoltage versus temp with no explicit error to a straight line. The Fit Results screen could look like this:

**** Fit number 1 ****

voltage with error errVoltage versus temp with no error
plot
A0 = –0.981 ± 0.021
A1 = 0.04122 ± 0.00036
Chi Squared = 21.053 for 19 degrees of freedom.
(Chi-squared probability: 33.385)
What would you like to do now?
Print these results Progress of Mathematica during this computation Change the plot options Continue with another fit Comment to the maintainer Go to terse mode Exit the fit program Help

We shall go through the above screen piece by piece.

We start in the upper-left corner and work down through the textual information.

First the screen confirms the variables being fit.

Next, the values of the fit parameters and the estimated errors in those parameters are given. The parameters are named An where n is one of the powers you selected in the Fit Setup screen. So A0 is the intercept of the straight line, and its value is –0.981 ± 0.021. Similarly the slope, A1, has a value of 0.04122 ± 0.00036.

Finally, the chi-squared statistic, the number of degrees of freedom, and the chi-squared probability are given. Information on what these mean may be found here.

The graph shows the data, including error bars, and the results of the fit. The small inset graph shows the residuals, which are the differences between the fitted value and the experimental value of the dependent variable. For a good fit, we expect these residuals to be more-or-less randomly distributed about zero. Thus, the residual plot indicates possible problems with this fit.

You may wish to know that the above dataset is for a thermocouple calibration, and was taken by Philip R. Bevington, who presented it in Data Reduction and Error Analysis (McGraw Hill, 1969), pg. 138.

Here is a straight line fit to another different dataset, this time when the data do not have explicit errors. In this case there are only two variable names for the data, which are temp and press respectively.

abszero.vars/abszero.dat

**** Fit number 1 ****

temp with no error versus press with no error
plot
A0 = –263. ± 18.
A1 = 3.71 ± 0.21
Sum of Squares = 133.899 for 3 degrees of freedom.
(Assumed statistical error in the dependent variable: 6.680)
What would you like to do now?
Print these results Progress of Mathematica during this computation Change the plot options Continue with another fit Comment to the maintainer Go to terse mode Exit the fit program Help

Some differences from the previous fit result can be seen.

You may wish to know that this data is for a constant volume gas thermometer. It was taken by an unidentified student and was reported in John R. Taylor, An Introduction to Error Analysis: The Study of Uncertainties in Physical Measurements (University Science Books, Mill Valley California, 1982) pg. 160.

Every Fit Results screen has the same seven choices along the bottom. These are:

Finally, the program stores every fit that you have done in a particular session. Imagine that you have chosen to do a second fit of the constant volume thermometer data, this time to a second order polynomial. Then the very bottom of the Fit Result screen will look like this:

Or, choose a fit to display from the list below:
Fit number 2: temp with no error versus press with no error (using powers 0, 1, and 2)
:Fit number 1 temp with no error versus press with no error (using powers 0 and 1)

Thus you may toggle back and forth between the two (or more) fits that you have performed.

Click here to go to the top of this page.


Table of ContentsNext


Authors

This help document is Copyright © 1999, 2000 David M. Harrison. The sample screens are Copyright © 1999, 2000 Solomon R.C. Douglas and David M. Harrison. This is version 1.8 of the help document, date (m/d/y) 03/08/00.