0% found this document useful (0 votes)
28 views

Linear Fit - Tutorial (Rev 1.1)

This document provides guidance on linear regression analysis and calculating uncertainties. It explains how to calculate the standard deviation and uncertainty for a sample average using the Student's T-distribution. It also discusses how to perform linear fits in OriginLab, Matlab, and Excel, and calculate the uncertainty of the slope using the standard error and T-value. Sample plots are shown as examples of how to present the linear fit, data points, error bars, legends, and a summary chart in the report.

Uploaded by

바나나우유
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Linear Fit - Tutorial (Rev 1.1)

This document provides guidance on linear regression analysis and calculating uncertainties. It explains how to calculate the standard deviation and uncertainty for a sample average using the Student's T-distribution. It also discusses how to perform linear fits in OriginLab, Matlab, and Excel, and calculate the uncertainty of the slope using the standard error and T-value. Sample plots are shown as examples of how to present the linear fit, data points, error bars, legends, and a summary chart in the report.

Uploaded by

바나나우유
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Physics Laboratory

(Vp141/Vp241)

Linear Fit Tutorial & Criteria

rev 1.1

Edited by: Yao Yuan


1 Uncertainty for a sample average
If we perform n independent measurements of a physical quantity X, obtaining a set of
results x1 , x2 , . . . , xn , the average value X̄ of X is defined as
n
1X
X̄ = xi , (1)
n i=1
and the standard deviation for X may be estimated by the quantity
v
u n
u 1 X
sX = t (xi − X̄)2 . (2)
n − 1 i=1

The standard deviation for X̄ is then


v
u n
sX u1 1 X
sX̄ = √ = t (xi − X̄)2 .
n n n − 1 i=1

The sample average X̄ follows a Student T Distribution with n-1 degrees of freedom
(This will be taught in probabilistic courses). Thus, the Type-A uncertainty with 95%
confidence is calculated as
sX tn−1,0.95
∆A = tn−1,0.95 · √ = √ · sX . (3)
n n

With Type-B uncertainty ∆B given, you should be able to calculate the total uncer-
p
tainty u = ∆2A + ∆2B .

The values of tn−1,0.95 and tn−1,0.95 / n are given in Table 1.

n 3 4 5 6 7 8 9 10 15 20
tn−1,0.95 4.30 3.18 2.78 2.57 2.45 2.36 2.31 2.26 2.14 2.09
tn−1,0.95

n
2.48 1.59 1.204 1.05 0.926 0.834 0.770 0.715 0.553 0.467

Table 1: The values of tn−1,0.95 and tn−1,0.95 / n.

For other values of n that are not included in the table, please refer to the table at the
end of this document for (two-sided) t-values, using two parameters n-1 and 0.95.


Note that this is a brief summary for calculation of confidence interval for sample
average. For more details, please refer to “handbook-uncertainty analysis.pdf ” page
8-9. Also, this is aim to make it clear that the confidence interval for sample average is

1
different from the confidence interval for linear regression, which will be explained in the
next section.

2 Uncertainty for a linear fit


Typically, a linear fit is performed using software such as Origin, Matlab or Microsoft
Excel. The uncertainty(,which leads to a confidence interval) could be directly obtained from
the output. Mostly, we would like to know the uncertainty of the slope.
First, we should know that the slope in a simple linear regression follows a Student T
Distribution with n-2 degrees of freedom
The values of tn−2,0.95 are given in Table 2.

n 3 4 5 6 7 8 9 10 15 20
tn−2,0.95 12.71 4.30 3.18 2.78 2.57 2.45 2.36 2.31 2.16 2.10

Table 2: The values of tn−2,0.95 .

For other values of n that are not included in the table, please refer to the table at the
end of this document for (two-sided) t-values, using two parameters n-2 and 0.95.

Let us consider a set of sample data for a linear fit, where n = 12.

ti [s] si [m] ti [s] si [m]


1.0 110 7.0 139
2.0 115 8.0 144
3.0 120 9.0 149
4.0 125 10.0 154
5.0 129 11.0 159
6.0 134 12.0 164

Table 3: Sample data for s-t linear fit.

Time ti [s] ± 0.1 [s]


Distance si [m] ± 1 [m]

Table 4: Uncertainty of the measurement (used for error bar drawing).

Then n − 2 = 12 − 2 = 10 and the t10,0.95 = 2.228 is read from the table in appendix.

2
2.1 OriginLab
First, import the data, make sure you have included all X, Y, X error and Y error,
otherwise you won’t have error bars in the plot.

Figure 1: Import data.

Then, select all the data and select Linear Fit in menu.

Figure 2: Select linear fit.

3
In this menu, tick the quantities as is shown in the figure below, including the neces-
sary Standard Error (Standard Deviation), Lower Confidence Limit (LCL), Up-
per Confidence Limit(UCL), Pearson’s r (Correlation Coefficient) and R-Square.
Some of them will be included in your report if specified.

Figure 3: Select quantity display.

4
Figure 4: Summary chart.

Click OK and you will get this table including all the information you need. Here, the
CI(Confidence Interval) Half-Width is the value of uncertainty.
You should notice that the uncertainty (0.05516) is the standard error (0.02476) times
t10,0.95 = 2.228. Round the uncertainty to 0.06, and you obtain the uncertainty for the slope.

5
2.2 Matlab
To do linear fit in Matlab, you need to acquire Curve Fitting in APP. If you don’t have
this toolbox, click “Acquire more App” on the left and download it(probably need VPN).

Figure 5: Curve fitting toolbox.

Import your data into two matrix variables.

Figure 6: Import data.

6
Select x data and y data and parameters will be shown in the “Results” window.

Figure 7: Display settings.

As we can see, “p1” is the slope we need and its 95% confidence is given. Divide the
length of confidence interval by 2, we obtain the uncertainty (4.943-4.833)/2=0.055≈0.06.
However, the standard error is not given and we can obtain it by dividing the uncertainty
by t10,0.95 .
Furthermore, error bars can be drawn on the plot if you use properly hold on and
function errorbar. The remaining tasks are left to you.

7
2.3 Excel
First, import all the data you got.

Figure 8: Import data.

The following steps show how to find the Data Analysis toolbox necessary for a linear
regression in Excel.

8
Figure 9: File -> Options.

Figure 10: Add-ins -> Go.

9
Figure 11: Analysis toolpak.

After this, the toolbox will appear in tab Data.

Figure 12: Data analysis.

Figure 13: Regression.

10
Figure 14: Regression settings.

Use this toolbox and you should get all the quantities you need.

Figure 15: Summary output.

Then, the uncertainty can be obtained by

u = t10,0.95 · “Standard Error” = 2.228 × 0.024757 = 0.5516 ≈ 0.06.

11
Figure 16: Plot.

Also, you will get a fit line by choosing Add Trendline. The remaining tasks are left to
you, including adding error bars, a summary chart and legends in the plot.

2.4 Other Software


For other software, please tell apart standard error and confidence interval(uncertainty).
If only one of them is given, calculate another using the same method given above.

12
3 Sample Plot
The linear fit plot included in your report should look like this. Of course it should
have different looks depending on which software you use, but please make sure
that the elements are included.

Figure 17: Sample Plot.

Checklist:
1. The fit line.
2. Data points.
3. Error bars in both directions.
(The ones that look like “H”. Sometimes one set of data is constant and we only have
error bars in the other direction. Must be visible when printed out!!! )
4. Proper legends and labels.
5. Summary chart
Equation
Intercept and Slope
Standard Error (of the quantity we need)
Confidence Interval Half-Width (of the quantity we need)
Pearson’s r
R-Square

13
4 Appendix

Figure 18: Table for t-values. Two-sided t0.95 values are expressed as one-sided t0.975 values,
which we choose to use.

14
The table is taken from Introduction to Probability and Statistics Principles and Appli-
cation for Engineering and Computer Sciences.

15

You might also like