Introduction to Chemical Engineering Processes/Basic Statistics and Data Analysis

Mean and Standard Deviation
A lot of the time, when you're conducting an experiment, you will run it more than once, especially if it is inexpensive. Scientists run experiments more than once so that the random errors that result from taking measurements, such as having to guess a length between two hash marks on a ruler, cancel themselves out and leave them with a more precise measurement. However, the question remains: how should you consolidate all of the data into something that's more manageable to use?

Mean
Suppose you have n data points taken under the same conditions and you wish to consolidate them to as few as feasibly possible. One thing which could help is is to use some centralized value, which is in some way "between" all of the original data points. This, in fact, is called the mean of the data set.

There are many ways of computing the mean of a data set depending on how it is believed to be distributed. One of the most common methods is to use the arithmetic mean, which is defined as:

Other types of mean include the Geometric mean, which should be used when the data are very widely distributed (ex. an exponential distribution) and the "log-mean" which occurs often in transport phenomena.

Standard Deviation
Having a value for the mean tells you what value the data points "cluster" around but it does not tell you how spread out they are from the center. A second statistical variable called the standard deviation is used for that. The standard deviation is essentially the average distance between the data points and their mean. The distance is expressed as a squared distance in order to prevent negative deviations from lessoning the effect of positive deviations.

The mathematical formulation for the standard deviation $$ \sigma $$ is:

The denominator is n-1 instead of n because statisticians found that it gives better results for small numbers of experiments; see Standard deviation for a more thorough explanation of this.

Putting it together
The standard deviation of a data set measured under constant conditions is a measure of how precise the data set is. Because this is true, the standard deviation of a data set is often used in conjunction with the mean in order to report experimental results. Typically, results are reported as:

$$ \bar{x} \pm \sigma $$

If a distribution is assumed, knowing both the mean and standard deviation can help us to estimate the probability that the actual value of the variable is within a certain range, if there is no systematic bias in the data. If there is (such as use of broken equipment, negligence, and so on) then no statistics could predict the effects of that.

Linear Regression
Suppose you have a set of data points ($$ \hat{x}_k, \hat{y}_k $$) taken under differing conditions which you suspect, from a graph, can be reasonably estimated by drawing a line through the points. Any line that you could draw will have (or can be written in) the following form:

$$ y = mx + b $$ where m is the slope of the line and b is the y-intercept.

We seek the best line that we could possibly use to estimate the pattern of the data. This line will be most useful for both interpolating between points that we know, and extrapolating to unknown values (as long as they're close to measured values). In the most usual measure, how "good" the fit is is determined by the vertical distance between the line and the data points ($$ R_k $$), which is called the residual:

$$ R_k = (m\hat{x}_k + b) - \hat{y}_k $$

In order to normalize the residuals so that they don't cancel when one's positive and one's negative (and thus helping to avoid statistical bias), we are usually concerned with the square of $$ R_k $$ when doing least-squares regression. We use squared terms and not absolute values so that the function is differentiable, don't worry about this if you haven't taken calculus yet.

In order to take into account all of the data points, we simply seek to minimize the sum of the squared residuals:

$$ \mbox{ minimize }\Sigma {R_k}^2 $$

Using calculus, we can take the derivative of this with respect to m and with respect to b and solve the equations to come up with the values of m and b that minimize the sum of squares (hence the alternate name of this technique: least-squares regression. The formulas are as follows, where n is the total number of data points you are regressing[1]:

Example of linear regression
The first thing we should do with any data like this is to graph it and see if a linear fit would be reasonable. Plotting this data, we can see by inspection that a linear fit appears to be reasonable.



Now we need to compute all of the values in our regression formulas, and to do this (by hand) we set up a table:

Now that we have this data we can plug it into our linear regression equation:

$$ m^* = \frac{n*\Sigma(\hat{x}_k*\hat{y}_k)-\Sigma(\hat{x}_k)*\Sigma(\hat{y}_k)} {n*\Sigma(\hat{x_k}^2) - (\Sigma(\hat{x}_k))^2} $$

$$ = \frac{5* 15931.13 - 15.1*4642.2}{5*56.35 - (15.1)^2} $$

$$ = 177.9 \mbox{ } \frac{yard}{min} $$

So $$ b = \frac{\Sigma(\hat{y}_k) - m^{*}*\Sigma(\hat{x}_k)} {n} $$

$$ = \frac{4642.2 - 177.9*15.1}{5} = 391.2 \mbox{ yards} $$

Hence the equation for the line of best fit is:

The graph of this plotted against the data looks like this:



How to tell how good your regression is
In the previous example, we visually determined if it would be reasonable to perform a linear fit, but it is certainly possible to have a less clear-cut case! If there is some slight curve to the data, is it still "close enough" to be useful? Though it will always come down to your own judgment after seeing the fit line graph against the data, there is a mathematical tool to help you called a correlation coefficient, r, which can be defined in several different ways. One of them is as follows [1]:

It can be shown that this value always lies between -1 and 1. The closer it is to 1 (or -1), the more reasonable the linear fit. In general, the more data points you have, the smaller r needs to be before it's a good fit, but a good rule of thumb is to look for high (higher than 0.85 or 0.9) values and then graph to see if the graph makes sense. Sometimes it will, sometimes it won't, the method is not foolproof.

In the above example we have:

$$ r = \frac{5*15931.13 - 15.1*4642.2}{\sqrt{5*56.35-(15.1)^2}*\sqrt{5*4655464-(4642.2)^2}} $$

$$ r = 0.992 $$

Hence the data correlates very well with a linear model.

In general
Whenever you have to fit a parameter or multiple parameters to data, it is a good idea to try to linearize the function first, because linear regression is much less intensive and more accurate than nonlinear regression. The goal with any linearization is to reduce the function to the form:

$$ Variable\mbox{ 1} = constant + constant*\mbox{ Variable 2} $$

The difference between this and "standard" linear regression is that Variable 1 and Variable 2 can be any functions of x and y, as long as they are not combined in any way (i.e. you can't have $$ln(x + y) $$ as one variable). The technique can be extended to more than two variables using a method called multiple linear regression but as that's more difficult to perform, this section will focus on two-dimensional regression.

Power Law
To see some of the power of linearization, let's suppose that we have two variables, x and y, related by a power law:

$$ y = A*x^b $$

where A and b are constants. If we have data connecting changes in y to changes in x, we would like to know the values of a and b. This is difficult to do if the equation is in its current form but we can change it into a linear-type function!

The trick here is we need to get rid of the exponent b, so in order to do that we take the natural log of both sides:

$$ ln\mbox{ y} = ln\mbox{ (A*x}^b) $$

Using laws of logarithms we can simplify the right-hand side to obtain the following:

The beauty of this equation is that it is, in a sense, linear. If we graph ln(y) vs. ln(x) obtain a straight line with slope b and y-intercept ln(A).

Exponentials
Another common use of linearization is with exponentials, where x and y are related by an expression of the form:

$$ y = A*b^x $$

This works for any base but the most common base encountered in practice is Euler's constant, e. Again, we take the natural log of both sides, in order to get rid of the exponent:

This time, Graph ln y vs. x to obtain a line with slope ln(b) and y-intercept ln(A).

Linear Interpolation
Often, when you look up properties on a chart, you will be looking them up at conditions in between two charted conditions. For example, if you were looking up the specific enthalpy of steam at 10 MPa and 430oC you would look in the steam tables and see something like this: [2]

How can you figure out the intermediate value for this? We can't exactly but we can assume that H(T) is a linear function. If we assume that it is linear, then we can easily find the intermediate value. First, we set up a table, including the unknown value like this:

Then since we're assuming the relationship between T and H is linear, and the slope of a line is a constant the slope between points 3 and 2 has to equal the slope between points 3 and 1.

Therefore, we can write that:

$$ \frac{2943.4-x}{450-430} = \frac{2943.4-2832.4}{450-400} $$

Solving gives x = 2899 kJ/kg 

The same method can be used to find an unknown T for a given H between two tabulated values.

General formula
To derive a more general formula (though I always derive it from scratch anyways, it's nice to have a formula), lets replace the numbers by variables ad give them more generic symbols:

Setting the slope between points 3 and 2 equal to that between 3 and 1 yields:

This equation can then be solved for x* or y* as appropriate.

Limitations of Linear Interpolation
It is important to remember that linear interpolation is not exact. How inexact it is depends on two major factors:


 * 1) What the real relationship between x and y is (the more curved it is, the worse the linear approximation)
 * 2) The difference between consecutive x values on the table (the smaller the distance, the closer almost any function will resemble a line)

Therefore, it is not recommended to use linear interpolation if the spaces are very widely separated. However, if no other method of approximation is available, linear interpolation is often the only option, or other forms of interpolation (which may be just as inaccurate, depending on what the actual function is).

See also interpolation.