Major topics covered in this chapter
Uncertainty 99 to each, and then combines these components using the rules summarised in
5.14 Curve fitting
Curve fitting 145 Once a decision has been taken that a set of calibration points cannot be satisfacto-rily fitted by a straight line, the analyst can play one further card before using the more complex curvilinear regression calculations. It may be possible to transform the data so that a non-linear relationship is changed into a linear one. Such transforma-tions are regularly applied to the results of certain analytical methods. For example, modern software packages for the interpretation of immunoassay data frequently offer a choice of transformations: commonly used methods involve plotting log y and/or log x instead of y and x, or the use of logit functions (logit x ln [x/(l x)]).
Such transformations may also affect the nature of the errors at different points on the calibration plot. Suppose, for example, that in a set of data of the form y pxq, the sizes of the random errors in y are independent of x. Any transformation of the data into linear form by taking logarithms will obviously produce data in which the errors in log y are not independent of log x. In this case, and in any other instance where the expected form of the equation is known from theoretical considerations or from longstanding experience, it is possible to apply weighted regression equa-tions (Section 5.10) to the transformed data. It may be shown that, if data of the general form y f(x) are transformed into the linear equation Y BX A, the weighting factor, w, used in Eqs (5.10.1)–(5.10.4) is obtained from the relationship:
(5.13.1)
Unfortunately, there are not many cases in analytical chemistry where the exact mathematical form of a non-linear regression equation is known with certainty (see below), so this approach may not be very valuable.
In contrast to the situation described in the previous paragraph, experimental data can sometimes be transformed so that they can be treated by unweighted methods.
Data of the form y bx with y-direction errors strongly dependent on x are some-times subjected to a log–log transformation: the errors in log y then vary less seriously with log x, so the transformed data can reasonably be studied by unweighted regres-sion equations.
146 5: Calibration methods in instrumental analysis: regression and correlation
analyst has little a priori guidance on which of the many types of equation that gen-erate curved plots should be used to fit the calibration data in a particular case. In practice, much the most common strategy is to fit a curve which is a polynomial in x, i.e. y a bx cx2 dx3 . . . . The mathematical problems to be solved are then (a) how many terms should be included in the polynomial and (b) what values must be assigned to the coefficients a, b, etc.? Computer software packages that tackle these problems are normally iterative: they fit first a straight line, then a qua-dratic curve, then a cubic curve, and so on, to the data, and present to the user the information needed to decide which of these equations is the most suitable. In prac-tice quadratic or cubic equations are often entirely adequate to provide a good fit to the data: polynomials with many terms are almost certainly physically meaningless and do not significantly improve the analytical results. In any case, if the graph has n calibration points, the largest polynomial permissible is that of order (n 1).
To decide whether (for example) a quadratic or a cubic curve is the best fit to a cali-bration data set we can use the ANOVA methods introduced in Section 5.12. ANOVA programs generate values for R2, the coefficient of determination. Equation (5.12.2) shows that, as the least-squares fit of a curve (or straight line) to the data points im-proves, the value of R2will get closer to 1 (or 100%). It would thus seem that we have only to calculate R2values for the straight-line, quadratic, cubic, etc. equations, and end our search when R2no longer increases. Unfortunately it turns out that the addi-tion of another term to the polynomial always increases R2, even if only by a small amount. ANOVA programs thus provide R2 (‘adjusted R2) values (Eq. (5.12.3)), which utilise mean squares (MS) rather than sums of squares. The use of 2takes into account that the number of residual degrees of freedom in the polynomial regression (given by (n k 1) where k is the number of terms in the regression equation containing a function of x) changes as the order of the polynomial changes.
As the following example shows, R2is always smaller than R2.
R¿
Example 5.14.1
In an instrumental analysis the following data were obtained (arbitrary units).
Concentration 0 1 2 3 4 5 6 7 8 9 10
Signal 0.2 3.6 7.5 11.5 15.0 17.0 20.4 22.7 25.9 27.6 30.2 Fit a suitable polynomial to these results, and use it to estimate the concentrations corresponding to signal of 5, 16 and 27 units.
Even a casual examination of the data suggests that the calibration plot should be a curve, but it is instructive nonetheless to calculate the least-squares straight line through the points using the method described in Section 5.4.
This line turns out to have the equation y 2.991x 1.555. The ANOVA table in this case has the following form:
Source of variation Sum of squares d.f. Mean square
Regression 984.009 1 984.009
Residual 9.500 9 1.056
Total 993.509 10 99.351
Curve fitting 147
Source of variation Sum of squares d.f. Mean square
Regression 992.233 2 494.116
Residual 1.276 8 0.160
Total 993.509 10 99.351
As already noted the number of degrees of freedom (d.f.) for the variation due to regression is equal to the number of terms (k) in the regression equation con-taining x, x2, etc. For a straight line, k is 1. There is only one constraint in the calculation (viz. that the sum of the residuals is zero, see above), so the total number of degrees of freedom is n 1. Thus the number of degrees of freedom assigned to the residuals is (n k 1) (n 2) in this case. From the ANOVA table R2 is given by 984.009/993.509 0.99044. i.e. 99.044%. An equation which explains over 99% of the relationship between x and y seems quite satis-factory but, as with the correlation coefficient, r, we must use great caution in interpreting absolute values of R2: we shall see that a quadratic curve provides a much better fit for the data. We can also calculate the R2value from equation (5.12.3): it is given by (1 [1.056/99.351]) 0.98937, i.e. 98.937%.
As always an examination of the residuals provides valuable information on the success of a calibration equation. In this case the residuals are as follows:
x yi y -residual
0 0.2 1.0 -1.4
1 3.6 4.5 -0.9
2 7.5 7.5 0
3 11.5 10.5 1.0
4 15.0 13.5 1.5
5 17.0 16.5 0.5
6 20.4 19.5 0.9
7 22.7 22.5 0.2
8 25.9 25.5 0.4
9 27.6 28.5 -0.9
10 30.2 31.5 -1.3
yNi
In this table, the numbers in the two right-hand columns have been rounded to one decimal place for simplicity. The trend in the signs and magnitudes of the residuals, which are negative at low x-values, rise to a positive maximum, and then return to negative values, is a sure sign that a straight line is not a suitable fit for the data.
When the data are fitted by a curve of quadratic form the equation turns out to be y 0.086 3.970x 0.098x2, and the ANOVA table takes the form:
The numbers of degrees of freedom for the regression and residual sources of variation have now changed in accordance with the rules described above, but the total variation is naturally the same as in the first ANOVA table. Here R2is 992.233/993.509 0.99872, i.e. 99.872%. This figure is noticeably higher than the value of 99.044% obtained from the linear plot, and the R2value is also higher at [1 (0.160/99.3511)] 0.99839, i.e. 99.839%. When the y-residuals are
148 5: Calibration methods in instrumental analysis: regression and correlation
Linear Quadratic Cubic
y 5 1.15 1.28 1.27
y 16 4.83 4.51 4.50
y 27 8.51 8.61 8.62
calculated, their signs (in increasing order of x-values) are - - - - .
There is no obvious trend here, so on all grounds we must prefer the quadratic over the linear fit.
Lastly we repeat the calculation for a cubit fit. Here, the best–fit equation is y -0.040 4.170x 0.150x2 0.0035x3. The cubic coefficient is very small, so it is questionable whether this equation is a significantly better fit than the quadratic one. The R2value is, inevitably, slightly higher than that for the qua-dratic curve (99.879% compared with 99.872%), but the value of R2is slightly lower than the quadratic value at 99.827%. The order of the signs of the resid-uals is the same as in the quadratic fit. As there is no value in including unnec-essary terms in the polynomial equation, we can be confident that a quadratic fit is satisfactory in this case.
When the above equations are used to estimate the concentrations corre-sponding to instrument signals of 5, 16 and 27 units, the results (x-values in arbitrary units) are:
As expected, the differences between the concentrations calculated from the quadratic and cubic equations are insignificant, so the quadratic equation is used for simplicity.
Since non-linear calibration graphs often result from the simultaneous occurrence of a number of physicochemical and/or mathematical phenomena it is sensible to assume that no single mathematical function could describe the calibration curve satisfactorily. It thus seems logical to try to fit the points to a curve that consists of sev-eral linked sections whose mathematical forms may be different. This is the approach used in the application of spline functions. Cubic splines are most commonly used in practice, i.e. the final curve is made up of a series of linked sections of cubic form. These sections must clearly form a continuous curve at their junctions (‘knots’), so the first two derivatives (dy/dx and d2y/dx2) of each curve at any knot must be identical. Several methods have been used for estimating both the number of knots and the equations of the curves joining them: these techniques are too advanced to be considered in detail here, but many commercially available statistics software packages now provide such facilities. Spline functions have been applied successfully to a variety of analytical methods, including gas–liquid chromatography, competitive binding immunoassays and similar receptor-based methods, and atomic-absorption spectrometry.
It is legitimate to ask whether we could use the spline idea in its simplest form, and just plot the curve (provided the curvature is not too great) as a series of straight lines joining the successive calibration points. The method is obviously non-rigorous, and would not provide any information on the precision of the interpolated x-values.
However, its value as a simple initial data analysis (IDA) method (see Chapter 6) is in-dicated by applying it to the data in the above example. For y-values of 5, 16 and 27
Outliers in regression 149 this method of linear interpolation between successive points gives x-values of 1.36, 4.50 and 8.65 units respectively. Comparison with the above table shows that these results, especially the last two, would be quite acceptable for many purposes.