Biostatistics with R

Estimation of uncertainities using function derivatives

On many occasions, we find that a quantity (say) \(\small{f}\) is epxressed as a function of another quantity, say \(\small{x}\). In the language of mathematics, \(\small{x}\) is an independent variable and \(\small{f}\) i>s a function of x written symbolically as \(\small{f(x)}\).

The function f(x) can have any form, from simple straight line relationship to very complicated formula. We will consider a simple exponential relationship of the form,
\(~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\small{f(x) = 13.6 e^{1.2x}~~}\)

Now suppose we do an experiment and determine the value of \(\small{x}\) to be 0.96 with an uncertainity (error) of 0.12. We can find the value of f at x = 0.96 by substituting it in the above formula. We get \(\small{y = 13.6 e^{1.2\times0.96} = 43.04}\). That is fine. But, given an uncertainity of 0.12 on the x value of 0.96, what is the uncertainity on the computed value 43.04 of y? . We need to use the idea of "total differential" from calculus compute this error propagation from x to its function f(x) .


Absolute and relative changes


Consider a increment in the value of x by a small value \(\small{\Delta x }\). The value of function f at these two points is \(\small{f(x)}\) and \(\small{f(x + \Delta x) }\).

Then, \(~~\small{\Delta f = f(x + \Delta x) - f(\Delta x) }\) is the absolute change in f for a change \(\small{\Delta x }\) in x.

\(\small{~~~~\dfrac{\Delta f}{f}~~ }\) is the corresponding relative change in f.

\(\small{~~~~\dfrac{\Delta f}{f} \times 100 \%~~~ }\) is the corresponding percentage change in f.


The derivative of a function at a given point


Consider the two points \(\small{P(x, f(x)) }\) and \(\small{Q(x + \Delta x, f(x + \Delta x) }\) on the curve f(x). See the figure below:




An increment of \(\small{\Delta x }\) on x creates a change of \(\small{\Delta f }\) in f. As the increment \(\small{\Delta x }\) becomes smaller and smaller, the two points \(\small{P(x, f(x) )}\) and \(\small{Q(x+\Delta x, f(x+\Delta x)) }\) come closer and closer, and in the limit when \(\small{\Delta x }\) approaches zero, the chord joining the points P and Q will become the tangent to the curve at the point \(\small{(x, f(x))}\). In this limit, the ratio \(\small{\dfrac{\Delta f}{\Delta x} }\) which represents the change in f for a unit change in x becomes a constant, and is equal to the slope of the tangent to the curve at x.

We write this as,

$$ \small{ \lim_{\Delta x\to 0} \dfrac{\Delta f}{\Delta x} = \lim_{\Delta x\to 0} \dfrac{f(x+\Delta x) - f(x)}{\Delta x} = m = slope~of~the~tangent~at~x}$$



The slopes of tangent at various values of x are different. It is a continuous function of x, since f(x) is a continuous function. Therefore, we can find represent the slope of tangent at various x values as another function, called derivative function , represented by \(\small{f'(x)}\). Once this derivative function is found, slope of tangent at any point x=a will be just \(\small{f'(a) }\). In our calculus class, have learnt to compute the derivative function \(\small{f'(x)}\) for any continuous function \(\small{f(x)}\).

The derivative f'(a) at x=1 gives the instantaneous rate of change of f with respect to x at x=a. It is a slope of the tangent for the curve f(x) at x=a, and is a number.


The differential of a function

For a small change \(\small{\Delta x}\) along on x, the function f(x) changed by \(\small{\Delta f }\). The ratio \(\small{\dfrac{\Delta f}{\Delta x} }\) gives the derivative (or slope of tangent) at x in the limit when \(\small{\Delta x }\) tends to zero. This "\(\small{\Delta x }\) tends to zero" is a mathematical concept. In real life situations, we are interested in computing the change in f for a very small, but finite change in x . This change can be as small as we require, but will not "tend to zero" as a limit.

Let \(\small{dx }\) be a very small change in \(\small{x}\). Let us denote the corresponding change in \(\small{f}\) by \(\small{df}\).

In order to find a relationship between \(\small{dx}\) and \(\small{df}\), we make use of the tangent to the curve at \(\small{x}\). See the figure below:






In the figure above, TA is the tangent line to the curve at a point \(\small{x}\), whose slope at \(\small{x}\) is \(\small{f'(x)}\).

When \(\small{x}\) incremented by an amount \(\small{dx}\), there is a vertical increment of \(\small{df}\) along the tangent line, while the vertical increment along the curve is \(\small{\Delta y }\).

The difference \(\small{\epsilon = \Delta f - df }\) between the climb along the curve and the tangent reduces as the increment \(\small{dx }\) becomes smaller and smaller. We now have a freedom to choose \(\small{\Delta x }\) sufficiently small so that this error \(\small{\epsilon }\) becomes negligible when compared to the dimensions of the problem..

The, we can write, for the right angled triangle PRS,

\(\small{ tan(a)~ = ~\dfrac{SR}{PR} ~= ~\dfrac{df}{dx}~ =~ f'(x)~ =~ slope~of~the~tangent~at~x }\)

From this, we get this important result:

\(~~~~~~~~~~~~~~~~~~~\large{ df~=~f'(x) dx }\)

ie., when \(\small{x}\) changes to \(\small{x + dx }\), the corresponding change \(\small{df }\) in the function\(\small{f(x) }\) is obtained by multiplying \(\small{dx}\) by the derivative of f at x.

This change \(\small{df}\) in \(\small{f}\) is along the tangent to the curve \(\small{f(x)}\) at x.

The difference (error) \(\small{\epsilon }\) between the change in \(\small{f}\) along the curve and the change in \(\small{f}\) along the tangent can be made negligibly small for the dimensions involved by a suitably small increment \(\small{dx}\)

\(\small{df}\) is called the differential of the function . It represents the actual change in the function when its variable changes by a small amount.

Now, we can treat \(\small{df}\) as the uncertainity or error in \(\small{f}\) due to the error \(\small{dx }\) in \(\small{x}\). Thus the above formula can be used to calculate error as well as uncertainity propagtion from x to x+dx.



Important Note 1: In this discussion, the \(\small{dx}\) and \(\small{df}\) are very small but finite increments. This means, \(\small{\dfrac{df}{dx} }\) is a ratio of these two actual increments. Confusingly, the symbol \(\small{\dfrac{df}{dx} }\) is also used for the derivative of f at x, instead of \(\small{f'(x)}\). We will consistently use \(\small{f'(x)}\) for the derivative and \(\small{\dfrac{df}{dx} }\) to represent the rato of finite increments in f and x.

Example-1 : A quantity Q is expressed as a function of a variable x by \(\small{Q = 3.1 x^2 + 1.5x + 2}\). The value of x was measured to be \(\small{x = 4.25 \pm 0.2}\). Find the uncertainity in Q.

We have \(~~\small{Q = 3.1x^2 + 1.5x + 2}\)

taking first derivative of Q with respect to x, we have
\(\small{Q'(x) = 3.1 \times 2x + 1.5 ~=~6.2x + 1.5 }\)

For \(\small{x = 4.25 }\), the uncertainity \(\small{dx = 0.2}\)

The value of Q at x=4.25 is,\(~~\small{Q = 3.1 \times 4.25^2 + 1.5\times4.25 + 2~~=~~64.36 }\)

The uncertainity in Q when x = 4.25 is given by,

\(\small{dQ = Q'(x)dx = (6.2 \times 4.15 + 1.5) \times 0.2~~=~~5.57}\)

The differential of a function with many variables

We have a function that depends on more than one variable, uncertinities in each one of these variables contribute to the uncertainity in the function. The differential of the function has contrinution from the variations in all its variables.

The differential of a single variable function \(\small{f(x) }\) is given by \(\small{df = f'(x)dx}\).

Suppose the function f is dependent on three variables \(\small{x,y,x}\). In this case, the above concept is extended to write the total differential of f in terms of the partial derivatives of f with respect to its variables as,

\(~~~~~~~~~~~~\small{df~=~\dfrac{\partial f}{\partial x} dx~+~\dfrac{\partial f}{\partial y} dy~+~\dfrac{\partial f}{\partial z} dz }\)

Where, \(~~\small{\dfrac{\partial f}{\partial x} }~~\), \(~~\small{\dfrac{\partial f}{\partial y} }~~\) and \(~~\small{\dfrac{\partial f}{\partial z} }~~\) represent the partial derivative of the function f with respect to the variables x, y and z respectively and ther terms dx, dy and dz represent the increment in the respective variables. To take a partial derivative of the function with respect to any one variable, differentiate the function with respect to that variable, while treating the remaining variables as constants.

As an example, we take the partial derivatives of the function \(~~\small{f = x^2y^2z^2 }\) as follows:

\(~~~~~~~~~\small{\dfrac{\partial f}{\partial x} = 2x(y^2z^2) }~~~~~~\) (differential the x term, keep y and z as constants)

\(~~~~~~~~~\small{\dfrac{\partial f}{\partial y} = 2y(x^2z^2) }~~~~~~\) (differential the y term, keep x and z as constants)

\(~~~~~~~~~\small{\dfrac{\partial f}{\partial z} = 2z(x^2y^2) }~~~~~~\) (differential the z term, keep x and y as constants)




We can extend the above concept to a function with any number of dependent variables x,y,x,w,.... and write down the expression for the differential as,

\(~~~~~~~~~~~~~~~{ df~=~ \dfrac{\partial f}{\partial x} dx~+~\dfrac{\partial f}{\partial y} dy~+~\dfrac{\partial f}{\partial z} dz ~+~ \dfrac{\partial f}{\partial w} dw~+~.... }\)

If we take the uncertainities on the values (x,y,z,w,...) to be (dx,dy,dz,dw,...) respectively, then we can compute the combined uncertainity in f using the above formula. For this, we have to compute the partial derivatives of f at (x,y,x,w,...).


Example-1 : The length l, width w and the height h of a tank in the shape of a rectangular paralleopiped was measured and the following result was quoted with uncertanities:

\(~~~~~~~~~~~~~~\small{w = 23.55 \pm 0.08~m,~~l = 35.41 \pm 0.1~m,~~h = 8.6 \pm 0.05~m}\).

Compute the uncertainity in the volume computed as \(\small{V = lwh}\).

We have the uncertainities \(\small{dl=0.08~cm, dw=0.1~m~~and~~dh=0.05m }\)

We compute the partial derivatives of V with respect to variables at given values as,

\(\small{\dfrac{\partial V}{\partial l}~=~wh~=~23.55 \times 8.6~=~202.53 }\)

\(\small{\dfrac{\partial V}{\partial w}~=~lh~=~35.41 \times 8.6~=~304.52 }\)

\(\small{\dfrac{\partial V}{\partial h}~=~wl~=~23.55 \times 35.41~=~ 833.90 }\)

The combined uncertainity in the volume V is given by,

\(\small{V~=~ \dfrac{\partial V}{\partial l} dl~+~\dfrac{\partial V}{\partial w} dw~+~\dfrac{\partial V}{\partial h} dh~~=~~(202.53 \times 0.1) + (304.52 \times 0.08) + (833.90 \times 0.05)~~=~~ 86.31~m^3 }\)

Volume of the tank = \(\small{V = 23.55 \times 35.41 \times 8.6 ~=~7171.58~m^3 }\)

With uncertainity, it is written as,\(~~~\small{V = 7171.58 \pm 86.31~~m^3 }\)


Important Note : In the derivation of above expressions (not shown here) for \(\small{df}\), the higher order derivatives of f with respect to variables were assumend to be insignificant, and hence were omitted from expressions. This amounts to the assumption that the first order changes remain constant over the range of variables in the problem. If not, higher order terms (in the Taylor's expansion involved) should be included.