Documente Academic
Documente Profesional
Documente Cultură
Slide 1 of 8
Lecture 11b
Application of Linear Regression to Kinetic Data
Brian G. Higgins
Department of Chemical Engineering & Materials Science
University of California, Davis
April 2014, Hanoi, Vietnam
ECM6Lecture11dVietnam_2014.nb
PMeOH
N
Kp
where Pi is the partial pressure of species i in units of Pa (Pascals) and R is the rate of
reaction in units of Kgmol Is m3 M. Further they are told that KP was fitted to the following
expression
Ln HKp L = -51.8 +
11 824
T
ECM6Lecture11dVietnam_2014.nb
Issue of Units
Before we begin our analysis we will check the units of the constants
From the denominator of the rate expression we can deduce that the units of K1 , K2 , and K3 are Pa-1 .
The units of PMeOH Kp must be Pa3 . Thus we can deduce that the units of KP must be Pa-2 . Hence the
numerical value 11824 in the rate expression KP has implied units of K -1 so that the dimensional form of
Kp is given by
ECM6Lecture11dVietnam_2014.nb
Method : Linearization
Although we can attempt a nonlinear regression to find the constants, it is prudent to try the simplest
approach first, viz, linear regression. In order to use linear regression we need to transform Eq. (1) into
a suitable form. This suggests we write Eq. (1) as
1
R13
13
PMeOH
NN
Kp
k13
JH-ERTL JP2H2 PCO 0
PZ =
H-ERTL
P2H2
13
PMeOH
PCO -
Kp
1
R13
PZ
k13
0
K1
P H2
PZ
k13
0
K2
PCO
PZ
k13
0
K3
PMeOH
k13
0
Pz
Y=
1
R13
X1 =
1
PZ
, a=
, X2 =
1
k13
0
P H2
PZ
, b=
, X3 =
K1
k13
0
PCO
PZ
, c=
, X4 =
K2
k13
0
, d=
K3
k13
0
PMeOH
Pz
so that in terms of the new variables our rate expression becomes has the following linear form:
Y = a X1 + b X2 + c X3 + d X4
We can now use linear regression on this expression to determine the parameters a, b, c, d
ECM6Lecture11dVietnam_2014.nb
Mathematica Implementation
Importing the Data
We begin first by importing the data which is in the form of an Excel spreadsheet
In[23]:=
rawData =
First@Import@"TeachingBGHTeaching1ECM6ECM6HomeworkECM6_06DesignData.xls"DD;
rawData TableForm
Out[23]//TableForm=
Run No
TempHKL
R of MeOH Hkgmolsm3L
P of H2HPaL
P of CO HPaL
4.052 10
1.53 106
1.
495.
11.5
8.509 10
2.
495.
11.
8.509 106
6
4.052 10
P of MeOH
253 000.
253 000.
1.013 106
3.
495.
8.33
8.509 10
4.
495.
7.
8.509 106
1.53 106
1.013 106
1.013 106
5.
495.
5.6
5.906 10
6.
495.
5.6
5.906 106
4.052 106
1.013 106
7.
495.
8.4
5.906 106
4.052 106
253 000.
8.
495.
9.
5.906 106
1.53 106
253 000.
6.
8.509 10
4.052 10
9.
475.
10.
475.
5.43
8.509 10
11.
475.
4.33
8.509 106
6
1.53 10
1.53 10
253 000.
4.052 106
1.013 106
1.013 106
475.
3.71
8.509 10
13.
475.
2.86
5.906 106
1.53 106
14.
475.
2.86
5.906 106
4.052 106
4.29
5.906 10
4.052 10
5.906 10
7.091 10
16.
17.
475.
475.
485.
4.67
6.8
1.53 10
1.013 106
12.
15.
1.53 10
253 000.
2.533 10
1.013 106
253 000.
253 000.
507 000.
Finally we display the modified data in a table with appropriate headings for the columns
ECM6Lecture11dVietnam_2014.nb
In[25]:=
TableFormAkineticData, TableHeadings
9None, 9"THKL", "RHKgmolHsm3 L", "PH2 HPaL", "PCO HPaL", "PMeOH HPaL"==,
TableAlignments CenterE
Out[25]//TableForm=
THKL
RHKgmolHsm3 L
PH2 HPaL
PCO HPaL
PMeOH HPaL
495.
495.
495.
495.
495.
495.
495.
495.
475.
475.
475.
475.
475.
475.
475.
475.
485.
11.5
11.
8.33
7.
5.6
5.6
8.4
9.
6.
5.43
4.33
3.71
2.86
2.86
4.29
4.67
6.8
8.509 106
8.509 106
8.509 106
8.509 106
5.906 106
5.906 106
5.906 106
5.906 106
8.509 106
8.509 106
8.509 106
8.509 106
5.906 106
5.906 106
5.906 106
5.906 106
7.091 106
4.052 106
1.53 106
4.052 106
1.53 106
1.53 106
4.052 106
4.052 106
1.53 106
4.052 106
1.53 106
4.052 106
1.53 106
1.53 106
4.052 106
4.052 106
1.53 106
2.533 106
253 000.
253 000.
1.013 106
1.013 106
1.013 106
1.013 106
253 000.
253 000.
253 000.
253 000.
1.013 106
1.013 106
1.013 106
1.013 106
253 000.
253 000.
507 000.
The data is now in the appropriate form for using in our least squares regression algorithm.
ECM6Lecture11dVietnam_2014.nb
Regression Analysis
Mathematica Formulation
We begin by defining some auxiliary functions to extract the data. The index i which is patterned match
refers to the run number in the data set.
In[26]:=
The variables and parameters for the linearized model are defined as
Y=
X1 =
1
R
13
1
PZ
, a=
, X2 =
1
k0
, b=
P H2
PZ
K1
, c=
k0
, X3 =
PCO
PZ
K2
k0
, d=
, X4 =
K3
k0
PMeOH
Pz
It is convenient to define additionally auxiliary functions for the constant Kp and our new variable PZ
In[27]:=
PMeOH @iD
Kp@iD
13
X1 @i_D :=
X3 @i_D :=
1
PZ @iD
; X2 @i_D :=
PCO @iD
PZ @iD
; X4 @i_D :=
PH2 @iD
PZ @iD
PMeOH @iD
PZ @iD
; Y@i_D :=
1
R@iD13
Let us test that all the transformed variables are working for i=2
In[30]:=
Out[30]=
Next we define a template for our linearized model of the rate expression
In[31]:=
Note that the variables X1, X2, X3, X4 in the template are pattern matched. Recall in linear regression
we will minimize the sum of squares of the error of (Ypred - Ymeas )
Our Mathematica function for the sum of squares is
M
In[32]:=
Note that the variables f and M in the argument of E2 are pattern matched.
ECM6Lecture11dVietnam_2014.nb
Results
To minimize the sum of errors we must find the values of the parameters a,b,c,d such that
E2
a
= 0,
E2
b
= 0,
E2
c
= 0,
E2
d
=0
In the following code we take the derivative of our sum of squares with respect to the parameters and
solve the linear system of equations
In[33]:=
Out[33]=
We can check on the size of the sum of errors by substituting the parameters back into the expression
for the sum of squares
In[34]:=
Out[34]=
E2 @Model1, MD . solModel1
0.000208943
Although we have not done any statistics on the parameters for this regression, the magnitude of E2
suggests we have a reasonable fit
Transforming back to the original parameters we find the following values for our kinetic expression
In[35]:=
Model1params = SolveB
:a ==
Out[35]=
1
k13
0
, b ==
K1
k13
0
, c ==
K2
k13
0
, d ==
K3
k13
0
ECM6Lecture11dVietnam_2014.nb
Summary of Results
At a minimum w should organize our data in a table to test see how good the fit is. Recall the predicted
function for the rate expression is
k0 H-66 532.9H8.314 T@iDLL JPH2 @iD2 PCO @iD In[36]:=
Rpredict@i_D :=
PMeOH @iD
N
Kp@iD
. Model1params
The index i refers to the run number. Here is a table that compares the measured rate expression with
the predicted rate expression and shows as well the relative error
In[37]:=
Out[37]//TableForm=
Run No
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Measured Rate
11.5
11.
8.33
7.
5.6
5.6
8.4
9.
6.
5.43
4.33
3.71
2.86
2.86
4.29
4.67
6.8
Predicted Rate
11.5579
10.9826
8.41561
7.15351
5.48624
5.76424
8.28768
9.20565
5.85558
5.57076
4.27292
3.64973
2.82295
2.93597
4.20206
4.67916
6.7699
Rel Error
0.00503824
0.00158377
0.0102774
0.0219294
0.020315
0.0293288
0.0133714
0.0228496
0.0240696
0.0259231
0.0131816
0.0162446
0.0129555
0.0265623
0.0204988
0.00196086
0.00442596
10
ECM6Lecture11dVietnam_2014.nb
Final Comments
Now that we have a good estimate of the parameter values, we are in a position to refine our regression
analysis by doing a nonlinear regression of the data.
In a nonlinear regression we use Newton's method to solve the nonlinear equations that arise from
minimizing the error E2 .
You saw in an earlier lecture that Newton's method will converge quadratically if the initial guess is
close to the fixed point.
Our strategy therefore is to use the linear regression (shown above) to get good initial values for the
rate constants.