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