methods / statistics-ref.texon commit [chem] start organic reactions summary document (5447e6c)
   1\documentclass[methods-collated.tex]{subfiles}
   2
   3\begin{document}
   4
   5\section{Statistics}
   6
   7\subsection*{Probability}
   8
   9\begin{align*}
  10  \Pr(A \cup B) &= \Pr(A) + \Pr(B) - \Pr(A \cap B) \\
  11  \Pr(A \cap B) &= \Pr(A|B) \times \Pr(B) \\
  12  \Pr(A|B) &= \frac{\Pr(A \cap B)}{\Pr(B)} \\
  13  \Pr(A) &= \Pr(A|B) \cdot \Pr(B) + \Pr(A|B^{\prime}) \cdot \Pr(B^{\prime})
  14\end{align*}
  15
  16Mutually exclusive: \(\Pr(A \cap B) = 0\) \\
  17
  18Independent events:
  19\begin{flalign*}
  20  \quad \Pr(A \cap B) &= \Pr(A) \times \Pr(B)& \\
  21  \Pr(A|B) &= \Pr(A) \\
  22  \Pr(B|A) &= \Pr(B)
  23\end{flalign*}
  24
  25\subsection*{Combinatorics}
  26
  27\begin{itemize} \tightlist
  28  \item Arrangements \({n \choose k} = \frac{n!}{(n-k)}\)
  29  \item \colorbox{highlight}{Combinations} \({n \choose k} = \frac{n!}{k!(n-k)!}\)
  30  \item Note \({n \choose k} = {n \choose k-1}\)
  31\end{itemize}
  32
  33\subsection*{Distributions}
  34
  35\begin{tikzpicture}
  36  \begin{axis}[axis lines=left,
  37    ticks=none,
  38    xmin=0,
  39    ymax=0.5,
  40    enlargelimits=upper,
  41    ylabel={\(\Pr(X=x)\)},
  42    xlabel={\(x\)},
  43    every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
  44    every axis y label/.style={at={(axis description cs:-0.02,0.5)}, anchor=south west, rotate=90},
  45    ]
  46    \fill[pattern=north east lines, pattern color=orange] (0,0)  -- plot[domain=0:1.68, samples=50] function {abs(x)*exp(-x)} -- (1.68,0) -- cycle;
  47    \fill[pattern=north west lines, pattern color=red] (1.68,0)  -- plot[domain=1.68:5, samples=50] function {abs(x)*exp(-x)} -- (5,0) -- cycle;
  48    \draw[dashed, blue, very thick] (axis cs:1.68,0) -- (axis cs:1.68,0.31) node [above, anchor=south west, black] {Median};
  49    \draw[dashed, blue, very thick] (axis cs:2,0) -- (axis cs:2,0.27) node [above, anchor=west, black] {Mean};
  50    \draw[dashed, blue, very thick] (axis cs:1,0) -- (axis cs:1,0.365) node [above, black] {Mode};
  51    \node at (1,0.18) {\textbf{50\%}};
  52    \node at (3.1,0.08) {\textbf{50\%}};
  53    \addplot[thick, black, no markers, samples=200, domain=0:5] {abs(x)*exp(-x)};
  54  \end{axis}
  55\end{tikzpicture}
  56
  57\subsubsection*{Mean \(\mu\)}
  58
  59\begin{align*}
  60  E(X) &= \frac{\Sigma \left[ x \cdot f(x) \right]}{\Sigma f} \tag{\(f =\) absolute frequency} \\
  61  &= \sum_{i=1}^n \left[ x_i \cdot \Pr(X=x_i) \right] \tag{discrete}\\
  62  &= \int_\textbf{X} (x \cdot f(x)) \> dx
  63\end{align*}
  64
  65\subsubsection*{Mode}
  66
  67Value of \(X\) which has the highest probability
  68
  69\begin{itemize} \tightlist
  70  \item Most popular value in discrete distributions
  71  \item Must exist in distribution
  72  \item Represented by local max in pdf
  73  \item Multiple modes exist when \(>1 \> X\) value have equal-highest probability
  74\end{itemize}
  75
  76\subsubsection*{Median}
  77
  78Value separating lower and upper half of distribution area
  79
  80\textbf{Continuous:}
  81\[ m = X \> \text{such that} \> \int_{-\infty}^{m} f(x) \> dx = 0.5 \]
  82
  83\textbf{Discrete:} (not in course)
  84\begin{itemize} \tightlist
  85  \item Does not have to exist in distribution
  86  \item Add values of \(X\) smallest to largest until sum is \(\ge 0.5\)
  87  \item If \(X_1 < 0.5 < X_2\), then median is the average of \(X_1\) and \(X_2\)
  88  \begin{itemize}\tightlist
  89    \item If \(m > 0.5\), then value of \(X\) that is reached is the median of \(X\)
  90  \end{itemize}
  91\end{itemize}
  92
  93\subsubsection*{Variance \(\sigma^2\)}
  94
  95\begin{align*}
  96  \operatorname{Var}(x) &= \sum_{i=1}^n p_i (x_i-\mu)^2 \\
  97  &= \sum (x-\mu)^2 \times \Pr(X=x) \\
  98  &= \sum x^2 \times p(x) - \mu^2 \\
  99  &= \operatorname{E}(X^2) - [\operatorname{E}(X)]^2 \\
 100  &= E\left[(X-\mu)^2\right]
 101\end{align*}
 102
 103\subsubsection*{Standard deviation \(\sigma\)}
 104
 105\begin{align*}
 106  \sigma &= \operatorname{sd}(X) \\
 107  &= \sqrt{\operatorname{Var}(X)}
 108\end{align*}
 109
 110\subsection*{Binomial distributions}
 111
 112Conditions for a \textit{binomial distribution}:
 113\begin{enumerate} \tightlist
 114  \item Two possible outcomes: \textbf{success} or \textbf{failure}
 115  \item \(\Pr(\text{success})\) (=\(p\)) is constant across trials
 116  \item Finite number \(n\) of independent trials
 117\end{enumerate}
 118
 119
 120\subsubsection*{Properties of \(X \sim \operatorname{Bi}(n,p)\)}
 121
 122\begin{align*}
 123  \mu(X) &= np \\
 124  \operatorname{Var}(X) &= np(1-p) \\
 125  \sigma(X) &= \sqrt{np(1-p)} \\
 126  \Pr(X=x) &= {n \choose x} \cdot p^x \cdot (1-p)^{n-x}
 127\end{align*}
 128
 129\begin{cas}
 130  Interactive \(\rightarrow\) Distribution \(\rightarrow\) \verb;binomialPdf;
 131  \begin{description}[nosep, style=multiline, labelindent=0.5cm, leftmargin=3cm, font=\normalfont]
 132    \item [x:] no. of successes
 133    \item [numtrial:] no. of trials
 134    \item [pos:] probability of success
 135  \end{description}
 136\end{cas}
 137
 138\subsection*{Continuous random variables}
 139
 140A continuous random variable \(X\) has a pdf \(f\) such that:
 141
 142\begin{enumerate}
 143  \item \(f(x) \ge 0 \forall x \)
 144  \item \(\int^\infty_{-\infty} f(x) \> dx = 1\)
 145\end{enumerate}
 146
 147\begin{align*}
 148  E(X) &= \int_\textbf{X} (x \cdot f(x)) \> dx \\
 149  \operatorname{Var}(X) &= E\left[(X-\mu)^2\right]
 150\end{align*}
 151
 152\[ \Pr(X \le c) = \int^c_{-\infty} f(x) \> dx \]
 153
 154\begin{cas}
 155  Define piecewise functions: \\
 156  \-\hspace{1em}Math3 \(\rightarrow\)
 157  \begin{tikzpicture}%
 158    \draw rectangle (0.5,0.5); 
 159    \node at (0.08,0.25) {\(\{\)};
 160    \filldraw [black] (0.15, 0.4) rectangle(0.25, 0.3);
 161    \draw (0.35, 0.4) rectangle(0.45, 0.3);
 162    \node [font=\footnotesize] at (0.3,0.3) {\verb;,;};
 163    \draw (0.15, 0.2) rectangle(0.25, 0.1);
 164    \node [font=\footnotesize] at (0.3,0.1) {\verb;,;};
 165    \draw (0.35, 0.2) rectangle(0.45, 0.1);
 166  \end{tikzpicture}
 167  % TODO: finish this section
 168\end{cas}
 169
 170\subsection*{Two random variables \(X, Y\)}
 171
 172If \(X\) and \(Y\) are independent:
 173\begin{align*}
 174  \operatorname{E}(aX+bY) & = a\operatorname{E}(X)+b\operatorname{E}(Y) \\
 175  \operatorname{Var}(aX \pm bY \pm c) &= a^2 \operatorname{Var}(X) + b^2 \operatorname{Var}(Y)
 176\end{align*}
 177
 178\subsection*{Linear functions \(X \rightarrow aX+b\)}
 179
 180\begin{align*}
 181  \Pr(Y \le y) &= \Pr(aX+b \le y) \\
 182  &= \Pr\left(X \le \dfrac{y-b}{a}\right) \\
 183  &= \int^{\frac{y-b}{a}}_{-\infty} f(x) \> dx
 184\end{align*}
 185
 186\begin{align*}
 187  \textbf{Mean:} && \operatorname{E}(aX+b) & = a\operatorname{E}(X)+b \\
 188  \textbf{Variance:} && \operatorname{Var}(aX+b) &= a^2 \operatorname{Var}(X) \\
 189\end{align*}
 190
 191\subsection*{Expectation theorems}
 192
 193For some non-linear function \(g\), the expected value \(E(g(X))\) is not equal to \(g(E(X))\).
 194
 195\begin{align*}
 196  E(X^2) &= \operatorname{Var}(X) - \left[E(X)\right]^2 \\
 197  E(X^n) &= \Sigma x^n \cdot p(x) \tag{non-linear} \\
 198  &\ne [E(X)]^n \\
 199  E(aX \pm b) &= aE(X) \pm b \tag{linear} \\
 200  E(b) &= b \tag{\(\forall b \in \mathbb{R}\)}\\
 201  E(X+Y) &= E(X) + E(Y) \tag{two variables}
 202\end{align*}
 203
 204\begin{figure*}[hb]
 205  \centering
 206  \include{../spec/normal-dist-graph}
 207\end{figure*}
 208
 209\subsection*{Sample mean}
 210
 211Approximation of the \textbf{population mean} determined experimentally.
 212
 213\[ \overline{x} = \dfrac{\Sigma x}{n} \]
 214
 215where
 216\begin{description}[nosep, labelindent=0.5cm]
 217  \item \(n\) is the size of the sample (number of sample points)
 218  \item \(x\) is the value of a sample point
 219\end{description}
 220
 221\begin{cas}
 222  \begin{enumerate}[leftmargin=3mm]
 223    \item Spreadsheet
 224    \item In cell A1:\\ \path{mean(randNorm(sd, mean, sample size))}
 225    \item Edit \(\rightarrow\) Fill \(\rightarrow\) Fill Range
 226    \item Input range as A1:An where \(n\) is the number of samples
 227    \item Graph \(\rightarrow\) Histogram
 228  \end{enumerate}
 229\end{cas}
 230
 231\subsubsection*{Sample size of \(n\)}
 232
 233\[ \overline{X} = \sum_{i=1}^n \frac{x_i}{n} = \dfrac{\sum x}{n} \]
 234
 235Sample mean is distributed with mean \(\mu\) and sd \(\frac{\sigma}{\sqrt{n}}\) (approaches these values for increasing sample size \(n\)).
 236
 237For a new distribution with mean of \(n\) trials, \(\operatorname{E}(X^\prime) = \operatorname{E}(X), \quad \operatorname{sd}(X^\prime) = \dfrac{\operatorname{sd}(X)}{\sqrt{n}}\)
 238
 239\begin{cas}
 240
 241  \begin{itemize}
 242    \item Spreadsheet \(\rightarrow\) Catalog \(\rightarrow\) \verb;randNorm(sd, mean, n); where \verb;n; is the number of samples. Show histogram with Histogram key in top left
 243    \item To calculate parameters of a dataset: Calc \(\rightarrow\) One-variable
 244  \end{itemize}
 245
 246\end{cas}
 247
 248\subsection*{Population sampling}
 249
 250\subsubsection*{Population proportion}
 251
 252\[ p = \dfrac{n \text{ with attribute in population}}{\text{population size}} \]
 253
 254Constant for a given population.
 255
 256\subsection*{Sample proportion}
 257
 258\[ \hat{p} = \dfrac{n \text{ with attribute in sample}}{\text{sample size}} \]
 259
 260Varies with each sample.
 261
 262\subsection*{Normal distributions}
 263
 264
 265\[ Z = \frac{X - \mu}{\sigma} \]
 266
 267Normal distributions must have area (total prob.) of 1 \(\implies \int^\infty_{-\infty} f(x) \> dx = 1\) \\
 268\(\text{mean} = \text{mode} = \text{median}\)
 269
 270\begin{warning}
 271  Always express \(z\) as +ve. Express confidence \textit{interval} as ordered pair.
 272\end{warning}
 273
 274\subsection*{Confidence intervals}
 275
 276\begin{itemize}
 277  \item \textbf{Point estimate:} single-valued estimate of the population mean from the value of the sample mean \(\overline{x}\)
 278  \item \textbf{Interval estimate:} confidence interval for population mean \(\mu\)
 279  \item \(C\)\% confidence interval \(\implies\) \(C\)\% of samples will contain population mean \(\mu\)
 280\end{itemize}
 281
 282\begin{cas}
 283  Menu \(\rightarrow\) Stats \(\rightarrow\) Calc \(\rightarrow\) Interval \\
 284  Set \textit{Type = One-Sample Z Int} \\ \-\hspace{1em} and select \textit{Variable}
 285\end{cas}
 286
 287\subsubsection*{95\% confidence interval}
 288
 289For 95\% c.i. of population mean \(\mu\):
 290
 291\[ x \in \left(\overline{x} \pm 1.96 \dfrac{\sigma}{\sqrt{n}} \right)\]
 292
 293where:
 294\begin{description}[nosep, labelindent=0.5cm]
 295  \item \(\overline{x}\) is the sample mean
 296  \item \(\sigma\) is the population sd
 297  \item \(n\) is the sample size from which \(\overline{x}\) was calculated
 298\end{description}
 299
 300\subsubsection*{Confidence interval of \(p\) from \(\hat{p}\)}
 301
 302\[ x \in \left( \hat{p} \pm Z \sqrt{\dfrac{\hat{p}(1-\hat{p})}{n}} \right) \]
 303
 304\subsection*{Margin of error}
 305
 306For 95\% confidence interval of \(\mu\):
 307\begin{align*}
 308  M &= 1.96 \times \dfrac{\sigma}{\sqrt{n}} \\
 309  &= \dfrac{1}{2} \times \text{width of c.i.} \\
 310  \implies n &= \left( \dfrac{1.96 \sigma}{M} \right)^2
 311\end{align*}
 312
 313Always round \(n\) up to a whole number of samples.
 314
 315\subsection*{General case}
 316
 317For \(C\)\% c.i. of population mean \(\mu\):
 318
 319\[ x \in \left( \overline{x} \pm k \dfrac{\sigma}{\sqrt{n}} \right) \]
 320\hfill where \(k\) is such that \(\Pr(-k < Z < k) = \frac{C}{100}\)
 321
 322\begin{cas}
 323  Menu \(\rightarrow\) Stats \(\rightarrow\) Calc \(\rightarrow\) Interval \\
 324  Set \textit{Type = One-\colorbox{important}{Prop} Z Int} \\
 325  Input  x \(= \hat{p} * n\)
 326\end{cas}
 327
 328\subsection*{Confidence interval for multiple trials}
 329
 330For a set of \(n\) confidence intervals (samples), there is \(0.95^n\) chance that all \(n\) intervals contain the population mean \(\mu\).
 331
 332\end{document}