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