Linear Fit - Tutorial (Rev 1.1)
Linear Fit - Tutorial (Rev 1.1)
(Vp141/Vp241)
rev 1.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.
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
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.
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.
Then, select all the data and select Linear Fit in menu.
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.
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).
6
Select x data and y data and parameters will be shown in the “Results” window.
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.
The following steps show how to find the Data Analysis toolbox necessary for a linear
regression in Excel.
8
Figure 9: File -> Options.
9
Figure 11: Analysis toolpak.
10
Figure 14: Regression settings.
Use this toolbox and you should get all the quantities you need.
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.
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.
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