{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1 Characterizing experimental data. Accuracy, precision, mean and standard deviation"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# import all python add-ons etc that will be needed later on\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sympy import *\n",
"from scipy.integrate import quad\n",
"from scipy.stats import t,norm # statistical functions\n",
"init_printing() # allows printing of SymPy results in typeset maths format\n",
"plt.rcParams.update({'font.size': 14}) # set font size for plots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.1 The Mean or Average value\n",
"\n",
"If several readings have been taken of a quantity $x$, for example a titration is performed $N$ times with identical solutions in an attempt to be precise, the titration's end-point volume will be quoted as the arithmetic sample average $\\langle x\\rangle$ of all the $n$ measurements. This is sometimes also labelled $\\bar x$ (pronounced 'x-bar') and the word 'mean' is often used instead of average. The arithmetic average is\n",
"\n",
"$$\\displaystyle \\langle x\\rangle =\\frac{1}{n}\\sum_{i=1}^{i=n} x_i=\\frac{1}{n}(x_1+x_2+x_3\\cdots x_n)\\qquad\\tag{1}$$\n",
"\n",
"where $x_1+x_2+x_3\\cdots x_n$ are the measurements. This average value will probably not be the same as any individual value and these will always be spread either side of the mean. The sum of the difference between each point and the average, is always zero; \n",
"\n",
"$$\\displaystyle \\sum_i(x_i-\\langle x\\rangle)=0$$\n",
"\n",
"![Drawing](analysis-fig1.png)\n",
"\n",
"Figure 1. The experimental average value $\\langle x\\rangle$ tends towards the population or theoretical mean $\\mu$ as the number of samples increase. The sample standard deviation $s$ is also shown and this tends to a constant value of 1/4 as $n$ increases. (Note the logarithmic abscissa scale). The samples are taken from a Normal distribution with $\\mu = 1/2$ and $\\sigma = 1/4$.\n",
"________________\n",
"\n",
"One trajectory showing the way the mean value is approached as the number of experiments is increased is shown in figure 1; the sample standard deviation $s$ (equation 2) is also shown. The samples at each $n$ are from a new list of length $n$ selected at random a normal distribution (figure 4) with a mean $1/2$ and a standard deviation $1/4$. In many experiments, the inherent accuracy of each measurement may not be the same and then the mean and standard deviation have to be _weighted_ to reflect this. This is described in Section 3.8.\n",
"\n",
"## 1.2 Sample Standard Deviation and parent or population Variance\n",
"\n",
"A measure of the spread of the results is the sample standard deviation $s$. The square of the standard deviation is called the _variance_ . The sample standard deviation is\n",
"\n",
"$$\\displaystyle s=\\sqrt{\\frac{1}{n-1}\\sum_{i=1}^n \\big( x_i - \\langle x\\rangle \\big)^2 } \\qquad\\tag{2}$$\n",
"\n",
"and is sometimes called the root mean square (or *rms*) deviation. This formula produces an unbiased estimate of $s$, but note that some authors define the standard deviation by dividing by $n$ rather than $n - 1$; there is not a single definition of $s$; see Barlow (1989, p. 11). The standard deviation is one of a class of measures called _dispersion indices_ ; range, quantile, skew, and kurtosis (peakedness) are others.\n",
"\n",
"In words, the formula for s says 'for each of the n measurements, subtract the average $\\langle x\\rangle$ from each $x$ value, square the result and then add up all the answers. Next, divide by the total number of measurements less one and finally take the square root'.\n",
"\n",
"The principle of _least squares_ is widely used in modelling or analysing data; see Section 5.2, and this approach minimizes a function such as\n",
"\n",
"$$\\displaystyle \\sum_{i=1}^n ( x_i - M )^2 $$\n",
"\n",
"with respect to $M$, where $M$ might represent some 'model' which is an equation or single value describing a set of data. In the definition of the standard deviation $s$, it appears that $M = \\langle x \\rangle$, therefore, if $s$ is a least squares estimate, the summation should be at a minimum when $M = \\langle x \\rangle$. Differentiating the sum of squares with respect to $M$ and setting the result to zero produces\n",
"\n",
"$$\\displaystyle \\frac{d}{dM}\\sum_{i=1}^n ( x_i - M)^2=-2\\sum_{i=1}^n ( x_i - M)+2nM=0$$\n",
"\n",
"or \n",
"\n",
"$$ \\displaystyle M=\\frac{1}{n}\\sum_{i=1}^n x_i$$\n",
"\n",
"showing that, indeed, $M = \\langle x \\rangle$. The mean value makes the sum of squares a minimum, and in this sense it is the best estimate of the deviation.\n",
"\n",
"Suppose that there is an underlying parent distribution whose width determines the standard deviation. This has a mean $\\mu$, called the _population mean_ , and its standard deviation is $\\sigma$; Greek letters being reserved for parent quantities, then this parent distribution is what an infinite number of ideal experimental results would produce. This ideal distribution is assumed to be the normal (Gaussian) distribution, see Figs 3 and 4. (The other common distribution is the Poisson, figure 13 which approximates the normal when its mean is $\\approx 10$ or greater.) The sample mean $\\langle x \\rangle$ is more likely than not to be different to the population mean $\\mu$. If it can be shown that the average of all sample means s equals the population or true mean value μ, then the sample mean is an unbiased estimate of the population mean.\n",
"\n",
"The standard deviation and variance can also be defined with reference to the parent distribution and then this _population_ or _parent variance_ $\\sigma^2$ is\n",
"\n",
"$$\\displaystyle \\sigma^2=\\frac{1}{n}\\sum_{i=1}^n(x_i-\\mu)^2 \\qquad\\tag{3}$$\n",
"\n",
"which assumes that $\\mu$ is known, whereas $s$, equation 2, is obtained only from the data itself. The variance is the single most important parameter when describing the parent population. To calculate $\\sigma^2,\\; \\mu$ has to be known, but $\\mu$ can never be exactly known in any set of measurements. The best estimate of this has to be used instead and is obtained from the set of measurements; this is usually taken to be\n",
"\n",
"$$\\displaystyle \\sigma^2=\\frac{n}{n-1}s^2$$\n",
"\n",
"which is an unbiased estimator of $\\sigma^2$. Strictly speaking, the equality symbol = should be replaced by $\\approx$ 'approximately' because this is an estimation; however, equality is usually used. The factor $n/(n - 1)$ enters because of an argument from statistical theory. The term reflects the degrees of freedom left with which to describe the data. Each parameter that is defined is considered to impose a restraint on the data and is, roughly speaking, equivalent to removing one data point. The more parameters that are measured the fewer data points there are left to describe the data (Parratt 1971).\n",
"\n",
"## 1.3 Standard Deviation in the Mean\n",
"\n",
"If experimental measurements are repeated, slightly different values of the mean are expected because only a few of the possibly infinite number of values needed to define the true result can be measured. The difference between any two means would be expected to be less than the standard deviation in either set. The standard deviation of the means would then be written in the same way as equation 2 as \n",
"\n",
"$$\\displaystyle s_m=\\sqrt{\\frac{1}{n-1}\\sum_{i=1}^n(m_i-\\langle m \\rangle)^2}$$\n",
"\n",
"where $\\langle m \\rangle$ is the average of the means of $N$ separate experiments. To evaluate this summation directly would require a huge number of experiments, viz; $nN$; however, a satisfactory formula is obtained by statistical theory and is\n",
"\n",
"$$\\displaystyle s_m=\\frac{s}{\\sqrt{N}}$$\n",
"\n",
"Experimentally, the square root makes improving precision quite a slow process; $100$ measurements are needed to improve the signal to noise by $10$ times, which means reducing the $s_m$ relative to the mean by $10$ times. The Hadamard transform method, Chapter 9, enables the experimenter to measure in groups and the noise can then be reduced more rapidly than $N$.\n",
"\n",
"The quantity $s_m$ is sometimes called the _estimated standard error on the mean_ or just the _standard error on the mean_ or simply the _standard error_. To relate this to the population standard deviation,\n",
"\n",
"$$\\displaystyle \\sigma_m=\\frac{\\sigma}{\\sqrt{N}}$$\n",
"\n",
"however, this is also called the standard error. Clearly, these names are not fixed so it is\n",
"always necessary to check the equation being used, which unfortunately, is not always given.\n",
"\n",
"## 2 Central Limit Theorem\n",
"\n",
"The mean $\\mu$ and standard deviation $\\sigma$ are used assuming that data is distributed normally. But many quantities measured are not expected to have a normal distribution; for example, when counting photons or particles, a Poisson distribution is produced which is quite unlike a normal distribution at small $\\mu$, see figure 13. The speed of a molecule follows a Maxwell - Boltzmann distribution (see chapter 3 Q54), which is clearly skewed or lopsided, again quite unlike a normal distribution. However, remarkably, if several measurements are taken of a given velocity, their distribution will be normal. This is what the central limit theorem predicts and although easy to demonstrate, it is harder to prove. It states that by taking many similar measurements from (almost) any type of continuous distribution, the result always approaches a normal (Gaussian) distribution. This population distribution has the theoretical form\n",
"\n",
"$$\\displaystyle p(x)=\\frac{1}{\\sqrt{2\\pi \\sigma^2}}e^{\\large{-\\frac{(x-\\mu)^2}{2\\sigma^2}} }\\qquad\\tag{4}$$\n",
"\n",
"where $\\mu$ is the mean of the distribution and $\\sigma$ the standard deviation. The central limit theorem forms the basis by which the standard deviation of a normal distribution is used to characterize data.\n",
"\n",
"The reasoning put more technically is that the sample mean $\\langle x\\rangle$, although an unbiased estimate, is unlikely to be exactly equal to the true population mean $\\mu$ and is itself subject to random variation. By repeating the sampling process, i.e. by repeating the whole set of measurements, a number of different estimates of $\\langle x\\rangle$ are obtained which are distributed about the true value $\\mu$. To simulate this and illustrate the central limit theorem, suppose that there are five measurements A, B, C, D, and E and each is an experimental result with values $1, 2, 3, 4$, and $5$ respectively. Any other numbers could be used but these are easy to average. The distribution of the numbers is uniform as shown in figure 2.\n",
"\n",
"Suppose that randomly selected pairs of these values are taken making $2$5 possible samples. The pairs are shown on the left of the table and the corresponding average (sample mean) is shown on the right. Looking at this table there are five entries with a value of $3$, and only $1$ entry each with a value of $1$ or $5$. If plotted as a histogram, this begins to look a little like a normal distribution; figure 2.\n",
"\n",
"![Drawing](analysis-table-1.png) ![Drawing](analysis-fig2.png)\n",
"\n",
"Figure 2. Uniform distribution and the (normalized) histogram formed by sampling pairs of numbers.\n",
"______\n",
"\n",
"Using Python the Central Limit theorem can be demonstrated more convincingly as shown with the next algorithm. The random numbers are chosen from a uniform, i.e. flat, distribution between zero and one. Five samples are taken each time and the process repeated five thousand times; see figure 3 for the result. It can be seen that the sample averages that form the histogram are more closely clustered about the population mean and are therefore less variable than the original data. It can be shown that the variation in the mean, which is the uncertainty in the mean, equals the variation in $\\langle x\\rangle$ divided by the sample size, $\\sigma^2/n$. With this in mind the normal distribution plotted on top of the histogram of the data is\n",
"\n",
"$$\\displaystyle p(x)=\\frac{1}{\\sqrt{2\\pi\\sigma^2/n}}e^{-\\large{ (x-\\mu)^2/(2\\sigma^2/n)} }$$\n",
"\n",
"Many other initial distributions can be chosen to start with besides the uniform distribution illustrated here. For (almost) all distributions, a normal distribution will eventually be formed, although this may require a huge number of calculations.\n",
"\n",
"![Drawing](analysis-fig3.png)\n",
"\n",
"Figure 3. Illustrating the central limit theorem.\n",
"______"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Algorithm: Central limit\n",
"\n",
"m = 5000 # number of reeat calculations\n",
"av= np.zeros(m,dtype=float) # array to hold data\n",
"x = np.linspace(0,1,100) # use to plot gaussian equation \n",
"n = 5 # number to average\n",
"for i in range(m):\n",
" av[i] = np.sum( np.random.rand(n) )/n # make average n points flat distribution \n",
"av_x= np.sum(av)/m # average x \n",
"\n",
"sig = np.sqrt( np.sum( (np.random.rand(m) - av_x )**2 )/m ) # sigma calculated \n",
"\n",
"gaus = lambda x,sig: np.exp(-(x-av_x)**2/(2*sig**2/n))/np.sqrt(2*np.pi*sig**2/n) # gaus distribution\n",
"\n",
"# #remove hash symbols to plot data as in fig 3\n",
"#fig = plt.figure(figsize=(8,6) )\n",
"#plt.rcParams.update({'font.size': 16}) # set font size for plot\n",
"#plt.plot(x,gaus(x,sig),color='red') # plot gaussian function with mu and sigma \n",
"#plt.hist(av,bins=50,density=True,color='lightgrey',edgecolor='black') # plot histogram of data \n",
"#\n",
"#plt.xlabel(r'$\\langle x\\rangle$')\n",
"#plt.ylabel('number with '+r'$\\langle x\\rangle$')\n",
"#plt.axhline(1,linewidth=1,color='grey')\n",
"#plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3 Confidence intervals\n",
"\n",
"The central limit theorem shows that repeated measurements follow a normal distribution (see Section 3.1) with a mean $\\mu$ and variance $\\sigma^2/n$ for n separate measurements. The mean $\\mu$ may be known from theoretical considerations or from other experimental data. The properties of the normal distribution are used to provide estimates of the probability that, by chance alone, a measurement of the mean will fall inside or outside a certain value.\n",
"\n",
"The standard deviation of the mean is often referred to as the standard error on the mean and defined as \n",
"\n",
"$$\\displaystyle \\sigma_m = \\sigma/\\sqrt{n}$$\n",
"\n",
"This confirms that measurements get more precise with the square root of the number of measurements. If a new statistic $Z$ is defined as\n",
"\n",
"$$\\displaystyle Z=\\frac{\\langle x\\rangle -\\mu}{\\sigma/\\sqrt{n}}\\qquad\\tag{5}$$\n",
"\n",
"this is distributed as the standard normal distribution with a mean of zero and a standard deviation of one. Notice that $Z$ increases as $\\sqrt{n}$. Because $\\langle x\\rangle$, the experimental or sample mean value, is unlikely to be equal to $\\mu$, there is a need for a measure of the confidence that we have in $\\langle x\\rangle$. From the properties of the normal distribution (see next section), there is a $95$% chance that $Z$ falls within the range $\\pm 1.96$. This is written as\n",
"\n",
"$$\\displaystyle p\\left(-1.96 \\lt \\frac{\\langle x\\rangle -\\mu}{\\sigma/\\sqrt{n}} <1.96 \\right)=0.95$$\n",
"\n",
"and hence\n",
"\n",
"$$\\displaystyle p\\left(\\langle x\\rangle -1.96\\frac{\\sigma}{\\sqrt{n}} \\lt \\mu \\lt \\langle x\\rangle +1.96\\frac{\\sigma}{\\sqrt{n}} \\right )= 0.95$$\n",
"\n",
"This is interpreted to mean that there is $95$% confidence that the population mean will fall in the interval $\\displaystyle \\pm 1.96\\frac{\\sigma}{\\sqrt{n}}$ and is written as\n",
"\n",
"$$\\displaystyle \\langle x\\rangle \\pm 1.96\\frac{\\sigma}{\\sqrt{n}} \\qquad\\tag{6}$$\n",
"\n",
"In practice, the standard deviation is almost never known and if the number of samples is large, typically $\\gt 25$, then $\\sigma$ can be replaced by $s$ the sample standard deviation, and then\n",
"\n",
"$$\\displaystyle \\langle x\\rangle \\pm 1.96\\frac{s}{\\sqrt{n}} \\qquad\\tag{6a}$$\n",
"\n",
"Confidence limits are not always used when quoting results and it is common to see $\\langle x\\rangle \\pm \\sigma$ quoted instead. Unless this is qualified as being $1\\sigma,\\; 2\\sigma$ etc., what is implied by this is uncertain. If the error is $\\pm\\sigma$ then $\\approx 68$% of all measurements fall in this range. Table 1 gives other values.\n",
"\n",
"### **(i) Table of different sigma's** \n",
"$$\\displaystyle \\begin{array}{l|l l}\n",
"\\hline\n",
"\\text{% chance} & &\\text{dispersion index} \\\\\n",
"\\hline\n",
"38.3 & &\\sigma/2\\\\\n",
"50 & &0.675\\sigma \\equiv p_e\\\\\n",
"68.3 & &\\sigma\\\\\n",
"82.2 & &2p_e\\\\\n",
"95 & &1.96\\sigma\\\\\n",
"95.45 & &2\\sigma\\\\\n",
"99.73 & &3\\sigma\\\\\n",
"99.9999 & & 5\\sigma\\\\\n",
"\\hline \\end{array}$$\n",
"\n",
"Sometimes, a statement may be made along the lines that a measurement has produced a result that is more than 'five sigma from the mean'. This means that the chance of this occurring is $1/25 \\equiv 4$%, which would suggest that it does not belong to the same distribution as other measurements. However, if only a few data points have been taken then there would be less confidence in assuming this, as to opposed to perhaps $100$ values in the data set with the mean and standard deviation properly established. \n",
"\n",
"However, the 'five sigma' statement can also be used with the normal distribution and this is far more common, particularly in particle physics. By integrating the distribution from $-\\infty\\to x$ the cumulative distribution is obtained. Thus there is a $50$% chance of being within $0.675\\sigma$, (this is sometimes called the probable error), a $68.5$% chance of being within $1\\sigma$ and a $95$% chance of being within $1.96\\sigma$, and $95.45$% chance of being within $2\\sigma$ and so on. For $5\\sigma$ the chance is $99.9999$%, pretty much a 'dead cert'. \n",
"\n",
"## 3.1 The normal and standard normal distribution\n",
"\n",
"The normal (Gaussian) distribution with mean $\\mu$ and variance $\\sigma^2$ has the form\n",
"\n",
"$$\\displaystyle p(x)=\\frac{1}{\\sqrt{2\\pi\\sigma^2}}e^{-\\large{ (x-\\mu)^2/(2\\sigma^2)} }$$\n",
"\n",
"which is normalised to one; $\\displaystyle \\int_{-\\infty}^\\infty p(x)dx=1$. The mean, average, or expectation value of $x$ is\n",
"\n",
"$$\\displaystyle \\int_{-\\infty}^\\infty xp(x)dx=\\mu\\equiv \\langle x\\rangle$$\n",
"\n",
"and the variance is \n",
"\n",
"$$\\displaystyle \\int_{-\\infty}^\\infty (x-\\mu)^2p(x)dx=\\sigma^2\\equiv \\langle x^2\\rangle-\\langle x\\rangle^2 $$\n",
"\n",
"The _standard normal distribution_ describes a Gaussian (bell-shaped) curve with a mean of zero and a standard deviation of one, viz.,\n",
"\n",
"$$\\displaystyle p(x)=\\frac{1}{\\sqrt{2\\pi}}e^{-\\large{ (x-\\mu)^2/2} }\\qquad\\tag{7}$$\n",
"\n",
"The total area under the curve is one and the area between symmetrically placed $x$ values gives the probability of falling within that area. The area $p(x)$ is the probability of an observation being between $\\pm x$;\n",
"\n",
"$$\\displaystyle p(x)=\\int_{-x}^x e^{-x^2/2}dx=\\mathrm{erf}\\left(\\frac{x}{\\sqrt{2}}\\right)\\qquad\\tag{8}$$\n",
"\n",
"The area within limits $\\pm 1.96$ is $\\mathrm{erf}(1.96/\\sqrt{2}) = 0.950$; hence this is the $95$% chance as described by equation 6. In figure 4, the total area in yellow adds up to $5$% of the total, meaning that a value that differs from the mean should exceed $\\pm 1.96$ by pure chance only on $5$% of all measurements.\n",
"\n",
"The probable error $p_e$ divides the normal distribution area into two with areas placed symmetrically about zero. The areas are $1/4:1/2:1/4$; the distribution's $x$ value is $p_e = \\pm 0.6745\\sigma$. Some values of the area and hence the chance of a value occurring within different standard deviations of the mean is shown in Table 1.\n",
"\n",
"Specific areas may be calculated using the _cumulative distribution_ function, or directly by integrating the normal distribution from $-\\inf \\to x$. For the reverse process - starting with the area to obtain the $x$ value producing that area - the quantile function is used. For example, with the normal distribution with a mean of zero and standard deviation of one the calculation of the cumulative value is, for example usimng $\\sigma/2$, see table 1, as the value and using Python/Sympy"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANIAAAAQCAYAAABjuSH9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAAHPklEQVR4nO2be6wW1RXFfxfBt1JFraltVKg0am2vrS+sqGikjUQCVo0xWDUB0ygBajG2tnS5awxYg4rPAhqxatrYlppSEFE0tVSqiYGowSpVwV6tD6goIhS50D/2GZg7znwzZ+bDv+5KJuebmT3nrDWzzzn7PL6Obdu20Yte9KIZ+mYvmNmXgV8C3wMGAP8BHgFM0gexBZjZmcB4YAiwH7AWeBGYIWlByq4DGBuOo4EO4GXgHmCWpK05eZ8HnAZ0At8E9gEekjQmgt8Y4IFwOk7S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M7l1Eve+amsJi6unUDDJ0BQ1fbWTOP1PAF/FdRyLT6dvwCvqA8BtSQ/d0fs3il70ojn+D6JvS7PkViatAAAAAElFTkSuQmCC\n",
"text/latex": [
"$\\displaystyle 0.691462461274013$"
],
"text/plain": [
"0.6914624612740132"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = symbols('x')\n",
"w = 0.5\n",
"ans = integrate(exp(-x**2/2)/sqrt(2*pi),(x,-oo,w)) # integrate -infinity to w \n",
"float(ans)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The same integration can be done numerically using the 'quad' routine. Note that this routine returns two numbers, the integral's value and the error, $\\mathtt{err}$."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANIAAAAQCAYAAABjuSH9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAAHPklEQVR4nO2be6wW1RXFfxfBt1JFraltVKg0am2vrS+sqGikjUQCVo0xWDUB0ygBajG2tnS5awxYg4rPAhqxatrYlppSEFE0tVSqiYGowSpVwV6tD6goIhS50D/2GZg7znwzZ+bDv+5KJuebmT3nrDWzzzn7PL6Obdu20Yte9KIZ+mYvmNmXgV8C3wMGAP8BHgFM0gexBZjZmcB4YAiwH7AWeBGYIWlByq4DGBuOo4EO4GXgHmCWpK05eZ8HnAZ0At8E9gEekjQmgt8Y4IFwOk7SPQ11DABGAyOAY4BDgM3B9j7gvjwtdXlFcot6X3W0mNml4V4rbJW0SyuDKvpjfbWOv5jZjcBxwGDgAGAjsDqUc4ektQB9Mg8NAp4HLgOeA24BXgcmAkvDi60MM/sV8EQg8mdgOjAfOBA4PWP+IDALOAz4LV6B9gTuBuYUFPFz3IE6gbdiuAV+XwHuAD4usYvRcT4wG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FCh9/g4cCUEvME60JaSUdBuePxadMVwDBJ/20Dr7Zwi0WZloJnjsa/YRewIOd+Hf3t9NUoSHpX0p/w0HEAzr3HGOmVkA4uyOOIkBbFpWkkea0ruJ8slu2RIvgpcGM4tsPMdg9lr5H0RoWyi7A3O7RtMrM8m9lmNhsf7E6iho40zGwSvr7xEnCmpLyGoA4vmnKLRUUteSibZGjyXdrhq7UgabWZrQA6zeyAdI+UzKkPN7PsQu0+wHeAT4B/VChnMR63H5XNKyAZGFepGBcCu+KLtE3wP+DegmNZsFkSzpPworYOM7sGd7zleOtd5Hh1eDXiFosILdnndsfDv26cfx7q6G+nrzbBl0Lavb1HkvSamS3Cu6wrgdtTDxi+ujtT0va5/TCf3w94Lb1mEWrrPHwxbyL+EZJnhgPfxVvShanr+0r6KM3SzDqBm/DWdVp9vRAGsGPz7pnZdfhA9/70VpQ6OsK9KfjWlefxAWlhCFSHVxNusYjRkoPz8QmivxRNMtT8LtG+WgdmNhh4V9KHmet9gOvxCZ9nJH2Q3dlwBfAMcJv5/q2X8e0hw/Bu8mcZ+8XAofi09arMvSvxl3CzmY3AW5fDgVF4CzU2Q/BxM9uIhw7rgSPxPV4bgXMkvZ0jdFTID3asRQ0xsznh9xpJhTsDKiJKh5ldgjteN/A3YEJOuLJK0pzsxc+B2ygi3lcbtCRhXeFOhgaI9dU6/nI2MNXMluA9+1rgi/iuiIHAO8A4yGwRCjX9OHZsBDwb3wg4g8hNq5K6zOzb+LTmSHw69iNgHjBV0nOZR/6Ah3Fj8Lj+LfwDTJXUVVBMJz4pkcZAdqw9rabFFpudpCNZC9sFnyrNw18p3j+4M7l1Eve+amsJi6unUDDJ0BQ1fbWTOP1PAF/FdRyLT6dvwCvqA8BtSQ/d0fs3il70ojn+D6JvS7PkViatAAAAAElFTkSuQmCC\n",
"text/latex": [
"$\\displaystyle 0.691462461274013$"
],
"text/plain": [
"0.6914624612740132"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fnorm = lambda x :np.exp(-x**2/2)/np.sqrt(2*np.pi)\n",
"ans, err = quad(fnorm,-np.inf,w)\n",
"ans"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"now using the built in cumulative distribution, where $\\mathtt{norm}$ is loaded as a library (from scipy.stats import norm, see top of page) and using $\\mathtt{cdf()}$ which is built in also, produces the same value."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANIAAAAQCAYAAABjuSH9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAAHPklEQVR4nO2be6wW1RXFfxfBt1JFraltVKg0am2vrS+sqGikjUQCVo0xWDUB0ygBajG2tnS5awxYg4rPAhqxatrYlppSEFE0tVSqiYGowSpVwV6tD6goIhS50D/2GZg7znwzZ+bDv+5KJuebmT3nrDWzzzn7PL6Obdu20Yte9KIZ+mYvmNmXgV8C3wMGAP8BHgFM0gexBZjZmcB4YAiwH7AWeBGYIWlByq4DGBuOo4EO4GXgHmCWpK05eZ8HnAZ0At8E9gEekjQmgt8Y4IFwOk7SPQ11DABGAyOAY4BDgM3B9j7gvjwtdXlFcot6X3W0mNml4V4rbJW0SyuDKvpjfbWOv5jZjcBxwGDgAGAjsDqUc4ektQB9Mg8NAp4HLgOeA24BXgcmAkvDi60MM/sV8EQg8mdgOjAfOBA4PWP+IDALOAz4LV6B9gTuBuYUFPFz3IE6gbdiuAV+XwHuAD4usYvRcT4wGzgReBa4Ffgj8HVc08Oh0WjMqwa32PdVR8tywAqOJ4PNoyWaSvXX9NU6/vIjYC/gcWAG8BCwBbgOeCFw/UyPdBdwEDBB0u0p0jeHDG8AflildDMbB1wN3A9cLmlz5n6/1O/RwEXAG8AJktaE67viH+5iM3tE0twckV3Av/CW5qkq3ELeHXjLuRaYC0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pLyGoA4vmnKLRUUteSibZGjyXdrhq7UgabWZrQA6zeyAdI+UzKkPN7PsQu0+wHeAT4B/VChnMR63H5XNKyAZGFepGBcCu+KLtE3wP+DegmNZsFkSzpPworYOM7sGd7zleOtd5Hh1eDXiFosILdnndsfDv26cfx7q6G+nrzbBl0Lavb1HkvSamS3Cu6wrgdtTDxi+ujtT0va5/TCf3w94Lb1mEWrrPHwxbyL+EZJnhgPfxVvShanr+0r6KM3SzDqBm/DWdVp9vRAGsGPz7pnZdfhA9/70VpQ6OsK9KfjWlefxAWlhCFSHVxNusYjRkoPz8QmivxRNMtT8LtG+WgdmNhh4V9KHmet9gOvxCZ9nJH2Q3dlwBfAMcJv5/q2X8e0hw/Bu8mcZ+8XAofi09arMvSvxl3CzmY3AW5fDgVF4CzU2Q/BxM9uIhw7rgSPxPV4bgXMkvZ0jdFTID3asRQ0xsznh9xpJhTsDKiJKh5ldgjteN/A3YEJOuLJK0pzsxc+B2ygi3lcbtCRhXeFOhgaI9dU6/nI2MNXMluA9+1rgi/iuiIHAO8A4yGwRCjX9OHZsBDwb3wg4g8hNq5K6zOzb+LTmSHw69iNgHjBV0nOZR/6Ah3Fj8Lj+LfwDTJXUVVBMJz4pkcZAdqw9rabFFpudpCNZC9sFnyrNw18p3j+4M7l1Eve+amsJi6unUDDJ0BQ1fbWTOP1PAF/FdRyLT6dvwCvqA8BtSQ/d0fs3il70ojn+D6JvS7PkViatAAAAAElFTkSuQmCC\n",
"text/latex": [
"$\\displaystyle 0.691462461274013$"
],
"text/plain": [
"0.6914624612740131"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cumul = lambda w: norm.cdf(w) # define function \n",
"cumul(w)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To find the percentage chance we recall that the cumulative value is that from $-\\infty\\to x$ (in this example $-\\infty\\to 0.5$) but that the remaining probability of that to the right of $x=1/2$ which is $(1-0.691)$. However the value we want is that in the middle of the curve, excluding both sides of the distribution, and is therefore $100(1-2(1- 0.691))=38.3$%, as in table 1. Using python this is "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMMAAAAQCAYAAACr1csrAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAAIC0lEQVR4nO2ae7BXVRXHPxdR1KuSQUoP80FRWBmYYVQiN5SKqxQ9JqeBzBkwRxkgRSUaWnxrjEsFCT4KsAFFp8YMSYIIREZCTWaURh1IGeFqWhBC4JVHyKM/1j6xOff8fr9zzu/2310zv9m/s8/aa63vOWvttfc6u+HIkSN0Uid1EnSNLyRNBy4C+gA9gX3AK8Bi4E4z25EWIKkZGA+cD/QA/gk8A8w0s6dqGSCpBzACaAY+BrwXOAA8D8wH5pvZ4YxxDcDo8PsI0ABsBO4B5sZjyurI0DkSWBgux5jZPWVtKmNXHc+qFTi7AqxtZtarXuwRXyF/kPQ+4IfAFyL+xYDM7N8p3rreo6QhwFhgIHA6sCOMnWVmy7qk+L8LNAIrgVnAA8BBYCrwnKSzUsKnA38ALgSWhzHPAl8CnggPsBZ9HZgHXAw8DdwO/A74KO5EDwYnS9P9wFzgHODXgfdk4BfAgg7SEWM9C7gTeKsKWxGbythVD47dgDJ+P6uCB8iNvbA/SOqNB8o1wDrg58BmPJieCs4fU2n8kn4CPIpP9o8AM4ClwLuAwZDKDMBpZrY/Q9BtwGTge8D1oa8XMBHYBlxgZv+K+JuAx/CIvz/LuIheAoYDS1Oz4GT8AX0V+EoAndwbAXwT2AIMMLM3Qv8JgW+UpMVmtqisjhT+Bnzm2QEsCrjTPEVtKmNXPTh2mdnULHzVKA/2wFfGH+4GzgDGmdkdEf9MfGK+Dbgu4i+FX9IY4GbgXuBaMzuQun88wDGZISsQAj0Y2g9GfWeH8U/HwIO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IFYHr4xTJOxKteb5jZlpI6TsHXqgD7pfTECsA8SfPwzeWEemwqYFdp/gqULHsbo75S2CnuDy+G233S/IGSymXmnqIA/kTPrgr3kw97J+UKhkDvCe2h0HYLbaXyadLfrpSVRWHz1QL8Fbg8Lk8WpKuAE/CPXmV1/Af4VYV7F+IvdC3+oPMsIyraVNCuUvxVKKnUxJNVWexF/SEJmqGSuqS+G5wKfAbYC/wlLagg/lX4XuH8tJ5AyYZ6y/+CQVIf/NP8MRsaSV2AH+EbkSejT+R/xuvm10qaY2avR2O+GMDsB55MyesNHA+8nNR3JU3BP8g8g2/Ua6Z7SaeZ2Zupvn7AT/Fob0ndy60jbBhHV9A7FXeIe639cYxCNhW1qyR/X+BVM9uT6j8HX9dD9CGsLHYK+oOZvSxpBb4EvwG4I5IlPFvNybC7EP6wqlmCV7TG49kkkTUU3+PtApbHmWEYME3SWvwr6g7gTOBSvBy4Fa8QJPQQXje+DNgo6eHA0xdPmQ3AJGt/nmkV/oHmXKBV0tUB3CH8gY7LSM2tZrYg1bdS0j48TbYFvc34eaorzewfEeiyOopSbpvK2FUSxzfwtfoa/JxZG17ubAZOBJaR40hGDirjD9fjwTFbfm5oI37UoglfHn0/VlDHe7wBD+KZ8rNT63H/+3KQNdrMdsfB8CjwAbyU2h8vae0JRi0EZsdRaGaHJQ0Liq7C14MnAzvxBzzbzFZUfHRHKanLH4eXcrPocdqf7Xko6B0JnIRv0OYC08zstQ7SUZSK2FTGrjI4VuM1/f747NyIz4Rr8fe60MzqPrpcxh9CdriIowf1huEH9WaRcVCPku/RzF6T9Am8XDwcLxi8CSzB3806gIbOI9yd1ElO/wX6vObKh/K9RQAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle 38.2924922548026$"
],
"text/plain": [
"38.292492254802625"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"100*(1-2*(1 - cumul(w)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Working the other way round, i.e. starting with the area and finding the $x$ value we use the quantile function which is called .ppf() and putting in the value from the cdf it returns the original value, $0.5$ in this case."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANIAAAAQCAYAAABjuSH9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAAG8UlEQVR4nO2be7BWVRnGf4fxUnkhA5HuehhJsLFjGUimYhmUqEnRTNPgVDNgjToiN6WLPT3NmFIDhlnNoE14YbRSJEvHFGIyL+VMnhltIKVAzC4q2GlIIC/QH+/asNlnf+fb3z54+P44z8w36+y117PeZ6+19lrvetc+Hbt27WIQgxhE/3BAMcP2O4BvAR8HhgH/BFYClvTvuoZsTwduTpczJd1QuN8BzEi/44EOYB1wA7BU0s6SOl93TrvqqstJvI8CFwMTgCOALcATwBJJ9xTKLgROAkYDw4HtwCZiTFwnaUsDG1OAWcBY9oyjPwKLJT1SUn4acDrQBbwPOAxYLml6g/pb1tWqjQK3zzYbUig8Kj3sF4FHgWuADalBHrE9rJnBBiLeCVwH/LePYrcAS4GjgVuJwfAm4EfAsv3IaVddtTi2vwOsIgbhXcAi4G7gSGBiCWU2cAhwP7AEWA68CnwTeDz1bdHGQuBXwPuBexPvMeCTwENpUi3i68RA7QL+3uB5+6Wrho3seZq2WXFF+iEwArhE0vdzFS1Owq8EvlxVQOJ2AD8h3uAVwLySMlOBzwEbgXGSNqf8g4A7gPNtr5S0YiA57aqrH5yZwHzgRuACSS8X+uHAYt8Ah0vaUcy0fSXwVeArwIW5/JFEHz8HnCDp+dy9M4DfEB7PLYUqZwPPAn8hVo01JVpq66ppo3KbDclljAImAU8DPyjUJ+AlonMOaWa8gEuAjxCr3EsNykxN6aJsQAAk0Veky4v3A6dddbXMsX0wMRE+Q8mASNxXSvJ6DdaE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NFfX4UWVtruA7xJvfq8ozEBw2lVXqxxJm4BfEvumWQXOJGKv1UNs1rP80bZ7ufq2h6SDzxHAw9r707HfpfQC228v8D5BTMg7gIeL9VZFTV0to5U2KwYbLiQe8FrHt0XrgPHEGdNTwNcK5VcTB3DHEAe5/cH9trcDfyL8+zHAFOIbqnMk/WM/cdpVVx3ORYRLtdjxLVw30XfnEbP3DEn5qO1ZwFW2HyRWqi3AUcRXAZ1EEGFmwcbtxDnRmcA623emcmMIt68DWKDCt3C2z0s6YM8Z2QTby9LfmyVlX8XU0dWqjQyV2myv5SqtSicR32mNB+YS8f8lwMnFh9/HuJ0ILU4H5hAhxqXAWEm/3Y+cdtXVMkfSs8AHiEjascQsO5GYdU+RdEeBsopwwY8kwtnzgU8DLxJeyvGS1hZs7CQG+mxgLbEfmksc5N8DTJa0pORZutgTMJmc8jpzedP6o6uGjex5KrVZx+C/UQxiEP3H/wGHzfL1IV54cQAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle 0.499999996381316$"
],
"text/plain": [
"0.49999999638131626"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"qtile = lambda w: norm.ppf(w )\n",
"\n",
"qtile(0.69146246 )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In figure 4 the areas $\\pm 1.96\\sigma$ are shaded. Calculating shows that the area from $-\\infty \\to 1.96\\sigma = 0.975$ Thus $0.025$ is left and is the $2.5$% shown as shaded on the right of the figure. Accounting for both extreme regions gives the middle area as $1 - 2(1-0.975) = 0.95$, and is the chance shown in table 1. If the distribution is not normal, for instance the $t$ or $\\chi^2$ distribution a similar calculation applies but, naturally, produces different percentages.\n",
"\n",
"The general form for a $(100 -\\alpha)$% confidence limit when the population standard deviation $\\sigma$ is known is\n",
"\n",
"$$\\displaystyle \\langle x \\rangle\\pm Z_{\\alpha/2}\\frac{\\sigma}{\\sqrt{n}}\\qquad\\tag{10}$$\n",
"\n",
"and when $\\sigma$ is unknown, the sample standard deviation is used\n",
"\n",
"$$\\displaystyle \\langle x \\rangle\\pm Z_{\\alpha/2}\\frac{s}{\\sqrt{n}}\\qquad\\tag{11}$$\n",
"\n",
"The term $Z_{\\alpha/2}$ is the percentage point of the standard normal distribution, i.e. the '% chance' in table 1.\n",
"\n",
"### **(i) Estimating the K$^+$ content of glass**\n",
"Two hundred samples taken at random were obtained for the K$^+$ content of the glass used to make Pyrex flasks. The mean value was found to be $136.48\\;\\mathrm{\\mu g}$ with a sample standard deviation of $25.31\\;\\mathrm{\\mu g}$. The calculation of $95$% and $99$% confidence limits about the mean mass follows directly from equation 11;\n",
"\n",
"$$\\displaystyle 95\\text{ % limits : } 136.48 \\pm 1.96\\cdot 25.31/\\sqrt{200} = 136.48 \\pm 3.51 \\;\\mathrm{\\mu g}$$\n",
"\n",
"which would normally be rounded to $136.5 \\pm 3.5$, or to $137 \\pm 4\\;\\mathrm{\\mu g}$ if one were being cautious. This result means that $95$% of the samples taken at random should fall between $133 \\to 141\\;\\mathrm{\\mu g}$ and by chance alone, it could be expected that $5$% of results would be outside these limits. The $9$9% confidence limits produce $136.5 \\pm 4.62\\;\\mathrm{\\mu g}$, which will round up to $137 \\pm 5\\;\\mathrm{\\mu g}$.\n",
"\n",
"$$\\displaystyle \\begin{array}{l|l l}\n",
"\\hline\n",
"\\text{% confidence level} & &Z_{\\alpha/2} \\\\\n",
"\\hline\n",
"90 & &1.28\\\\\n",
"95 & &1.96\\\\\n",
"99 & &2.58\\\\\n",
"\\hline \\end{array}$$\n",
"\n",
"## 3.2 Small sample confidence limits: Student’s $t$ distribution\n",
"\n",
"When the number of samples is small, s may not be a very good estimate of $\\sigma$ and, in this case, Student's '$t$' test is needed. The distribution is similar in shape to the normal distribution, but is wider in the wings. It is characterized by one parameter $v = n - 1$ where $n$ is the number of samples being averaged, and $v$ is called its 'degrees of freedom'. When the sample size increases, the $t$ distribution approaches the normal one. Using a similar argument to that for the normal distribution, the $t$ distribution produces confidence limits,\n",
"\n",
"$$\\displaystyle \\langle x \\rangle\\pm t_{\\alpha/2}\\frac{s}{\\sqrt{n}}\\qquad\\tag{12}$$\n",
"\n",
"where $t_{\\alpha/2}$ is obtained by integrating the distribution, just as was done for the normal distribution. Only a few values are used regularly, some of which are listed in Table 3. (Notice that in the table that $v$ is one less than the number of data points.)\n",
"\n",
"## (i) Student's $t$ distribution\n",
"$$\\text{Student's } t, \\text{two tailed confidence}$$\n",
"$$\\displaystyle \\begin{array}{cccc|c|ccc}\n",
"\\hline\n",
"& 90\\text{ %} & 95\\text{ %} & 99\\text{ %}& & & 90\\text{ %} & 95\\text{ %} & 99\\text{ %}\\\\\n",
"\\alpha/2\\to & 0.05 & 0.025 & 0.005& & & 0.05 & 0.025 & 0.005\\\\\n",
"\\hline\n",
"v & & &\\\\\n",
"1 & 6.314 & 12.706 & 63.657 & & 11 & 1.796 & 2.201 & 3.106\\\\\n",
"2 & 2.920 & 4.303 & 9.925 & & 12 & 1.782 & 2.179 & 3.055\\\\\n",
"3 & 2.353 & 3.182 & 5.841 & & 13 & 1.771 & 2.160 & 3.012\\\\\n",
"4 & 2.132 & 2.776 & 4.604 & & 14 & 1.761 & 2.145 & 2.977\\\\\n",
"5 & 2.015 & 2.571 & 4.032 & & 15 & 1.753 & 2.131 & 2.947\\\\\n",
"6 & 1.943 & 2.447 & 3.707 & & 20 & 1.725 & 2.086 & 2.845\\\\\n",
"7 & 1.895 & 2.365 & 3.499 & & 30 & 1.697 & 2.042 & 2.750\\\\\n",
"8 & 1.860 & 2.306 & 3.355 & & 40 & 1.684 & 2.021 & 2.704\\\\\n",
"9 & 1.833 & 2.262 & 3.250 & & 50 & 1.676 & 2.009 & 2.678\\\\\n",
"10 & 1.812 & 2.228 & 3.169& & \\infty& 1.645 & 1.960 & 2.576\\\\\n",
"\\hline \n",
" \\end{array}\\\\v =\\infty \\text{ is normal distribution}$$\n",
"\n",
"![Drawing](analysis-fig5.png)\n",
"\n",
"Figure 5. Student's $t$ distribution is wider in the wings than the normal distribution, which it approaches when $v$ is larger that $\\approx 15$\n",
"___________\n",
"\n",
"### **(ii) Response times**\n",
"Some typical response times of a certain commercial mass spectrometry service are\n",
"\n",
"$$\\displaystyle 8.21, \\; 25.15,\\; 11.20,\\; 18.06,\\; 22.55,\\; 16.49 \\text{ days} $$\n",
"\n",
"and $95$% confidence limits need to be placed on the population mean $\\mu$. To calculate how many days on average it will be necessary to wait to be $95$% sure of obtaining the results of an analysis, use equation 12 with the $t$ value taken from Table 3. As $\\sigma$ (population mean) is unknown and the sample is small then\n",
"\n",
"$$\\displaystyle \\langle x\\rangle \\pm t_{0.025}\\frac{s}{\\sqrt{n}}\\qquad\\tag{13}$$\n",
"\n",
"The sample size $n = 6$ so there are $v = n - 1 = 5$ degrees of freedom, and from $t$ distribution table $t_{0.025} = 2.571$ for $95$% confidence. The $0.025$ is used because this is the two sided value, the limit being $2.5$% to the far right and far left of the $t$-distribution, in the same way as that shown for the normal distribution in figure 4. The sample mean $\\langle x\\rangle = 16.94$ days and the sample standard deviation $s = 6.47$ days. Therefore, a $95$% confidence interval for $\\mu$ is given by\n",
"\n",
"$$\\displaystyle 16.94 \\pm 2.571\\cdot6.47/\\sqrt{6} = 16.94 \\pm 6.79 \\text{ days}$$\n",
"\n",
"Rounding the answers gives $17 \\pm 7$ which is $10 \\to 24$ days and is a very wide variation. It would certainly be worth considering changing your supplier!\n",
"\n",
"## 3.3 Critical values from cumulative Student’ s *t* distribution\n",
"\n",
"To use Python to find the $t$ values for $n$ points with $\\alpha/2 = 0.025$ we follow the method used for the normal distribution but now with the $t$ distribution. This means loading the library as 'from scipy.stats import t,norm' as shown at the top of this page. Looking at Table 3, with $v=5$ and at $95$% the value is $2.571$. Using the t.cdf function produces $0.975$ which is the value fro $-\\infty\\to 2.571$ and so the two tailed value is $0.95$ or $95$%."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANIAAAAQCAYAAAB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S7ofwoo3FE8C7Kq4xKLRx1bBZMhKS59vws4v2OvnKcjwH6R/zFZAk+emNp1dojyMbSX987nOg+aqFPL2UlaVLeixoY/8NY1nXmkDzaLhf1cGEpL/jCWQf4Op4bXwXWSipo4ZuZq1mdlrWoZyZvSujrw34Lr6TTc8R4HK8CLG0RgKImfXLOicwsz54jA2dD/AqyVgFZjYNl+8JfMffWote0vPAg3jeeE0013A819xG56ran0I70cxOiJ75JG5Mu4A/N5OvKnopK0sD9FjXxiTtlDQ+68K/7gC4O/T9Mi42fCUwe7v5t1Xr8U9K2nE3+bWIfjl+mHYyfjiWxsNmthMPH7YD/fDvvHYCl0r6Z46QicvNPWUO+DweN68Eng9rtIY1Dsfj3qzPUUrJaGYjgZHhNjkfG2xmC8LfWyVdn6K/Aj+F340byOSMsGCzpAVR39V46DIrnNeswX/XkWGu8ZLSVap78c92LgLWm9lv8AS9Hx4qtQA3SXq1yXxV0UspWQLK2moaRW2sMDq5xfCmn4t/CzcQr7C04knpoEiQergXL5WOAabgJdO5QP+M8x2g4+DrYxQrMqzAv81qxT9HmoJ/wvMoXti4JOckvqyMbewrlowIfX1TfaMj+uTs7FDgWvykPb7GZfC1BfgwvmufgnuAobhHOE/SfRH9HuBT+Ocw6/AcYioePi0BRkia02y+qKCXCrJUttWSNlYYLd3/RtGNbnQd/wdC1b0Vd5/UuQAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle 0.975012682658074$"
],
"text/plain": [
"0.9750126826580743"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w = 2.571\n",
"v = 5\n",
"cumult = lambda w,v: t.cdf(w,v) # define function \n",
"cumult(w,v)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the 95% confidence level has $\\alpha/2 = 0.025$ which is $5/2$% because the table is for 'two-tailed' values on the distribution and $\\alpha = 5$. The $t$ value at $95$% and for seven points (or six degrees of freedom) is written as $t_{0.025,6}$. Figure 4 shows two-tailed values on the normal distribution.\n",
"\n",
"The quantiles, the values in Table 3, are found using the $\\mathtt{ppf()}$ function, i.e inverting the cdf and give"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMQAAAAQCAYAAABJCdBSAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAAH0ElEQVR4nO2aa9BWVRXHf+jroIOkDl6Ybl4oCk3FqRCiuEjhBTJIrJkGBWeEHHWA5JJR9mfVmNAkgtKF1AE1v3STRJFQZCKyYkZfRpvXglBEnMSAaEB8M4E+rH3icJ59nvdcHr+9/5ln9nPO3mv/1z577ctae/c4fPgw3ehGNxxtyR8z6wOMB8YA5wPvA94GXgCWAcskHSpasZltA87Myd4pqW8oNznU3wyHJB0b4Xg/8B3gMqAP8A9gBWCS/lVFnwjHGGA6cG6K41lgoaQ/RspPAIYDA4ELgd7Aw5Im5jWuAscC4BNAf+BU4C3gldD2JZJ2N+EaBdwMDAFOAXbjfbxY0qo6MlXaHuGaCDwUHqdIui+TP5mK9lKEpy1V5mrgx3hnrAO2A2cAXwTuAy43s6sllVlS/g0sirzfn/q/CbAc+c8AlwBPZDPMrB/wDHA68Bvgr8Ag3LAuM7OhEcMook+aYwEwBzeAFcAu4EPAF4CrzOxaST/LiH0LN4b9wA7gozltq8PxNeA54EngDaAXMBiYB0w1s8GSXo1wfR+YHfR6NHCdBnwcGAE0DIiSMqXaHuH6ALAkyJ+YU2wTFeylKE96QGwGrgQeT68EZjYX2AhchQ+OXzUjy2CvpHnNCkjahDcypngyO/40kv0jfDBMk3RPSmYhbjC3AzeU1SdVT19gFrATuEDSG6m8kcDT+OoUM9YdwN/x2XLdu8DxHkmdkfpuB+YC3wBuzORNwQ37AWCqpLcz+cdF6isrU7jtEa4e+My/G/g1/l0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YmHHSk++1N0c0OcQ8IfWuikwZnMiR/us0ix4t3Gtm9+JO8Iycerqyl1I8DStEcPLuwmO9I1s8GMAjPxDpYDM7Ht+aHQTub1JHYkCjzeyoNphZb2AocAD4Uw19eoa0IeyZed8QjiyBd4PjvSFNG8da3A84N/u9AhKH+eWaMmXwH7yPY7/2UGZDeI5ucwraSymeo1YIM7sNPwh6FnfOmm6TwnnAccDWdEw6hLe2S3ozU/4sfJ8MjYdN4M7kKcBjTZwjJG01szX4FuEm4J5UtuGz/dKEv6I+v8evK0w1s6WSXkvJXY4Puk78tLwqSnOYWX/8qslRAYVgtN/FneFn0ldXwsqxEo9cTccnvERuNHApvhKsriNTBsGxvT6WZ2bz8FXxgezVjQy6tJeyPOm7TJPwwXAQ76hpkeVlm6Tlqee1+OHS2fghWYIv43vf9fgdm314KHEMcDy+1/tBRMdk+cs9aUzhRtxQ7ja/a/MicDF+RrEZ+GZNfX4JPAV8FnjRzB7BHd4B+FanB3Br9nqImY0DxoXH5H7UEDNbHv7vkpScjlbhuAK4w8w24LPzbvyKzXDgnCA/JfK9bsI7f2E4U2jH+20c3ufXZwdZWZmSbW8FythLIaSXwrNDeiwexlPkN7lgveuAx3Cj+wpwC95hG4BJwNjINYABeOiwmTP9f0jaisfel+MDYWbgWwwMzhhRaX3Cgd8V+HWEDnwvPxPfYq0CLpW0OKLawFDnJHwWBTfU5N2EmhxP4cv7aXi4djZ+rWYPvjqeJ6kj8r124PePluA+1nT85sFKYKikhis5FWQKt70uytpLUfTovv7djW4cwf8AO1E0xff4cnIAAAAASUVORK5CYII=\n",
"text/latex": [
"$\\displaystyle 2.57058183661474$"
],
"text/plain": [
"2.5705818366147395"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = 0.975\n",
"n = 5\n",
"quant = lambda x,n: t.ppf(x, n ) # prec quantile for T distribution\n",
"quant(x,n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"which is the value in the table under $95$% and $v=5$.\n",
"\n",
"## 3.4 Hypothesis testing\n",
"\n",
"Suppose that a micro-analytical laboratory has to be certified and one of the tests it has to perform is to determine the ratio of $^{12}$C / $^{14}$N on an unknown compound. The examiners know that the ratio should be $50$ and a standard deviation of $1/2$ is acceptable. The laboratory produces the following set of data,\n",
"\n",
"$$\\displaystyle 49.8,\\;50.15,\\; 50.6,\\; 49.9,\\; 50.7,\\; 50.1,\\; 50.9,\\; 49.6 $$\n",
"\n",
"and have calculated that they fall within the allowed error bounds. Do you agree?\n",
"\n",
"To solve this problem, a slightly different approach has to be taken and this involves using a common approach to testing data by forming hypotheses. This means testing whether or not there is confidence in a given mean value. Some criterion or test statistic is computed and used to make a decision. When using these tests, it is always assumed that the underlying parent distribution is normal and that the samples are independent of one another. Two related statistics are needed. When the population standard deviation $\\sigma$ is known (it is $1/2$ in the problem), the following statistic can be used;\n",
"\n",
"$$\\displaystyle z_0=\\frac{\\langle x\\rangle -\\mu_0}{\\sigma/\\sqrt{n}}\\qquad\\tag{14}$$\n",
"\n",
"This statistic should follow a normal distribution, and if the experimental mean is going to converge on $\\mu_0$, if sufficient samples could be taken, then it would be expected that $z_0$ is 'close' to zero because $\\langle x\\rangle\\to \\mu_0$. The problem is to find critical values with which to test, with a certain confidence, how approximate the statement $\\langle x\\rangle\\approx \\mu_0$ actually is. For example, if $z_0$ is greater than $\\pm 1.96$ then with $95$% certainty $\\langle x\\rangle\\ne \\mu_0$; however, we would still expect to observe $\\langle x\\rangle\\approx \\mu_0$ on $5$% of occasions. Thus, large values of $z_0$ means that the experimental mean is probably not the same as the population mean. The data produces\n",
"\n",
"$$\\displaystyle \\langle x\\rangle=50.22,\\text{ and as } \\sigma =1/2\\text{ and }\\mu_0 =50,\\text{ then } z_0 =1.24$$\n",
"\n",
"This is less than $1.96$ which is the value needed for $95$% acceptance with a normal distribution, so the conclusion would be that the lab had produced an acceptable set of data. However, the number of samples is small and this last calculation assumes that many measurements have been taken. The statistic would be more discriminating if a second test were used based on the $t$ distribution. In this case, the sample standard deviation $s$ is used rather than $\\sigma$, making the statistic subtly different\n",
"\n",
"$$\\displaystyle t_0=\\frac{\\langle x\\rangle -\\mu_0}{s/\\sqrt{n}}\\qquad\\tag{15}$$\n",
"\n",
"Calculating again with $s = 0.466$ gives $t_0 = 1.33$ and from the $t$ distribution, with seven degrees of freedom at the $95$% level, $t_{025,7} = 2.365$. As $t_0$ is less than this and $z_0$ is less than $1.96$, although this is a less critical test, the conclusion reached is that with $95$% confidence the data is consistent with a population mean of $50$ and standard deviation of $1/2$ and the lab is up to standard.\n",
"\n",
"## 3.5 Comparison of two means\n",
"\n",
"When a mean value has been obtained, to eliminate systematic errors it is necessary to compare this with another determination, perhaps done on another day, or to compare with a result from different apparatus or with a literature result. The two means are only samples from the true distribution and should not be very different from one another as they are supposedly measuring the same thing. The difference in means should therefore be normally distributed about the true difference $\\mu_1 - \\mu_2$, which in turn, should be zero. The simplest test is to use the propagation of errors formula, see Section 4, to compare the difference in the means $\\langle x\\rangle_1-\\langle x\\rangle_2$ with the difference in standard deviation,\n",
"\n",
"$$\\displaystyle s_{1,2}=\\sqrt{s_1^2+s_2^2}$$\n",
"\n",
"If the difference is less than the standard deviation, the two results are probably acceptable.\n",
"\n",
"When there are only a few measurements, two for example, it is natural to try to use the $t$ distribution to quantify their difference which can be done in the following manner after first assuming that the population variances are not different, i.e. $\\sigma_1^2 = \\sigma_2^2 = \\sigma^2$, which means that the data is measuring the same thing. The pooled variance is\n",
"\n",
"$$\\displaystyle s_p^2=\\frac{(n_1-1)s_1^2+(n_2-1)s_2^2}{(n_1-1)+(n_2-1)}$$\n",
"\n",
"where data set 1 with mean $\\langle x \\rangle_1$ is the average of $n_1$ measurements and similarly for set 2. This variance has $n_1 + n_2 - 2$ degrees of freedom. The $t$ test statistic is\n",
"\n",
"$$\\displaystyle t_0= \\frac{\\langle x\\rangle_1+\\langle x\\rangle_2}{s_p}\\sqrt{\\frac{n_1n_2}{n_1+n_2}} \\qquad\\tag{16}$$\n",
"\n",
"which is expected to follow a $t$ distribution with $n_1 + n_2 - 2$ degrees of freedom. If this $t_0$ exceeds the critical value set by the percentage points of the $t$ distribution, then it is clear that the means are not the same. Confidence intervals, at $95$%, for the difference between population means $(\\mu_1 - \\mu_2)$ may be obtained using\n",
"\n",
"$$\\displaystyle \\langle x\\rangle_1-\\langle x\\rangle_2\\pm t_{0.025,S_p}\\sqrt{\\frac{n_1+n_2}{n_1n_2}}\\qquad\\tag{17}$$\n",
"\n",
"### **(i) Comparing columns yields in chromatography**\n",
"The yields of two nominally identical columns used for chromatographic separation have been measured. There are nine and eight experiments on each column under identical experimental conditions and the subsequent yield (mg) for each is as follows:\n",
"\n",
" $$\\displaystyle \\begin{array}\\\\\n",
" \\hline\n",
" \\text{Column 1:} & 17.5& 21.1 & 26.6 &18.1 &23.2 &18.4 &16.5& 21.9& 26.8 \\\\\n",
" \\text{Column 2:}& 13.7& 12.3 &16.3 &15.9 &21.0 &21.9 &18.2 &14.1 &-\\\\\n",
" \\hline \\end{array}$$\n",
"\n",
"To determine if there is evidence of a 'significant' difference in their yield (at the $95$% level) the mean and standard deviation for each sample are calculated, then $t_0$ using equation 16, and this compared with the value from the $t$ distribution. The data produces\n",
"\n",
"$$\\displaystyle \\langle x\\rangle_1 = 21.1,\\quad s_i= 3.84,\\qquad \\langle x\\rangle_2 = 16.67,\\quad s_i= 3.46,\\qquad \n",
"S_p=3.67,\\quad t_0=2.49$$\n",
"\n",
"The $t$ distribution at the $95$% level (two-tailed distribution at $0.025$, with $t = n_1 + n_2 - 2 = 15$ degrees of freedom) has a value $2.13$ (see Table 3) and as this is _smaller_ than the $t_0$ calculated from the data, we conclude that the two sets of data are different. The confidence limits (equation 17) are\n",
"\n",
"$$\\displaystyle \\langle x\\rangle_1-\\langle x\\rangle_2\\pm 3.8$$\n",
"\n",
"making the lower bound $4.47 - 3.8 = 0.65$ mg and the upper bound $+8.2$ mg. Thus, the difference in mean value at the $95$% level is $0.65 \\le \\langle x\\rangle_1-\\langle x\\rangle_2 \\ge 8.2$ mg which means that it is possible to be $95$% confident that column 1 produces between $0.65 \\to 8.2$ mg more on average that column 2.\n",
"\n",
"### **(ii) Comparing fluorescence yields**\n",
"When repeated measurements are made on the same instrument they are likely to be correlated and therefore not independent of one another. In this example, the difference in the experimental values is examined using the $t$ test rather than comparing the two means.\n",
"\n",
"Consider measuring fluorescence from the dye thionine, which is known to intercalate into calf thymus DNA. One sample is treated with protein and measured to see if this has an effect on the amount of fluorescence observed. The data (in arbitrary units) for the fluorescence intensity was as follows:\n",
"\n",
"$$\\displaystyle\\begin {array}{lclllllll}\\\\\n",
"\\hline\n",
"\\text{DNA sample}& 1& 2& 3& 4& 5& 6& 7\\\\\n",
"\\text{Treated} & 80.1 &64.2 &75.4 &51.7 &71.8 &85.9 &64.7 \\\\\n",
"\\text{Control} &88.6 &71.3& 79.8& 60.3 &70.2& 92.7& 65.0\\\\\n",
"\\hline\\end{array}$$\n",
"\n",
"The mean value of the _difference_ is $-4.87$ and the sample standard deviation $4.06$. The $t_0$ statistic (equation 15) is $-3.18$ with a population mean $\\mu_0 = 0$. From the $t$ distribution table with six degrees of freedom $t_{0.025,6} = 2.45$ and as $|-3.18| \\gt 2.45$ the protein does have an effect at the $95$% level and the fluorescence intensity is different between the two sets of measurements.\n",
"\n",
"## 3.6 Chebychev’ s rule, Chauvenet's criterion and outliers\n",
"\n",
"Sometimes data points seem to be too far from the trend exhibited by all the others and there is then a temptation to remove such points. This must always be resisted. One famous consequence of removing data led to the hole in the Antarctic ozone layer being missed. As the New Scientist (31 March 1988) put it, 'So unexpected was the hole, that for several years computers analyzing ozone data had systematically thrown out the readings that should have pointed to its growth.' However, it should be remembered that by the random statistical nature of noise adding to any measurement that deviations, often large ones, are to be expected. Note also that the process of smoothing data is akin to removing outliers and should be avoided, and in some settings, clinical ones for example, no data should ever be disregarded.\n",
"\n",
"### **(i) Chebychev**\n",
"When outlying points are found in data, the obvious thing is to check that no numerical or transcriptional error has occurred, then go to the instrument used and check that a simple error has not been made, such as using the wrong solvent or a mistake in the concentration, or amplifier setting and so forth. The instrument could be checked out with a known reference but if everything turns out satisfactorily then it must be assumed that the data point is the result of random chance. Highly unlikely but not impossible. If the experiment cannot be repeated and the data still has to be dealt with, then the Chebychev rule may be useful. \n",
"\n",
"This gives a number to the probability that a random variable or the absolute value from a mean $| x - \\langle x \\rangle |$ exceeds a given number. Suppose that this number is $k\\sigma$ where $k \\gt 1$ is an integer and $\\sigma$ is the standard deviation, then the condition is\n",
"\n",
"$$\\displaystyle prob(| x - \\langle x \\rangle | \\ge k\\sigma) \\le \\frac{1}{k^2}$$\n",
"\n",
"This means that the chance that $| x - \\langle x \\rangle |$ is numerically greater than $k\\sigma$, is less than $1/k^2$, or, equivalently, that no more that $1/k^2$ data points should be more than $k$ standard deviations from the mean or, which is the same, that $1 - 1/k^2$ are within $k$ standard deviations. The value of $k \\gt 1$ is for us to choose. The data described above in Section 3.4 for the $^{12}$C / $^{14}$N ratio has a mean of $50.22$ and a (sample) standard deviation of $s = 0.466$. If $k = 2$ is chosen then $1 - 1/4 = 0.75$ or $75$% of the values should fall in the range $50.22 \\pm 2 \\cdot 0.466$. If $k = 3$, then $89$% of values fall in the range $50.22 \\pm 3 \\cdot 0.466$ and for any points that do not fall in this range there is a sound reason for ignoring them.\n",
"\n",
"### **(ii) Chauvenet**\n",
"An alternative method of removing outliers has been given by Chauvenet and this considers both the number of data points and their value. We use this method to _reject a data point_ if its deviation from the mean have a probability of occurring that is _less than_ $1/(2n)$ for $n$ data points. This method does not work well on small datasets.\n",
"\n",
"In the set of data $89,\\;120,\\;94,\\;110,\\;105,\\;108,\\;85,\\;83,\\;101,\\;95$ the largest value $120$ may be an outlier. This point is $21$ from the mean $\\langle x\\rangle = 99$ and we check that the probability from $\\langle x\\rangle -21 \\to \\langle x\\rangle +21$ is less that $1/2n$ which is $1/20$ as there are 10 points.\n",
"\n",
"This value is obtained from the integral of the normal distribution, with limits $78$ and $120$ the probability of observing a value in this range is\n",
"\n",
"$$\\displaystyle 1 - p=\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\int_{78}^{120}e^{-(x-\\langle x\\rangle)^2/(2\\sigma^2)}dx $$\n",
"\n",
"Evaluating this integral produces $0.92$ making $1-p = 0.078$ and as this is less than $1/20$ the data point is retained.\n",
"\n",
"As the integral can be evaluated algebraically and then limits applied we can use this result, which is\n",
"\n",
"$$\\displaystyle p=\\frac{1}{2}\\mathrm{erf}\\left(\\frac{x-\\langle x\\rangle }{\\sqrt{2}\\sigma}\\right)\\Bigg|_a^b $$\n",
"\n",
"where erf is the error function. An example is shown below, and as the $1-p$ is greater than $1/(2n)$ we do not reject the data point. If the value were $130$ this method would indicate that it should be removed."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"limits 78.000 120.000\n",
"mean and std dev 99.000 11.907\n",
"1-p = 0.0778 , 1/(2n) = 0.050\n",
"retain point\n"
]
}
],
"source": [
"# Algorithm: Chauvenet criterion to test for outliers\n",
"\n",
"c = np.array([89,120,94,110,105,108,85,83,101,95]) # data assumed positive\n",
"\n",
"indx = 1 # point to check in the list. index starts at zero\n",
"n = len(c)\n",
"limit= 1/(2*n)\n",
"xbar = np.sum(c)/n\n",
"x0 = c[indx]\n",
"delta= np.abs(x0 - xbar)\n",
"if x0 >= xbar:\n",
" b = xbar + delta\n",
" a = xbar - delta \n",
"else:\n",
" a = xbar - delta\n",
" b = xbar + delta \n",
"print('{:s}{:6.3f} {:6.3f}'.format('limits ', a,b))\n",
"s = 0\n",
"for i in range(n):\n",
" s = s + (c[i] - xbar)**2\n",
"sig = np.sqrt(s/(n-1))\n",
"print('{:s}{:6.3f} {:6.3f}'.format('mean and std dev ',xbar,sig)) \n",
"\n",
"p = 0.5*(erf((b - xbar)/(sig*np.sqrt(2.0) )) - erf((a - xbar)/(sig*np.sqrt(2.0) )) )\n",
"\n",
"print('{:s} {:6.3g} {:s} {:6.3f}'.format('1-p =', 1.0-p, ', 1/(2n) =', 1/(2*n)))\n",
"if 1 - p > 1/(2*n):\n",
" print('retain point')\n",
"else:\n",
" print('remove point')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3.7 Standard deviation in a single measurement\n",
"\n",
"When only a single measurement has been made, as is often the case in an undergraduate laboratory, the question arises as to what standard deviation it should be given. In such laboratories, many other measurements will undoubtedly have been made so the mean and standard deviation for the experiment will be known. However, in the absence of such knowledge we can appeal to the Poisson distribution (see Section 6.4) to determine what value should be given to the standard deviation. It turns out that by calculating the maximum likelihood function that the standard deviation is the square root of the result itself. Thus if the result has a value $k$ then $\\sigma_k =\\sqrt{k}$.\n",
"\n",
"## 3.8 Weighting\n",
"\n",
"In Chapter 1.9.13 the average energy and average length of trans and gauche butane molecules was calculated by weighting the individual values according to the Boltzmann distribution. Experimental measurements are similarly not always of equal precision and this may be inherent in the nature of the observation. When counting photons, for instance, the precision of each measurement is proportional to the number of counts. For example, the intensity of an emission spectrum varies with wavelength; the precision is therefore different at different wavelengths. Alternatively, it may be that one instrument has twice the resolution of another or simply it may be that one experimentalist is better than another; nevertheless, the average has to be taken. \n",
"\n",
"If two measurements of $x$ are made and $x_1$ is twice as precise as $x_2$, then the weighted average is made in the proportions, $\\langle x\\rangle = (2x_1 + x_2)/3$. In the general case, if $w_i$ are the weights, then\n",
"\n",
"$$\\displaystyle \\langle x\\rangle=\\frac{\\sum\\limits_i w_ix_i}{\\sum\\limits_i w_i} \\qquad\\tag{18}$$\n",
"\n",
"This equation means that the contribution of each measurement to the average is in proportion to $w$ unweighted measurements. This formula has been used in several other guises in other chapters to estimate an expectation value, when $w_i$ was called the distribution of $x_i$ rather than a weighting. The weighted standard deviation is\n",
"\n",
"$$\\displaystyle s=\\sqrt{\\frac{\\sum\\limits_iw_i\\left(x_i-\\langle x\\rangle\\right)^2}{\\sum\\limits_iw_i} }$$\n",
"\n",
"For experimental measurements, weighting is optimal if it is the reciprocal of the variance, $w_i=1/\\sigma_i^2$ and $\\sigma_i$ must be determined for each of the $i$ observations. In many cases the $\\sigma$ will be equal to one another, then $\\displaystyle \\langle x \\rangle =\\frac{1}{N}\\sum_ix_i$, which is the unweighted mean of $x$. The variance of the weighted average is\n",
"\n",
"$$\\displaystyle \\sigma^2= \\frac{1}{\\sum_i w_i}=\\frac{1}{\\sum_i/\\sigma_i^2} \\qquad\\tag{19}$$\n",
"\n",
"Weightings ensure that more importance is given to the more precise measurement because the smaller the standard deviation is, the larger is the weighting given to it.\n",
"\n",
"### **(i) Spectral lines**\n",
"Suppose that on one instrument a line in the SO$_2$ infrared spectrum is measured at $550\\;\\mathrm{ cm^{-1}}$ with a standard deviation of $\\sigma = 10\\;\\mathrm{ cm^{-1}}$; another instrument is then used with $\\sigma = 5\\;\\mathrm{ cm^{-1}}$ and produces $555\\;\\mathrm{ cm^{-1}}$. The unweighted average is $552.5\\;\\mathrm{ cm^{-1}}$, while the weighted average of the two measurements is $554\\;\\mathrm{ cm^{-1}}$, which is close to that of the higher resolution instrument as might be anticipated. \n",
"\n",
"If three measurements are made of a rate constant with values $(3.16 \\pm 0.03)\\cdot 10^7, (3.21 \\pm 0.05)\\cdot 10^7$, and $(3.14 \\pm 0.02)\\cdot 10^7\\;\\mathrm{ s^{-1}}$, the errors are then taken to be the standard deviations and equations 18,19 are used. The best combined rate constant is $(3.15_2 \\pm 0.014)\\cdot 10^7\\;\\mathrm{ s^{-1}}$.\n",
"\n",
"In many experiments, the standard deviation can be found by looking at an instrument's specification, where a resolution of a certain number of wavenumbers or millivolts, and so forth, is usually given. In other cases this may have to be estimated from the data itself and this can be difficult to do point by point. However, one case in which the standard deviation is known exactly is in a particle or photon counting experiment because the arrival of photons at the detector is Poisson distributed where $\\sigma^2 = \\mu$ and then $w_i = 1/\\mu_i$ where $\\mu_i$ is the average number of counts in the $i^{th}$ measurement. Fluorimeters often use photon counting to measure fluorescence and phosphorescence spectra, and the standard deviation can then be measure directly from the data.\n",
"\n",
"## 4 Error propagation\n",
"\n",
"In many experimental situations, a measurement does not always produce the final result, which will be obtained from further calculations, and may also involve other experimental measurements. For example, the measured value and its associated error may have to be exponentiated and then multiplied by another quantity with its error.\n",
"\n",
"The formula for error propagation (or combination) can be determined by expanding the required function as a Taylor series about its mean value and substituting the result into the variance equation 3; see Bevington & Robinson (2003) or Barlow (1989) for the proof. If the functional form is written as $y = f (u, v)$, then the variables that have been measured are $u$ and $v$ and their respective standard deviations $\\sigma_u$ and $\\sigma_v$. The variance in the final result $y$ is\n",
"\n",
"$$\\displaystyle \\sigma_y^2=\\left(\\frac{\\partial y}{\\partial u}\\right)_v^2\\sigma_u^2+\\left(\\frac{\\partial y}{\\partial v}\\right)_u^2\\sigma_v^2+2\\left(\\frac{\\partial y}{\\partial u}\\right)_v\\left(\\frac{\\partial y}{\\partial v}\\right)_u\\sigma_{uv}^2$$\n",
"\n",
"where $\\sigma_{uv}^2$ is the covariance between the two variables. This is always assumed to be zero, i.e. the result of one measurement is not influenced by the other; therefore, the result to use is\n",
"\n",
"$$\\displaystyle \\sigma_y^2=\\left(\\frac{\\partial y}{\\partial u}\\right)_v^2\\sigma_u^2+\\left(\\frac{\\partial y}{\\partial v}\\right)_u^2\\sigma_v^2\\qquad\\tag{20}$$\n",
"\n",
"If there are more than two variables, the extra terms are added in the same way;\n",
"\n",
"$$\\displaystyle \\sigma_y^2=\\left(\\frac{\\partial y}{\\partial u}\\right)_{v,w}^2\\sigma_u^2+\\left(\\frac{\\partial y}{\\partial v}\\right)_{u,w}^2\\sigma_v^2+\\left(\\frac{\\partial y}{\\partial w}\\right)_{u,v}^2\\sigma_w^2+\\cdots\\qquad\\tag{21}$$\n",
"\n",
"### **(i) Gas law**\n",
"The gas law states that $p = nRT/V$, and the volume, temperature, and number of moles have been measured, each with their standard deviations. The standard deviation of the pressure is found by taking the partial derivatives of each variable in turn, while holding the others constant and substituting into equation 21. The variables are $n\\equiv u,T\\equiv v,V\\equiv w$,\n",
"\n",
"$$\\displaystyle \\sigma_p^2=\\left(\\frac{\\partial p}{\\partial n}\\right)^2\\sigma_n^2+\\left(\\frac{\\partial p}{\\partial T}\\right)^2\\sigma_T^2+\\left(\\frac{\\partial p}{\\partial V}\\right)^2\\sigma_V^2\\\\= \\left(\\frac{RT}{V}\\right)^2\\sigma_n^2+\\left(\\frac{nR}{V}\\right)^2\\sigma_T^2+\\left(-\\frac{nRT}{V^2}\\right)^2\\sigma_V^2$$\n",
"\n",
"which can be simplified by factoring out $(R/V)^2$. The relative or fractional uncertainty is found by dividing this result by $p^2$ producing, in this case, the simpler result,\n",
"\n",
"$$\\displaystyle \\frac{\\sigma_p^2}{p^2}= \\frac{\\sigma_n^2}{n^2}+\\frac{\\sigma_T^2}{T^2}+\\frac{\\sigma_V^2}{V^2}$$\n",
"\n",
"### **(ii) Vapour pressure**\n",
"The vapour pressure (in torr) of a certain organic liquid has the form $\\ln(p) = mT + c$ and the values of the constants $m$ and $c$ were obtained from a least squares analysis of a plot of log pressure _vs_ $1/T$. The gradient produced $m = -5390 \\pm 33$ K and the intercept $c = 21.89 \\pm 0.099$. To calculate the liquid's normal boiling temperature, i.e. the boiling temperature when $p = 760$ torr or $1$ atm. pressure, the equation must be rearranged to,\n",
"\n",
"$$\\displaystyle T=\\frac{m}{\\ln(760/1)-c}$$\n",
"\n",
"making $T = 353.29$ K. The pressure is written as $760/1$ as a reminder that the log must be dimensionless. Using equation 21, the error in this determination can be calculated with $\\sigma_m = 33,\\; \\sigma_c = 0.099$ and gives\n",
"\n",
"$$\\displaystyle \\sigma_T^2=\\left(\\frac{\\partial T}{\\partial m}\\right)^2\\sigma_m^2+\\left(\\frac{\\partial T}{\\partial c}\\right)^2\\sigma_c^2$$\n",
"\n",
"Completing the differentiations and substituting values gives $\\sigma_T=3.15$ K. The final answer produces a boiling temperature = $353 \\pm 3$ K. The Python/Sympy calculation, which also performs the differentiation, is"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSU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RdK8Qvt6j7A3k+GfbIR7CMOKJKuB72Q5IIyVobUM9puBOxP/rwR2Al9L2HY24ace7Q6xasUAwrndmbKdBfwL+FPCNiV+PtfAlgfqnetqmtP8XbS2Y0GRNK/Qvt5Z9pokG+HDhB2vhon7fCT3+sgimcGe+UwgaS9hxywAbL8A7JXUylBmByH5c278G9uHA28F7kiUOQCcQZixqs6GzaL20HBUDGy/grD1Qro3+xzwPUkvJWyzgJ2pvVBq2fLAqHOF5jW33bTe0W8hNO+A3ln2miQb4S+AlbanpjbPaZaeZrDHIcZNhDrvIQyPPgucAHwjlnnR9rcSZXYBKwgBrtVz1orBLMJ2CxfbvoewXeIK4HXAB1K/nxd9NLLlgULpDT3TfKx6Z9lrMtza44PiZsI2ci3Tpwz2ZcD3CVkEWwizWPPjKoUqS4GNhGnjXxNmuR4kDC1GUCcGFcJGswK+S+g5JwPzJD1bLRR70IXAmixbXiio3tB9zSu0qXeWPYsRqUy25wNfBWZKOtSskyIR39k8CVyfXnIUvx8RA9tfB46XlO4F07+7HFgg6dwsW554OegNrWkeP9vSO8uexYi1o5LW274RODFWuvDYngOcSujtJhF60kmE3nQUNWJQIWzF14gDwGeasOWG8ag3jFnzCu3rnWWvy7hP6o2CrCE8bB/k/yssGs7qxRetzwOXSFrXzXqWdI52Ne+X3uO+EZaU5J0yn7CkpM/8D+JN4d+eNcBBAAAAAElFTkSuQmCC\n",
"text/latex": [
"$\\displaystyle \\frac{m^{2} sc^{2}}{\\left(- c + \\log{\\left(p \\right)}\\right)^{4}} + \\frac{sm^{2}}{\\left(- c + \\log{\\left(p \\right)}\\right)^{2}}$"
],
"text/plain": [
" 2 2 2 \n",
" m ⋅sc sm \n",
"────────────── + ──────────────\n",
" 4 2\n",
"(-c + log(p)) (-c + log(p)) "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m, p, c, sm, sc, sT = symbols('m, p, c, sm, sc, sT')\n",
"\n",
"T = m/(ln(p) - c)\n",
"sigTsqrd = (diff(T,m))**2*sm**2+(diff(T,c))**2*sc**2\n",
"sigTsqrd"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAC0AAAAQCAYAAACC/vbpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAACWUlEQVR4nNXWT6hVVRTH8Y+SKLzUQElpkKalScQzcPBM0YHgIBUUgiaCOEikkeKbFMJyEZFCgxAHNTLUJk10pIKKJOJQQaRBVP7Jgf//4BOFkNfg7PO4Hu99HuS9gT847LPXXWuvL4t911kThoeHvW56o3OTmXuwBAswE09wFUewLyLutj04Mz/HSixGP6bi14jY2MP/Cub0OO5mRMzuCo3tOI8TuIU+DGAXtmTmQET825J7Z4EdwnV82CLmIX7sYh/q3DShp0XE02ZEZn6Hb/A1vmqRnKoA1/GXquKnW8Q8iIhdL3N6DrobcNFvKugPWiSuzxqBzMy2Ya3UrHQvrSvrxTHN/qImZ+ZGvIvHJd+ZiHjW6dQVOjMH8Samq/6Yy8sBu8eTGLNxsGG7nJmbI+L32jCxR/AgAttUwMexOiJujwNorf1YpQLvw8f4GXNxLDP7a8eula7bS2bOwqeqCl/IzLURcX48iCOiefEvYWtmDmGHqoNtoHel64NuRsRhrMYMHBhz2pfrp7KuqA2jQteKiKv4Ax9l5sxxABtN9ZXsqw2toIveKeuzUb3GXgNl/ac2jNzpzFyg+lw+7IzIzIn4Fm/jXETc7/htPibh74j471WpMnMRrkXE44Z9LvaV7aEXoPEZvs/Ms7iMu5il+prNww182ch3SjUvvIcrjYTrsb5s67lhaWb+Ut7vRMRgef8COzLzjGrWeYT5WIMpOIofukGfxPuqFvcJ3lI1+D9VvXNvRNzTXouxqWGbVx4FroY+jYUl7zLV/X2AsyX3wYgYGUcnvI6j6f90fa/fHuiiyQAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle 3.15$"
],
"text/plain": [
"3.15"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sig = sqrt(sigTsqrd)\n",
"sigT = sig.subs(p,760).subs(m,-5390).subs(c,21.89).subs(sm,33).subs(sc, 0.099)\n",
"sigT.evalf(3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### **(iii) Vapour pressure continued**\n",
"Continuing with the last example, suppose that the vapour pressure is required and that the temperature has been measured as $353 \\pm 3$ K, and again $m = -5390 \\pm 33$ K and $c = 21.89 \\pm 0.099$. In this case, $p = e^{m/T +c}$ and the derivatives produce\n",
"\n",
"$$\\displaystyle \\sigma_p^2=\\left(\\frac{m^2\\sigma_T^2}{T^2}+\\frac{\\sigma_m^2}{T^2}+\\sigma_c^2\\right)p^2$$\n",
"\n",
"and working out the terms produces a standard deviation of $141$ torr and a pressure of $750$ torr. The resulting standard deviation might seem unusually large, but this is caused by the exponential nature of the pressure equation having a great sensitivity to temperature.\n",
"\n",
"## 4.1 Table of some error propagation formulae\n",
"\n",
"The following table gives some examples of frequently met functions. The variances $\\sigma_u^2$ and $\\sigma_v^22$ are assumed to be known. The total variance $\\sigma^2$ is shown; remember to take the square root before using and note that σ 2 is always positive. The equation to use for many variables is\n",
"\n",
"$$\\displaystyle \\sigma_y^2=\\sum_i\\left(\\frac{\\partial y}{\\partial u_i}\\right)^2\\sigma_i^2\\qquad\\tag{22}$$\n",
"\n",
"$$\\displaystyle \\begin{array}{l|ll|l}\n",
"\\hline\n",
"y=f(x) & \\sigma_y && y=f(u,v) & \\sigma_y\\\\\n",
"\\hline\n",
"mx+c & m\\sigma_x && u\\pm v & \\sqrt{\\sigma_x^2+\\sigma_y^2}\\\\\n",
"mx^n+c & m nx^{n-1}\\sigma_x && uv & \\sqrt{s_{u}^{2} v^{2} + s_{v}^{2} u^{2}}\\\\\n",
"e^{\\pm ax} & a\\sigma_x e^{\\pm ax} && u/v &\\displaystyle\\sqrt{\\frac{s_{u}^{2} v^{2} + s_{v}^{2} u^{2}}{v^{4}}}\\\\\n",
"e^{\\pm a/x} & \\displaystyle \\frac{a\\sigma_x}{x^2}e^{\\pm a/x} && \\displaystyle \\frac{1}{u}\\pm \\frac{1}{v} & \\displaystyle\\sqrt{\\frac{s_{u}^{2}}{u^{4}} + \\frac{s_{v}^{2}}{v^{4}}}\\\\\n",
"\\sin(\\pm ax) & \\displaystyle a\\sigma_x\\cos(ax) && u\\ln(av) & \\displaystyle\\sqrt{s_{u}^{2} \\log{\\left(a v \\right)}^{2} + \\frac{s_{v}^{2} u^{2}}{v^{2}}}\\\\\n",
"\\ln(ax) &\\displaystyle \\frac{\\sigma_x}{a}&& ue^{av} & e^{av}\\sqrt{a^{2} s_{v}^{2} u^{2} + s_{u}^{2} }\\\\\n",
"\\hline\n",
"\\end{array}$$\n",
"\n",
"## 4.2 Matrix formulation of errors\n",
"Barlow (1989) demonstrates that equation 20 can be written in a matrix form, which does not immediately seem to offer any advantage, but this becomes clearer for problems that are more complex. The matrix equation is\n",
"\n",
"$$\\displaystyle V=GV_\\sigma^2G^T \\qquad\\tag{23}$$\n",
"\n",
"where $V_\\sigma^2$ is a square matrix of variances and $G$ a (Jacobian) matrix of partial derivatives. $V$ is the matrix of the variances for each variable. The total variance is the sum of the terms in $V$, which may be calculated as\n",
"\n",
"$$\\displaystyle \\sigma^2=UV\\qquad\\tag{24}$$\n",
"\n",
"where $U$ is a row matrix where each term is one. In example (vii) the matrix equation is written as\n",
"\n",
"$$\\displaystyle \n",
"V=\\begin{bmatrix}\\displaystyle\\frac{\\partial T}{\\partial m}&\\displaystyle\\frac{\\partial T}{\\partial c} \\end{bmatrix} \n",
" \\begin{bmatrix}\\sigma_m^2 & 0\\\\ 0& \\sigma_c^2 \\end{bmatrix}\\begin{bmatrix}\\displaystyle\\frac{\\partial T}{\\partial m}\\\\ \\displaystyle\\frac{\\partial T}{\\partial c}\\end{bmatrix} =\n",
"\\begin{bmatrix} \\displaystyle\\left(\\frac{\\partial T}{\\partial m}\\right)^2\\sigma_m^2 \\\\ \\left(\\displaystyle\\frac{\\partial T}{\\partial c}\\right)^2\\sigma_c^2\\end{bmatrix} $$\n",
"\n",
"and then\n",
"\n",
"$$\\displaystyle \\sigma^2 =\\begin{bmatrix} 1&1\\end{bmatrix}\\begin{bmatrix} \\left(\\displaystyle\\frac{\\partial T}{\\partial m}\\right)^2\\sigma_m^2 \\\\ \\left(\\displaystyle\\frac{\\partial T}{\\partial c}\\right)^2\\sigma_c^2\\end{bmatrix}= \\left(\\displaystyle\\frac{\\partial T}{\\partial m}\\right)^2\\sigma_m^2+ \\left(\\frac{\\partial T}{\\partial c}\\right)^2\\sigma_c^2$$\n",
"\n",
"## 5 Maximum Likelihood Method. Parameter estimation: \n",
"\n",
"The variance and mean have been used in our calculations on the assumption that they were the 'best estimation' of these properties, which means that they are as close as possible to the true values for the underlying process given that only a limited number of measurements are taken. Using the Maximum Likelihood method these estimates, such as mean and variance, can be found in terms of the measured values which we call $x_i$.\n",
"\n",
"A series of measurements of the same thing will always have a probability distribution $f(x,\\theta)$ with measured values $x_1,x_2\\cdots$ and the distribution will always depend on some unknown parameter $\\theta$, for example it could be the the mean. The likelihood function of observing a series of events is therefore the product of individual events, viz, $L(\\theta) = f(x_1,\\theta) f(x_2,\\theta) f(x_3,\\theta)\\cdots f(x_n,\\theta)$. What we want to know is what quantity best describes the quantity $\\theta$, i.e what is the most likely value of this quantity. This can be found by differentiating $L$ with respect to this quantity which is often the mean or variance, then setting the value to zero in the usual way of finding a maximum.\n",
"\n",
"Suppose that the process measured follows a normal distribution but with an unknown mean $\\mu$ but known variance $\\sigma^2$. The likelihood function is\n",
"\n",
"$$\\displaystyle L(\\mu)=\\prod_{i=1}^n \\frac{1}{\\sqrt{2\\pi\\sigma^2}}e^{-(x_i-\\mu)^2/2\\sigma^2}$$\n",
"\n",
"and it is a product as this is the probability of observing $n$ events one after the other. Because of the probabilities are multiplied together, mathematically it is far, far easier to take the log first, because this changes the product into a sum, then differentiate. The maximum of the log will be the same as that of the function itself.\n",
"\n",
"$$\\displaystyle \\ln\\big( L(\\mu)\\big) = \\sum_{i=1}^n -\\frac{1}{2}\\ln\\left(2\\pi\\sigma^2\\right) - \\frac{\\left(x_i-\\mu\\right)^2}{2\\sigma^2} \\\\\n",
"=-\\frac{n}{2}\\ln\\left(2\\pi\\sigma^2\\right) -\\frac{1}{2\\sigma^2}\\sum_i (x_i-\\mu)^2$$\n",
"\n",
"and differentiating by $\\mu$ and set to zero to find the maximum gives\n",
"\n",
"$$\\displaystyle \\begin{align}\\frac{d\\ln\\big(L(\\mu)\\big)}{d\\mu}=&0-\\frac{1}{2\\sigma^2}\\big( -2(x_1-\\mu)-2(x_2-\\mu)\\cdots - 2(x_n-\\mu)\\big)\\\\=&\\frac{1}{\\sigma^2}\\big(-n\\mu+\\sum_i x_i\\big)\\\\ =& \\frac{n}{\\sigma^2}\\big(-\\mu+\\sum_i \\frac{x_i}{n}\\big) =0\\end{align}$$\n",
"\n",
"thus the mean value is \n",
"\n",
"$$\\displaystyle \\langle x\\rangle \\equiv \\mu = \\frac{\\sum x_i}{n}$$\n",
"\n",
"which is what we had assumed anyway, and this shows that it is the most likely, i.e. the best estimate of the true value when only $n$ measurements are made. By assuming that the variance is also unknown by differentiating wrt. $\\sigma$ and setting the result to zero, this is found to be \n",
"\n",
"$$\\displaystyle \\sigma^2=\\frac{1}{n}\\sum_{i=1}^n (x_i-\\langle x\\rangle)^2$$\n",
"\n",
"The Poisson distribution, used for particle/photon counting or other infrequent but numerous random events (see section 7) has the likelihood function\n",
"\n",
"$$\\displaystyle L(\\mu)=\\prod_{i=0}^n \\frac{\\mu^{x_i} e^{-\\mu}}{x_i!}$$\n",
"\n",
"taking the log gives $\\ln(L)=-n\\mu+\\sum_i x_i\\ln(\\mu) -\\sum_i x_i!$ and differentiating \n",
"\n",
"$$\\displaystyle \\frac{d\\ln\\big(L(\\mu)\\big)}{d\\mu}=-n+ \\frac{\\sum_i x_i}{\\mu}=0$$\n",
"\n",
"then the mean value $\\mu$ is the best estimator if $\\displaystyle \\mu=\\frac{1}{n}\\sum_{i=0}^n x_i$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}