Tải bản đầy đủ - 0 (trang)


Tải bản đầy đủ - 0trang

DK4712_C007.fm Page 221 Tuesday, January 31, 2006 12:04 PM

Kinetic Modeling of Multivariate Measurements with Nonlinear Regression


shown here are given in Equation 7.5, which lists the equations for each example.

Note that in examples (a) to (c), the integrated form of the equation is only given

for A. The equations for the concentration(s) of the remaining species can be calculated from the mass balance or closure principle (e.g., in the first example [B] =

[A]0 − [A], where [A]0 is the concentration of A at time zero). In example (d), the

integrated form is given for species A and B. Again, the concentration of species C

can be determined from the mass balance principle.


[ A] = [ A]0 e − kt


[ A] =

[ A]0

1 + 2[ A]0 kt


[ A] =

[ A]0 ([ B]0 − [ A]0 )

[ B]0 e([ B ]0 −[ A]0 ) kt − [ A]0


[ A] = [ A]0 e − kt ,

[ B] = [ A]0

([ A]0 ≠ [ B]0 )



(e − k1t − e −kk2t ) ([ B]0 = 0, k1 ≠ k2 )

k2 − k1

Modeling and visualization of a reaction A k

→ B requires only a few lines of

MATLAB code (see MATLAB Example 7.1), including a plot of the concentration

profiles, as seen in Figure 7.1. Of course this task can equally well be performed in


x 10−4


Concentration (M)










Time (s)



FIGURE 7.1 Concentration profiles for a reaction A 

→ B ( A, … B ) as calculated

by MATLAB Example 7.1.


© 2006 by Taylor & Francis Group, LLC

DK4712_C007.fm Page 222 Tuesday, January 31, 2006 12:04 PM


Practical Guide to Chemometrics

MATLAB Example 7.1

% A -> B


% time vector (column vector)


% initial concentration of A


% rate constant


% [A]


% [B] (Closure)


% plotting C vs t

Solutions for the integration of ODEs such as those given in Equation 7.5 are not

always readily available. For nonspecialists, it is difficult to determine whether there is

an explicit solution at all. MATLAB’s symbolic toolbox provides a very convenient means

of producing the results and also of testing for explicit solutions of ordinary differential

→ B, as seen in MATLAB Example 7.2. (Note

equations, e.g., for the reaction 2A k

that MATLAB’s symbolic toolbox demands lowercase characters for species names.)

MATLAB Example 7.2

% 2A -> B, explicit solution

d=dsolve('Da=-2*k1*a^2','Db=k1*a^2','a(0)=a_0',' b(0)=0');



--------------2 k1 t a_0 + 1

In a section 7.5, we will demonstrate how to deal with more complex mechanisms

for which the ODEs cannot be integrated analytically.


Model-based fitting of measured data can be a rather complex process, particularly if

there are many parameters to be fitted to many data points. Multivariate measurements

can produce very large data matrices, especially if spectra are acquired at many

wavelengths. Such data sets may require many parameters for a quantitative description. It is crucial to deal with such large numbers of parameters in efficient ways, and

we will describe how this can be done. Large quantities of data are no longer a problem

on modern computers, since inexpensive computer memory is easily accessible.

As mentioned previously, the task of model-based data fitting for a given matrix Y

is to determine the best rate constants defining the matrix C, as well as the best molar

absorptivities collected in the matrix A. The quality of the fit is represented by the matrix

of residuals, R = Y − C × A. Assuming white noise, i.e., normally distributed noise of

constant standard deviation, the sum of the squares, ssq, of all elements ri,j is statistically

the “best” measure to be minimized. This is generally called a least-squares fit.


ssq =



i, j

i =1

© 2006 by Taylor & Francis Group, LLC

j =1


DK4712_C007.fm Page 223 Tuesday, January 31, 2006 12:04 PM

Kinetic Modeling of Multivariate Measurements with Nonlinear Regression


(An adaptation using weighted least squares is discussed in a later section for the

analysis of data sets with nonwhite noise.) The least-squares fit is obtained by

minimizing the sum of squares, ssq, as a function of the measurement, Y, the chemical

model (rate law), and the parameters, i.e., the rate constants, k, and the molar

absorptivities, A.

ssq = f (Y, model, parameters)


It is important to stress here that for the present discussion we do not vary the

model; rather, we determine the best parameters for a given model. The determination

of the correct model is a task that is significantly more difficult. One possible

approach is to fit the complete set of possible models and select the best one defined

by statistical criteria and chemical intuition. Because there is usually no obvious

limit to the number of potential models, this task is rather daunting. As described

in Chapter 11, Multivariate Curve Resolution, model-free analyses can be a very

powerful tool to support the process of finding the correct model.

We confidently stated at the very beginning of this chapter that we would deal

with multivariate data. The high dimensionality makes graphical representation

difficult or impossible, as our minds are restricted to visualization of data in three

dimensions. For this reason, we initiate the discussion with monovariate examples,

i.e., kinetics measured at only one wavelength. As we will see, the appropriate

generalization to many wavelengths is straightforward.

In order to gain a good understanding of the different aspects of the task of

parameter fitting, we will start with a simple but illustrative example. We will use

the first-order reaction A k

→ B, as shown in MATLAB Example 7.1 and also

in Figure 7.1. The kinetics is followed at a single wavelength, as shown in Figure 7.2.

The measurement is rather noisy. The magnitude of noise is not relevant, but it

is easier to graphically discern the difference between original and fitted data.











Time (s)



FIGURE 7.2 First-order (A 

→ B) kinetic single-wavelength experiment (…) and the

result of a least-squares fit ().


© 2006 by Taylor & Francis Group, LLC

DK4712_C007.fm Page 224 Tuesday, January 31, 2006 12:04 PM


Practical Guide to Chemometrics

In Appendix 7.1 at the end of this chapter, a MATLAB function (data_ab) is given

that generates this absorbance data set.

Because this is a single-wavelength experiment, the matrices A, Y, and R collapse

into column vectors a, y, and r, and Equation 7.2 is reduced to Equation 7.8.


× nc

nt = C a + nt




For this example there are three parameters only, the rate constant k, which defines

the matrix C of the concentration profiles, and the molar absorptivities eA,l and eB,l

for the components A and B, which form the two elements of the vector a.

First, we assume that the molar absorptivities of A and B at the appropriate wavelength l have been determined independently and are known (eA,l = 100 M−1cm−1,

eB,l = 400 M−1cm−1); then, the only parameter to be optimized is k. In accordance

with Equation 7.6 and Equation 7.8, for any value of k we can calculate a matrix C

— and subsequently the quality of the fit via the sum of squares, ssq — by multiplying

the matrix C with the known vector a, subtracting the result from y, and adding up

the squared elements of the vector of differences (residuals), r. Figure 7.3 shows a

plot of the logarithm of ssq vs. k. The optimal value for the rate constant that

minimizes ssq is obviously around k = 0.05 s−1.

In a second, more realistic thought experiment, we assume to know the molar

absorptivity eA,l of species A only, and thus have to fit eB,l and k. The equivalent ssq

analysis as above leads to a surface in a three-dimensional space when we plot ssq

vs. k and eB,l. This is illustrated in Figure 7.4. Again, the task is to find the minimum

of the function defining ssq, or in other words, the bottom of the valley (at k ≅ 0.05 s−1


Log (ssq)









k (s−1)

FIGURE 7.3 Logarithm of the square sum ssq of the residual vector r as a function of the

rate constant k.

© 2006 by Taylor & Francis Group, LLC

DK4712_C007.fm Page 225 Tuesday, January 31, 2006 12:04 PM

Kinetic Modeling of Multivariate Measurements with Nonlinear Regression



Log (ssq)














−1 )

k (s



FIGURE 7.4 Square sum ssq of the residuals r as a function of two parameters k and eB,l.

and eB,l ≅ 400 M−1cm−1). In the first example, there was only one parameter (k) to

be optimized; in the second, there are two (k and eA,l).

Even more realistically, all three parameters k, eA,l, and eB,l are unknown (e.g.,

a solution of pure A cannot be made, as it immediately starts reacting to form B).

It is impossible to represent graphically the relationship between ssq and the three

parameters; it is a hypersurface in a four-dimensional space and beyond our imagination. Nevertheless, as we will see soon, there is a minimum for one particular set

of parameters.

It is probably clear by now that highly multivariate measurements need special

attention, as there are many parameters that need to be fitted, i.e., the rate constants

and all molar absorptivities at all wavelengths. We will come back to this apparently

daunting task.

There are many different methods for the task of fitting any number of parameters

to a given measurement [14–16]. We can put them into two groups: (a) the direct

methods, where the sum of squares is optimized directly, e.g., finding the minimum,

similar to the example in Figure 7.4, and (b) the Newton-Gauss methods, where the

residuals in r or R themselves are used to guide the iterative process toward the



Graphs of the kind shown in Figure 7.3 and Figure 7.4 are simple to produce and

the subsequent “manual” location of the optimum is straightforward. However, it

requires a great deal of computation time and, more importantly, the direct input of

an operator. Additionally, such a method is restricted to only one or two parameters.

Very useful and, thus, heavily used is the simplex algorithm, which is conceptually a very simple method. It is reasonably fast for a modest number of parameters;

further, it is very robust and reliable. However, for high-dimensional tasks, i.e., with

many parameters, the simplex algorithm becomes extremely slow.

© 2006 by Taylor & Francis Group, LLC

DK4712_C007.fm Page 226 Tuesday, January 31, 2006 12:04 PM


Practical Guide to Chemometrics

A simplex is a multidimensional geometrical object with n + 1 vertices in an

n-dimensional space. In two dimensions (two parameters), the simplex is a triangle, in three dimensions (three parameters) it becomes a tetrahedron, etc. At

first, the functional values (ssq) at all corners of the simplex have to be determined. Assuming we are searching for the minimum of a function, the highest

value of the corners has to be determined. Next, this worst one is discarded and

a new simplex is constructed by reflecting the old simplex at the face opposite

the worst corner. Importantly, only one new value has to be determined for the

new simplex. The new simplex is treated in the same way: the worst vertex is

determined and the simplex reflected until there is no more significant change in

the functional value.

The process is represented in Figure 7.5. In the initial simplex, the worst value

is 14, and the simplex has to be reflected at the opposite face (8,9,11), marked in

gray. A new functional value of 7 is determined in the new simplex. The next move

would be the reflection at the face (8,9,7), reflecting the corner with value 11.

Advanced simplex algorithms include constant adaptation of the size of the simplex

[17]. Overly large simplices will not follow the fine structure of the surface and will

only result in approximate minima; simplices that are too small will move very

slowly. In the example here, we are searching for the minimum, but the process is

obviously easily adapted for maximization.

The simplex algorithm works well for a reasonably low number of parameters.

Naturally, it is not possible to give a precise and useful maximal number; 10 could

be a reasonable estimate. Multivariate data with hundreds of unknown molar

absorptivities cannot be fitted without further substantial improvement of the


In MATLAB Example 7.3a and 7.3b we give the code for a simplex optimization

of the first-order kinetic example discussed above. Refer to the MATLAB manuals

for details on the simplex function fminsearch. Note that all three parameters k, eA,l,

and eB,l are fitted. The minimal ssq is reached at k = 0.048 s−1, eA,l = 106.9 M−1cm−1, and

eB,l = 400.6 M−1cm−1.

MATLAB Example 7.3b employs the function that calculates ssq (and also

C). It is repeatedly used by the simplex routine called in MATLAB Example 7.3a.

In Figure 7.2 we have already seen a plot of the experimental data together with

their fit.






Reflection at the

grey face




FIGURE 7.5 Principle of the simplex minimization with three parameters.

© 2006 by Taylor & Francis Group, LLC

DK4712_C007.fm Page 227 Tuesday, January 31, 2006 12:04 PM

Kinetic Modeling of Multivariate Measurements with Nonlinear Regression


MATLAB Example 7.3a

% simplex fitting of k, eps_A and eps_B to the kinetic model A -> B


% get absorbance data


% initial concentration of A


% start parameter vector

% [k0;eps_A0;eps_B0]



% simplex call

% calculate ssq and C with final parameters


% determine y_calc from C, eps_A and eps_B


% plot y and y_calc vs t

MATLAB Example 7.3b

function [ssq,C]=rcalc_ab1(par,A_0,t,y)


% concentrations of species A


% concentrations of B


% residuals


% sum of squares


Fitting tasks of a modest complexity, like the one just discussed, can straightforwardly be performed in Excel using the Solver tool provided as an Add-In method.

The Solver tool does not seem to be very well known, even in the scientific

community, and therefore we will briefly discuss its application based on the

example above. As with MATLAB, we assume familiarity with the basics of


Figure 7.6 displays the essential parts of the spreadsheet. The columns A and

B (from row 10 downward) contain the given measurements, the vectors t and y,

respectively. Columns C and D contain the concentration profiles [A] and [B],

respectively. The equations used to calculate these values in the Excel language

are indicated. The rate constant is defined in cell B2, and the molar absorptivities

in the cells B3:B4. Next, a vector ycalc is calculated in column E. Similarly, the

residuals and their squares are given in the next two columns. Finally, the sum

over all these squares, ssq, is given in cell B6. The task is to modify the parameters,

the contents of the cells B2:B4, until ssq is minimal. It is a good exercise to try

to do this manually. Excel provides the Solver for this task. The operator has to

(a) define the Target Cell, in this case, cell B6 containing ssq; (b) make sure the

Minimize button is chosen; and (c) define the Changing Cells, in this case, the

cells containing the variable parameters, B2:B4. Click Solve and in no time the

result is found. As with any iterative fitting algorithm, it is important that the initial

guesses for the parameters be reasonable, otherwise the minimum might not be

found. These initial guesses are entered into the cells B2:B4, and they are subsequently refined by the Solver to yield the result shown in Figure 7.6. For further

information on Excel’s Solver, we refer the reader to some relevant publications

on this topic [18–21].

© 2006 by Taylor & Francis Group, LLC

DK4712_C007.fm Page 228 Tuesday, January 31, 2006 12:04 PM


Practical Guide to Chemometrics







FIGURE 7.6 Using Excel’s Solver for nonlinear fitting of a first-order reaction A 

→ B.


7.4.3 LINEAR



As stated in the introduction (Section 7.1), this chapter is about the analysis of

multivariate data in kinetics, i.e., measurements at many wavelengths. Compared

with univariate data this has two important consequences: (a) there is much more

data to be analyzed and (b) there are many more parameters to be fitted.

Consider a reaction scheme with nk reactions (rate constants), involving nc

absorbing components. Measurements are done using a diode-array spectrophotometer

where nt spectra are taken at nl wavelengths. Thus, we are dealing with nt × nl

individual absorption measurements. The number of parameters to be fitted is

nk + nc × nl (the number of rate constants plus the number of molar absorptivities).

Let us look at an example for the reaction scheme A→B→C, with 100 spectra

measured at 1024 wavelengths. The number of data points is 1.024 × 105 and, more

importantly, the number of parameters is 3074 (2 + 3 × 1024). There is no doubt

that “something” needs to be done to reduce this large number, as no fitting method

can efficiently deal with that many parameters.

There are two fundamentally different kinds of parameters: a small number of

rate constants, which are nonlinear parameters, and the large number of molar

absorptivities, which are linear parameters. Fortunately, we can exploit this situation

of having to deal with two different sets of parameters.

© 2006 by Taylor & Francis Group, LLC

DK4712_C007.fm Page 229 Tuesday, January 31, 2006 12:04 PM

Kinetic Modeling of Multivariate Measurements with Nonlinear Regression


The rate constants (together with the model and initial concentrations) define

the matrix C of concentration profiles. Earlier, we have shown how C can be

computed for simple reactions schemes. For any particular matrix C we can

calculate the best set of molar absorptivities A. Note that, during the fitting, this

will not be the correct, final version of A, as it is only based on an intermediate

matrix C, which itself is based on an intermediate set of rate constants (k). Note

also that the calculation of A is a linear least-squares estimate; its calculation is

explicit, i.e., noniterative.

A = C+ Y or

A = (CtC)−1 CtY or

A = C\Y (MATLAB notation)


C+ is the so-called pseudoinverse of C. It can be computed as C+ = (CtC)−1 Ct.

However, MATLAB provides a numerically superior method for the calculation of

A by means of the back-slash operator (\). Refer to the MATLAB manuals for details.

The important point is that we are now in a position to write the residual matrix R,

and thus ssq, as a function of the rate constants k only:

R = Y − CA = Y − CC+Y = f (Y, model, k)


The absolutely essential difference between Equation 7.10 and Equation 7.7

is that now there is only a very small number of parameters to be fitted iteratively.

To go back to the example above, we have reduced the number of parameters

from 3074 to 2 (nk). This number is well within the limits of the simplex

algorithm. For the example of the consecutive reaction mechanism mentioned

above, we give the function that calculates ssq in MATLAB Example 7.4b. It is

repeatedly used by the simplex routine fminsearch called in MATLAB Example 7.4a.

A minimum in ssq is found for k1 = 2.998 × 10−3 s−1 and k2 = 1.501 × 10−3 s−1.

As before, a MATLAB function (data_abc) that generates the absorbance data

used for fitting is given in the Appendix at the end of this chapter. It is interesting

to note that the calculated best rate constants are very close to the “true” ones

used to generate the data. Generally, multivariate data are much better and more

robust at defining parameters compared with univariate (one wavelength) measurements.

MATLAB Example 7.4a

% simplex fitting to the kinetic model A -> B -> C


% get absorbance data


% initial concentration of A

k0=[0.005; 0.001];

% start parameter vector


© 2006 by Taylor & Francis Group, LLC

% simplex call

DK4712_C007.fm Page 230 Tuesday, January 31, 2006 12:04 PM


Practical Guide to Chemometrics

MATLAB Example 7.4b

function ssq=rcalc_abc1(k,A_0,t,Y)


% concentrations of species A


% conc. of B


% concentrations of C


% elimination of linear parameters


% residuals


% sum of squares

To analyze other mechanisms, all we need to do is to replace the few lines that

calculate the matrix C. The computation of A, R, and ssq are independent of the

chemical model, and generalized software can be written for the fitting task.

In two later sections, we will deal with numerical integration, which is required

to solve the differential equations for complex mechanisms. Before that, we will

describe nonlinear fitting algorithms that are significantly more powerful and faster

than the direct-search simplex algorithm used by the MATLAB function fminsearch.

Of course, the principle of separating linear (A) and nonlinear parameters (k) will

still be applied.


In contrast to methods where the sum of squares, ssq, is minimized directly, the

NGL/M type of algorithm requires the complete vector or matrix of residuals to

drive the iterative refinement toward the minimum. As before, we start from an initial

guess for the rate constants, k0. Now, the parameter vector is continuously improved

by the addition of the appropriate (“best”) parameter shift vector ∆k. The shift vector

is calculated in a more sophisticated way that is based on the derivatives of the

residuals with respect to the parameters.

We could define the matrix of residuals, R, as a function of the measurements,

Y, and the parameters, k and A. However, as previously shown, it is highly recommended if not mandatory to define R as a function of the nonlinear parameters only.

The linear parameters, A, are dealt with separately, as shown in Equation 7.9 and

Equation 7.10.

At each cycle of the iterative process a new parameter shift vector, δ k, is

calculated. To derive the formulae for the iterative refinement of k, we develop R

as a function of k (starting from k = k0) into a Taylor series expansion. For sufficiently

small δ k, the residuals, R(k + δ k), can be approximated by a Taylor series expansion.

R(k + δ k) = R(k) +

1 ∂R(k)

1 ∂2 R(k)


×δ k+ ×

× δ k2 + …






We neglect all but the first two terms in the expansion. This leaves us with an

approximation that is not very accurate; however, it is easy to deal with, as it is a

linear equation. Algorithms that include additional higher terms in the Taylor expansion often result in fewer iterations but require longer computation times due to the

© 2006 by Taylor & Francis Group, LLC

DK4712_C007.fm Page 231 Tuesday, January 31, 2006 12:04 PM

Kinetic Modeling of Multivariate Measurements with Nonlinear Regression


increased complexity. Dropping the higher-order terms from the Taylor series expansion gives the following equation.

R(k + δ k) = R(k) +





The matrix of partial derivatives, ∂R(k)/∂k, is called the Jacobian, J. We can

rearrange this equation in the following way:

R(k) = −J × δ k + R(k + δ k)


The matrix of residuals, R(k), is known, and the Jacobian, J, is determined as

shown later in this section. The task is to calculate the δ k that minimizes the new

residuals, R(k + δ k). Note that the structure of Equation 7.13 is identical to that of

Equation 7.2, and the minimization problem can be solved explicitly by simple linear

regression, equivalent to the calculation of the molar absorptivity spectra A (A = C+ × Y)

as outlined in Equation 7.9.

δ k = −J+ × R(k)


The Taylor series expansion is an approximation, and therefore the shift vector

δ k is an approximation as well. However, the new parameter vector k + δ k will

generally be better than the preceding k. Thus, an iterative process should always

move toward the optimal rate constants. As the iterative fitting procedure progresses,

the shifts, δ k, and the residual sum of squares, ssq, usually decrease continuously.

The relative change in ssq is often used as a convergence criterion. For example,

the iterative procedure can be terminated when the relative change in ssq falls below

a preset value m, typically m = 10−4.

 ssq − ssq 

abs  old


 ssqold 


At this stage, we need to discuss the actual task of calculating the Jacobian matrix

J. It is always possible to approximate J numerically by the method of finite differences.

In the limit as ∆ki approaches zero, the derivative of R with respect to ki is given by

Equation 7.16. For sufficiently small ∆ki, the approximation can be very good.

∂R R(k + ∆ ki ) − R(k )




Here, (k + ∆ki) represents the original parameter vector k to whose ith element, ∆k1,

is added. A separate calculation must be performed for each element of k. In other

words, the derivatives with respect to the elements in k must be calculated one at a

time. It is probably most instructive to study the MATLAB code in MATLAB Box

7.5b, where this procedure is defined precisely.

© 2006 by Taylor & Francis Group, LLC

Tài liệu bạn tìm kiếm đã sẵn sàng tải về


Tải bản đầy đủ ngay(0 tr)