An MS Excel Tool for Parameter Estimation by Multivariate Nonlinear Regression in Environmental Engi
* Author to whom correspondence should be addressed.
Sigma Journal of Engineering and Natural Sciences 2017, Vol. 35, Issue 2, pp. 265-273; doi.org/10.62051/ytu.sigma-journal-of-engineering-and-natural-sciences-an-ms-excel-tool-for-parameter-estimation-by-multivariate-nonlinear-regression-i
Abstract
Keywords: Environmental modeling; optimization; multivariate nonlinear regression; MS Excel.
1. Introduction
Although most formulations in environmental processes can be linearized for handling optimization work easily, sometimes parameter estimation becomes difficult due to nonlinear nature of the environmental process of interest. In such cases, one of the numerical methods that can be used to optimize the parameters required to express the process is the Gauss-Newton algorithm. This algorithm is based on principles similar to the least squares method used in linear regression applications. More precisely, the goal of this method is to minimize the sum of the squares of the differences between the calculated and measured values of the dependent variable. There are many software packages developed to perform nonlinear regression analysis that explain the nonlinear relationship between variable parameters of many natural phenomena. Softwares such as MATLAB and STATA are used quite frequently for academic purposes among these [1-2]. However, these softwares require high CPU performance. In this regard, Visual Basic for Applications (VBA) draws attention with its simple handling and easy accessibility [3-6]. Visual Basic for Applications (VBA) is an event-driven programming language and is a derivative of Microsoft Visual Basic 6 (VB6). VBA is embedded in Microsoft Office software like Excel and is compiled to packed code (P-code). The P-code is then stored as a separate stream in an Excel file, independent of the spreadsheet stream. This property of VBA simplifies *
Corresponding Author/Sorumlu Yazar: e-mail/e-ileti: seldemir@yildiz.edu.tr, tel: (212) 383 53 72 265
S. Demir, A. Karadeniz, H. Civelek Yörüklü, N. Manav Demir / Sigma J Eng & Nat Sci 35 (2), 265-273, 2017
the problem of compiling the program into an executable file and of preparing a distribution package, if necessary, usually associated with stand-alone computer programming platforms, like VB6. Simple use and easy accessibility make VBA a useful tool in the field of education. Especially in engineering education, VBA is an effective platform in the teaching of numerical methods [7-8]. Due mostly to the licensing fees and other drawbacks of several software packages such as the fact that the code and algorithms are unavailable to the user, professors who teach numerical methods in engineering fields often discourage the use of commercial software packages. Besides, professors usually wish focusing on the numerical methods and algorithms when teaching the regression techniques and other engineering calculations. Thus, open-source software packages are encouraged. Of these, MS Excel and VBA offers a perfect solution. Considering the fact that almost all of engineering students own or have the access to a personal computer, and that a spreadsheet software (usually MS Excel) is already installed on these computers at least with a student license, one concludes that MS Excel can be used efficiently for teaching in engineering fields. Therefore, a great number of papers have been dedicated on the usability of MS Excel and VBA in engineering education as well as in reasearch [9-19]. The pupose of this study is to implement a flexible MS Excel tool incorporating VBA that uses a multivariate nonlinear regression algorithm for parameter estimation in any linear/nonlinear optimization work encountered in environmental studies. The implemented program was tested using experimental data from previous works including cyclone pressure drop, polarization curves for microbial fuel cells, and rate of oxygen uptake of microorganisms in wastewater treatment modeling.
2. Materials And Methods
A flexible MS Excel tool using multivariate nonlinear regression for parameter estimation in optimization work for environmental studies was implemented in Visual Basic for Applications (VBA) v7.0 and tested with a number of experimental data.
2.1. Implementation of the Tool
Gauss-Newton method was employed in the implemented code using the flowchart in Fig. 1. Assuming any multivariate function f(x1, x2, ... xm) of m independent variables which is defined by an array of constants as [a1, a2, ...ak]T, a first-order Taylor expansion of the function is given by the sum of all partial derivatives with respect to each constant as follows: f x1 , x2 ,...xm j 1 f x1 , x2 ,...xm j
The objective of the tool is to find a set of constants [a1, a2, ...ak]T iteratively that produces the exact value of f x1 , x 2 ,...x m j 1 starting from the point , ,… , through which the error yi – f(x1i, x2i, ...xmi) for each data point i = 1, 2, ...n is minimized. For a given set of n data points that consists of m independent variables and one dependent variable connected to independent variables by a pre-defined array of k constants, the mean square error is expressed as follows: MSE
Starting with an arbitrary set of constants, this can be accomplished iteratively by updating each constant’s value by an update factor that can be expressed as follows: (3) 266
An MS Excel Tool for Parameter Estimation by … / Sigma J Eng & Nat Sci 35 (2), 265-273, 2017
Read regression equation (dependent and independent variables) Report the values of regression constants in the final iteration step Start with initial estimates of regression constants (Random or user specified)
Build the T and V matrices for regression (Details are in the text)
Calculate updated constants (First calculate updates and then calculate corrected constants)
Convergence test: For each constant, Change in successive iterations is below acceptable level
Calculate coefficient of determination and mean square error
Figure 1. Flowch art of the implemented algorithm where U is a kx1 column vector composed of update factors for constants as [Δa1, Δa2, ...Δak]T, J is the nxm Jacobian matrix composed of partial derivatives of the multivariate function f in an iteration step, E is the nx1 column vector composed of the error value yi – f(x1i, x2i, ...xmi) for each data point i = 1, 2, ...n. The new set of constants can be calculated by updating the old set of constants as (anew)i = ai – ηui1 for each constant i = 1, 2, ...k, with η being user-defined constant for learning rate which is a constant used for relaxing the solution algorithm. The new set of constants can be used to calculate a still new set of them iteratively until mean square error is minimized, or alternatively until each of the percent changes in constants in two successive iterations is equal to or less than a predefined limit. The implemented tool requires maximum number of iterations, predefined limit of change in constants (percent maximum error), percent step size, learning rate, and numbers of independent variables and regression constants. The user is expected to write the regression formula of his choice in a cell as a string. The implemented code recognizes the formula and converts it into a mathematical equation for nonlinear regression. The partial derivatives are calculated numerically as centered finite differences, which requires an input of percent step size for derivation. The tool also allows the input for the number of independent variables through the user interface. Finally, the tool starts iterating by a random or a user-defined set of initial values for constants. An MS Excel view of the tool is shown in Fig. 2.
S. Demir, A. Karadeniz, H. Civelek Yörüklü, N. Manav Demir / Sigma J Eng & Nat Sci 35 (2), 265-273, 2017
2.2. Test Problem: Cyclone Pressure Drop
Pressure drop in cyclone separators can be estimated by inlet velocity heads as follows: Δ
where ΔP is pressure drop in cyclone (N/m2), ρ is the density of air (kg/m3), V is the inlet velocity to the cyclone (m/s), and NH is the number of inlet velocity heads. A great number of models were developed for predicting the number of inlet velocity heads depending on the cyclone geometry. A summary of these models are given in Demir [20], in which a new, practical model was also presented based on experimental data as follows: (4.b) where k1, k2, k3, and k4 are regression constants, a is the inlet height, b is the inlet width, De is the diameter of vortex finder, hb is the cylindrical height, hc is the conical height, S is the length of vortex finder, and D is the body diameter of the cyclone. Experimental data from Demir [20] and Demir et al. [21, 22] was used for testing the MS Excel tool for obtaining a set of regression constants (k1, k2, k3, and k4) that fits the experimental data best.
2.3. Test Problem: Aeration
Volumetric mass transfer coefficient (kLa) is of great importance to environmental engineers in designing aeration systems for various water and wastewater treatment plants employing either physical, chemical or biological treatment processes [23]. Therefore, accurate estimation of volumetric mass transfer coefficient from experimental data is vital in the design of cost-effective and efficient aeration systems. The aeration process in a completely mixed reactor is explained by a mass balance equation as follows: (5.a) where C is the dissolved oxygen (DO) concentration in liquid phase at time t, and CS is the saturation concentration of oxygen. Using the boundary conditions (t, C) = (0, C0) and (t, C) = (t, C(t)), this equation can be integrated into a nonlinear formulation for dissolved oxygen concentration in the following form: 1
where C0 is the initial DO concentration in liquid phase. Experimental determination of volumetric mass transfer coefficient involves measuring DO in liquid phase at various times t, and
An MS Excel Tool for Parameter Estimation by … / Sigma J Eng & Nat Sci 35 (2), 265-273, 2017
running a nonlinear regression algorithm to estimate experimental kLa value. Experimental data was collected using a lab-scale aeration equipment and the implemented MS Excel tool was used to estimate kLa to test the tool’s performance.
2.4. Test Problem: Anaerobic Digestion
As a result of anaerobic digestion techniques for producing energy, in the form of biogas, from organic wastes and wastewater treatment plant sludge becoming more and more widespread in recent years [24], an increased need for new mathematical models has emerged rapidly to establish methods to assess effectiveness of anaerobic process and to compare results from various research papers using kinetic constants [25]. A number of models were used for explaining the S-shaped curve of biogas production (as methane) depending on several kinetic parameters [25, 26]. These models include the modified Gompertz equation, the logistic function, and the transference function, all of which considers cumulative bio-methane production as a nonlinear function of several kinetic parameters and time. In order to test the performance of the implemented MS Excel Tool, a bio-methane potential (BMP) test was conducted using a sample of macroalgae as substrate, and the experimental data was used in MS Excel tool to estimate kinetic parameters of bio-methane potential for transference function which is given as: 1
where Vg is the cumulative biogas produced at the end of time t, Vmax is the biogas potential, R is the rate of biogas production (1/time), and L is a model parameter (time) representing the lag phase of the process.
3. Results
An MS Excel tool was implemented in Visual Basic for Applications for estimating parameters in nonlinear equations commonly encountered in undergraduate/graduate environmental studies. The tool employs Gauss-Newton algorithm and is able to estimate parameters in multivariate nonlinear functions. The most distinguishing property of the tool is that it allows the user to define a linear/nonlinear function on MS Excel sheet as a string (text) variable, recognizes the given function and converts it into a mathematical expression for use in parameter estimation. A number of sample problems most commonly encountered in environmental engineer’s daily work was provided and the tool was tested with experimental data on these problems.
3.1. Cyclone Pressure Drop
The experimental data for cyclone problem was obtained from Demir [20] in which a new model was proposed based on pressure drop measurements on 162 cyclones at 6 different inlet velocities (972 data points). The data set was composed of five independent variables and four regression constants. Definition of the regression equation and results are shown in Table 1. The formulation in Eqn. 4.a was typed as the regression equation and global settings including maximum number of iterations, maximum error, precent step size, and learning rate were defined as given in Table 1. The tool estimated the parameters in 996 iterations (less than 10 seconds) starting from random initial values between 0 and 1. The estimated values of parameters were almost identical to those previously published in Demir [20], indicating that the implemented tool proves a valuable tool in cyclone pressure drop calculation.
S. Demir, A. Karadeniz, H. Civelek Yörüklü, N. Manav Demir / Sigma J Eng & Nat Sci 35 (2), 265-273, 2017
Table 1. Performance data of the implemented tool for test problem: cyclones Definition of equation and global settings Parameter Value Regression equation ‘0.61*x5^2*(a1*x1+a2*x2+a3 *x3+a4*x4)
Maximum iteration Maximum error Percent step size Learning rate Estimated parameters and statistics Parameter Value (this study) k1 14.8588 k2 –0.6984 –0.4841 k3 k4 0.5738 Coefficient of 0.980 2 determination (R ) Mean square error 4370 (MSE)
Remarks x1 = ab/De2 (Eqn. 4.b); x2 = hb/D (Eqn. 4.b); x3 = hc/D (Eqn. 4.b); x4 = S/D (Eqn. 4.b); x5 = V (Eqn. 4.a); a1 = k1 (Eqn. 4.b); a2 = k2 (Eqn. 4.b); a3 = k3 (Eqn 4.b); a4 = k4 (Eqn 4.b) Gas density (ρ) is assumed to be 1.22 kg/m3 Dependent variable was cyclone pressure drop 5000 0.0001% 0.01% 0.01 Value [9] 14.8587 –0.6984 –0.4841 0.5738 0.976 Not specified
3.2. Aeration
A simple aeration equipment was used to obtain experimental data on the process of aeration in a complete-mix reactor. Experiments were conducted at constant temperature and pressure at a constant, low mixing intensity for a period of 230 minutes. In the experiment, water was purged with pure nitrogen gas to reduce initial concentration of dissolved oxygen to zero. A total of 29 data points were used in the regression. Table 2 shows the regression settings and results. The formulation in Eqn. 5.b was typed as the regression equation. The tool estimated the parameters in 955 iterations (less than 10 seconds) starting from random initial values between 0 and 1. The estimated value of final dissolved oxygen concentration, that’s the solubility of oxygen, was 8.45 mg/L with an estimated value of volumetric mass transfer coefficient of 0.0143/min. The mean square error (MSE) was calculated as 3.26*10-2 and the coefficient of determination between experimental and modeled DO concentration (R2) was calculated as 0.996. The results suggested that the implemented tool can be used for predicting experimental kLa value for a given aeration system. Fig. 3 shows the good agreement between experimental and model dissolved oxygen concentrations, verifying that the estimated value of kLa represents experimental data very well. Table 2. Performance data of the implemented tool for test problem: aeration Definition of equation and global settings Parameter Value Regression equation ‘a1*exp(-a2*x1) + (a3-a1)*(1- exp(-a2*x1))
Maximum iteration Maximum error Percent step size Learning rate Estimated parameters and statistics Parameter a1 a2 a3 Coefficient of determination (R2) Mean square error (MSE)
5000 0.0001% 0.01% 0.01 Value (this study) 0.00 0.0143 min-1
8.45. mg.L-1
Remarks x1 = t (Eqn. 5.b); a1 = C0 (Eqn. 5.b); a2 = kLa (Eqn. 5.b); a3 = CS (Eqn. 5.b)
An MS Excel Tool for Parameter Estimation by … / Sigma J Eng & Nat Sci 35 (2), 265-273, 2017
Figure 3. Experimental and model DO concentrations in water. a. correlation plot, b. time series data
3.3. Anaerobic Digestion
Bio-methane potential assay was performed for 20 days and produced biogas was measured at certain intervals. The rate of biogas production started with a low value and rapidly increased. The highest rate of production was observed in the second day of the experiment as 90 L/day under experimental conditions. Cumulative biogas production rate was 670 L at the end of 20 days. A total of 13 data points each consisting of a set of assay time (t) and cumulative biogas production (Vg) was used for regression to estimate the parameters Vmax, R, and L. Iterations were made by random initials. Table 3 shows the regression settings and results. The formulation in Eqn. 6 was typed as the regression equation. The tool found a feasible solution to the BMP problem in 257 iterations at a learning rate of 0.1. Calculated values were Vmax = 822.46 L, R = 67.74 day-1 and L = 0.103 day with R2 = 0.998 and MSE = 91.9. Fig. 4 shows the correlation plots of experimental and model results for cumulative biogas produced. Also, time series of experimental and model results are shown. The results indicated that the tool is able to handle nonlinear functions such as the transference function used in this work. Table 3. Performance data of the implemented tool for test problem: anaerobic digestion Definition of equation and global settings Parameter Regression equation ‘
Maximum iteration Maximum error Percent step size Learning rate Estimated parameters and statistics Parameter a1 a2 a3 Coefficient of determination (R2) Mean square error (MSE)
Remarks x1 = t (Eqn. 6); a1 = Vmax (Eqn. 6); a2 = R (Eqn. 6); a3 = L (Eqn. 6) 5000 0.0001% 0.01% 0.1 Value (this study) 822.46 L
67.74. day-1
S. Demir, A. Karadeniz, H. Civelek Yörüklü, N. Manav Demir / Sigma J Eng & Nat Sci 35 (2), 265-273, 2017
Figure 4. Experimental biogas production and results obtained by the implemented tool. a. correlation plot, b. time series data
4. Conclusions
An MS Excel VBA tool for general purpose multivariate nonlinear regression in environmental studies is presented in this study. The tool employs standard Guass-Newton algorithm to minimize the cost function which is defined as the sum of squares of differences between target and predicted values of a dependent variable. The tool’s performance is tested with a number of optimization problems that any environmental engineer encounter in his/her daily works. For each test problem, the tool completed calculations in less than 10 seconds. Calculated coefficients of determination were 0.98 and above and mean square errors were satisfactory. The results suggested that the MS Excel tool produces satisfactorily fast and reliable results, and can be used confidently for optimization works in environmental studies as well as for teaching purposes. The tool is an open-source, user-friendly VBA code and it is available on academic web pages of the authors.
Share and Cite
DEMİR, S.; KARADENİZ, A.; YÖRÜKLÜ, H.C.; DEMİR, N.M. An MS Excel Tool for Parameter Estimation by Multivariate Nonlinear Regression in Environmental Engi. Sigma Journal of Engineering and Natural Sciences 2017, Vol. 35, pp. 265-273. https://doi.org/10.62051/ytu.sigma-journal-of-engineering-and-natural-sciences-an-ms-excel-tool-for-parameter-estimation-by-multivariate-nonlinear-regression-i

