1\documentclass[spec-collated.tex]{subfiles} 2\begin{document} 3 4 \section{Statistics} 5 6 \subsection*{Continuous random variables} 7 8 A continuous random variable \(X\) has a pdf \(f\) such that: 9 10 \begin{enumerate} 11 \item \(f(x) \ge 0 \forall x \) 12 \item \(\int^\infty_{-\infty} f(x) \> dx = 1\) 13 \end{enumerate} 14 15 \begin{align*} 16 E(X) &= \int_\textbf{X} (x \cdot f(x)) \> dx \\ 17 \operatorname{Var}(X) &= E\left[(X-\mu)^2\right] 18 \end{align*} 19 20 \[ \Pr(X \le c) = \int^c_{-\infty} f(x) \> dx \] 21 22 23 \subsection*{Two random variables \(X, Y\)} 24 25 If \(X\) and \(Y\) are independent: 26 \begin{align*} 27 \operatorname{E}(aX+bY) & = a\operatorname{E}(X)+b\operatorname{E}(Y) \\ 28 \operatorname{Var}(aX \pm bY \pm c) &= a^2 \operatorname{Var}(X) + b^2 \operatorname{Var}(Y) 29 \end{align*} 30 31 \subsection*{Linear functions \(X \rightarrow aX+b\)} 32 33 \begin{align*} 34 \Pr(Y \le y) &= \Pr(aX+b \le y) \\ 35 &= \Pr\left(X \le \dfrac{y-b}{a}\right) \\ 36 &= \int^{\frac{y-b}{a}}_{-\infty} f(x) \> dx 37 \end{align*} 38 39 \begin{align*} 40 \textbf{Mean:} && \operatorname{E}(aX+b) & = a\operatorname{E}(X)+b \\ 41 \textbf{Variance:} && \operatorname{Var}(aX+b) &= a^2 \operatorname{Var}(X) \\ 42 \end{align*} 43 44 \subsection*{Expectation theorems} 45 46 For some non-linear function \(g\), the expected value \(E(g(X))\) is not equal to \(g(E(X))\). 47 48 \begin{align*} 49 E(X^2) &= \operatorname{Var}(X) - \left[E(X)\right]^2 \\ 50 E(X^n) &= \Sigma x^n \cdot p(x) \tag{non-linear} \\ 51 &\ne [E(X)]^n \\ 52 E(aX \pm b) &= aE(X) \pm b \tag{linear} \\ 53 E(b) &= b \tag{\(\forall b \in \mathbb{R}\)}\\ 54 E(X+Y) &= E(X) + E(Y) \tag{two variables} 55 \end{align*} 56 57 \subsection*{Sample mean} 58 59 Approximation of the \textbf{population mean} determined experimentally. 60 61 \[ \overline{x} = \dfrac{\Sigma x}{n} \] 62 63 where 64 \begin{description}[nosep, labelindent=0.5cm] 65 \item \(n\) is the size of the sample (number of sample points) 66 \item \(x\) is the value of a sample point 67 \end{description} 68 69\begin{cas} 70 \begin{enumerate}[leftmargin=3mm] 71 \item Spreadsheet 72 \item In cell A1:\\ \path{mean(randNorm(sd, mean, sample size))} 73 \item Edit \(\rightarrow\) Fill \(\rightarrow\) Fill Range 74 \item Input range as A1:An where \(n\) is the number of samples 75 \item Graph \(\rightarrow\) Histogram 76 \end{enumerate} 77 \end{cas} 78 79 \subsubsection*{Sample size of \(n\)} 80 81 \[ \overline{X} = \sum_{i=1}^n \frac{x_i}{n} = \dfrac{\sum x}{n} \] 82 83 Sample mean is distributed with mean \(\mu\) and sd \(\frac{\sigma}{\sqrt{n}}\) (approaches these values for increasing sample size \(n\)). 84 85 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}}\) 86 87 \begin{cas} 88 89 \begin{itemize} 90 \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 91 \item To calculate parameters of a dataset: Calc \(\rightarrow\) One-variable 92 \end{itemize} 93 94 \end{cas} 95 96 \subsection*{Normal distributions} 97 98 99 \[ Z = \frac{X - \mu}{\sigma} \] 100 101 Normal distributions must have area (total prob.) of 1 \(\implies \int^\infty_{-\infty} f(x) \> dx = 1\) \\ 102 \(\text{mean} = \text{mode} = \text{median}\) 103 104 \begin{warning} 105 Always express \(z\) as +ve. Express confidence \textit{interval} as ordered pair. 106 \end{warning} 107 108\pgfmathdeclarefunction{gauss}{2}{% 109 \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}% 110} 111 \pgfplotsset{every axis/.append style={ 112 axis x line=middle, % put the x axis in the middle 113 axis y line=middle, % put the y axis in the middle 114 }} \pgfkeys{/pgf/decoration/.cd, 115 distance/.initial=10pt 116} \pgfdeclaredecoration{add dim}{final}{ 117\state{final}{% 118\pgfmathsetmacro{\dist}{5pt*\pgfkeysvalueof{/pgf/decoration/distance}/abs(\pgfkeysvalueof{/pgf/decoration/distance})} 119 \pgfpathmoveto{\pgfpoint{0pt}{0pt}} 120 \pgfpathlineto{\pgfpoint{0pt}{2*\dist}} 121 \pgfpathmoveto{\pgfpoint{\pgfdecoratedpathlength}{0pt}} 122 \pgfpathlineto{\pgfpoint{(\pgfdecoratedpathlength}{2*\dist}} 123 \pgfsetarrowsstart{latex} 124 \pgfsetarrowsend{latex} 125 \pgfpathmoveto{\pgfpoint{0pt}{\dist}} 126 \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{\dist}} 127 \pgfusepath{stroke} 128 \pgfpathmoveto{\pgfpoint{0pt}{0pt}} 129 \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{0pt}} 130}} 131\tikzset{dim/.style args={#1,#2}{decoration={add dim,distance=#2}, 132 decorate, 133 postaction={decorate,decoration={text along path, 134 raise=#2, 135 text align={align=center}, 136 text={#1}}}}} 137 \begin{figure*}[hb] 138 \centering 139 {\begin{center} \begin{tikzpicture} 140 \pgfplotsset{set layers, axis x line=middle, axis y line=middle} 141\begin{axis}[every axis plot post/.append style={ 142 mark=none,domain=-3:3,samples=50,smooth}, 143 axis x line=bottom, 144 axis y line=left, 145 enlargelimits=upper, 146 x=\textwidth/10, 147 ytick={0.55}, 148 yticklabels={\(\frac{1}{\sigma \sqrt{2\pi}}\)}, 149 xtick={-2,-1,0,1,2}, 150 x tick label style = {font=\footnotesize}, 151 xticklabels={\((\mu-2\sigma)\), \((\mu-\sigma)\), \(\mu\), \((\mu+\sigma)\), \((\mu+2\sigma)\)}, 152 xlabel={\(x\)}, 153 every axis x label/.style={at={(current axis.right of origin)},anchor=north west}, 154 every axis y label/.style={at={(axis description cs:-0.02,0.2)}, anchor=south west, rotate=90}, 155 ylabel={\(\Pr(X=x)\)}] 156 \addplot {gauss(0,0.75)}; 157\fill[red!30] (-3,0) -- plot[id=f3,domain=-3:3,samples=50] 158 function {1/(0.75*sqrt(2*pi))*exp(-((x)^2)/(2*0.75^2))} -- (3,0) -- cycle; 159 \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; 160 \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; 161 \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; 162 \begin{scope}[<->] 163 \draw (-1,0.35) -- (1,0.35) node [midway, fill=white] {68.3\%}; 164 \draw (-2,0.25) -- (2,0.25) node [midway, fill=white] {95.5\%}; 165 \draw (-3,0.15) -- (3,0.15) node [midway, fill=white] {99.7\%}; 166 \end{scope} 167 \begin{scope}[-, dashed, gray] 168 \draw (-1,0) -- (-1, 0.35); 169 \draw (1,0) -- (1, 0.35); 170 \draw (-2,0) -- (-2, 0.25); 171 \draw (2,0) -- (2, 0.25); 172 \draw (-3,0) -- (-3, 0.15); 173 \draw (3,0) -- (3, 0.15); 174 \end{scope} 175\end{axis} 176\begin{axis}[every axis plot post/.append style={ 177 mark=none,domain=-3:3,samples=50,smooth}, 178 axis x line=bottom, 179 enlargelimits=upper, 180 x=\textwidth/10, 181 xtick={-2,-1,0,1,2}, 182 axis x line shift=30pt, 183 hide y axis, 184 x tick label style = {font=\footnotesize}, 185 xlabel={\(Z\)}, 186 every axis x label/.style={at={(axis description cs:1,-0.25)},anchor=south west}] 187 \addplot {gauss(0,0.75)}; 188\end{axis} 189\end{tikzpicture}\end{center}} 190 \end{figure*} 191 192 \subsection*{Central limit theorem} 193 194 If \(X\) is randomly distributed with mean \(\mu\) and sd \(\sigma\), then with an adequate sample size \(n\) the distribution of the sample mean \(\overline{X}\) is approximately normal with mean \(E(\overline{X})\) and \(\operatorname{sd}(\overline{X}) = \frac{\sigma}{\sqrt{n}}\). 195 196 \subsection*{Confidence intervals} 197 198 \begin{itemize} 199 \item \textbf{Point estimate:} single-valued estimate of the population mean from the value of the sample mean \(\overline{x}\) 200 \item \textbf{Interval estimate:} confidence interval for population mean \(\mu\) 201 \item \(C\)\% confidence interval \(\implies\) \(C\)\% of samples will contain population mean \(\mu\) 202 \end{itemize} 203 204 \subsubsection*{95\% confidence interval} 205 206 For 95\% c.i. of population mean \(\mu\): 207 208 \[ x \in \left(\overline{x} \pm 1.96 \dfrac{\sigma}{\sqrt{n}} \right)\] 209 210 where: 211 \begin{description}[nosep, labelindent=0.5cm] 212 \item \(\overline{x}\) is the sample mean 213 \item \(\sigma\) is the population sd 214 \item \(n\) is the sample size from which \(\overline{x}\) was calculated 215 \end{description} 216 217 \begin{cas} 218 Menu \(\rightarrow\) Stats \(\rightarrow\) Calc \(\rightarrow\) Interval \\ 219 Set \textit{Type = One-Sample Z Int} \\ \-\hspace{1em} and select \textit{Variable} 220 \end{cas} 221 222 \subsection*{Margin of error} 223 224 For 95\% confidence interval of \(\mu\): 225 \begin{align*} 226 M &= 1.96 \times \dfrac{\sigma}{\sqrt{n}} \\ 227 \implies n &= \left( \dfrac{1.96 \sigma}{M} \right)^2 228 \end{align*} 229 230 Always round \(n\) up to a whole number of samples. 231 232 \subsection*{General case} 233 234 For \(C\)\% c.i. of population mean \(\mu\): 235 236 \[ x \in \left( \overline{x} \pm k \dfrac{\sigma}{\sqrt{n}} \right) \] 237 \hfill where \(k\) is such that \(\Pr(-k < Z < k) = \frac{C}{100}\) 238 239 \subsection*{Confidence interval for multiple trials} 240 241 For a set of \(n\) confidence intervals (samples), there is \(0.95^n\) chance that all \(n\) intervals contain the population mean \(\mu\). 242 243 \section{Hypothesis testing} 244 245 \begin{warning} 246 Note hypotheses are always expressed in terms of population parameters 247 \end{warning} 248 249 \subsection*{Null hypothesis \(H_0\)} 250 251 Sample drawn from population has same mean as control population, and any difference can be explained by sample variations. 252 253 \subsection*{Alternative hypothesis \(H_1\)} 254 255 Amount of variation from control is significant, despite standard sample variations. 256 257 \subsection*{\(p\)-value} 258 259 Probability of observing a value of the sample statistic as significant as the one observed, assuming null hypothesis is true. 260 261 % table of p-values for strength of evidence 262 263 \subsection*{Distribution of sample mean} 264 265 If \(X \sim \operatorname{N}(\mu, \sigma)\), then distribution of sample mean \(\overline{X}\) is also normal with \(\overline{X} \sim \operatorname{N}(\mu, \frac{\sigma}{\sqrt{n}}\). 266 267 \subsection*{Statistical significance} 268 269 Significance level is denoted by \(\alpha\). 270 271 \-\hspace{1em} If \(p<\alpha\), null hypothesis is \textbf{rejected} \\ 272 \-\hspace{1em} If \(p>\alpha\), null hypothesis is \textbf{accepted} 273 274 \subsection*{\(z\)-test} 275 276 Hypothesis test for a mean of a sample drawn from a normally distributed population with a known standard deviation. 277 278 \begin{cas} 279 Menu \(\rightarrow\) Statistics \(\rightarrow\) Calc \(\rightarrow\) Test. \\ 280 Select \textit{One-Sample Z-Test} and \textit{Variable}, then input: 281 \begin{description}[nosep, style=multiline, labelindent=0.5cm, leftmargin=2cm, font=\normalfont] 282 \item[\(\mu\) cond:] same operator as \(H_1\) 283 \item[\(\mu_0\):] expected sample mean (null hypothesis) 284 \item[\(\sigma\):] standard deviation (null hypothesis) 285 \item[\(\overline{x}\):] sample mean 286 \item[\(n\):] sample size 287 \end{description} 288 \end{cas} 289 290\end{document}