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 260 \begin{align*} 261 p &= \Pr(\overline{X} \lessgtr \mu(H_1)) \\ 262 &= 2 \cdot \Pr(\overline{X} <> \mu(H_1) | \mu = 8) 263 \end{align*} 264 265 Probability of observing a value of the sample statistic as significant as the one observed, assuming null hypothesis is true. 266 267 \vspace{0.5em} 268 \begin{tabularx}{23em}{|l|X|} 269 \hline 270 \rowcolor{cas} 271 \(\boldsymbol{p}\) & \textbf{Conclusion} \\ 272 \hline 273 \(> 0.05\) & insufficient evidence against \(H_0\) \\ 274 \(< 0.05\) (5\%) & good evidence against \(H_0\) \\ 275 \(< 0.01\) (1\%) & strong evidence against \(H_0\) \\ 276 \(< 0.001\) (0.1\%) & very strong evidence against \(H_0\) \\ 277 \hline 278 \end{tabularx} 279 280 \subsection*{Statistical significance} 281 282 Significance level is denoted by \(\alpha\). 283 284 \-\hspace{1em} If \(p<\alpha\), null hypothesis is \textbf{rejected} \\ 285 \-\hspace{1em} If \(p>\alpha\), null hypothesis is \textbf{accepted} 286 287 \subsection*{\(z\)-test} 288 289 Hypothesis test for a mean of a sample drawn from a normally distributed population with a known standard deviation. 290 291 \begin{cas} 292 Menu \(\rightarrow\) Statistics \(\rightarrow\) Calc \(\rightarrow\) Test. \\ 293 Select \textit{One-Sample Z-Test} and \textit{Variable}, then input: 294 \begin{description}[nosep, style=multiline, labelindent=0.5cm, leftmargin=2cm, font=\normalfont] 295 \item[\(\mu\) cond:] same operator as \(H_1\) 296 \item[\(\mu_0\):] expected sample mean (null hypothesis) 297 \item[\(\sigma\):] standard deviation (null hypothesis) 298 \item[\(\overline{x}\):] sample mean 299 \item[\(n\):] sample size 300 \end{description} 301 \end{cas} 302 303 \subsection*{One-tail and two-tail tests} 304 305 \subsubsection*{One tail} 306 307 \begin{itemize} 308 \item \(\mu\) has changed in one direction 309 \item State ``\(H_1: \mu \lessgtr \) known population mean'' 310 \end{itemize} 311 312 \subsubsection*{Two tail} 313 314 \begin{itemize} 315 \item Direction of \(\Delta \mu\) is ambiguous 316 \item State ``\(H_1: \mu \ne\) known population mean'' 317 \end{itemize} 318 319 For two tail tests: 320 \begin{align*} 321 p\text{-value} &= \Pr(|\overline{X} - \mu| \ge |\overline{x}_0 - \mu|) \\ 322 &= \left( |Z| \ge \left|\dfrac{\overline{x}_0 - \mu}{\sigma \div \sqrt{n}} \right| \right) 323 \end{align*} 324 325 \subsection*{Modulus notation for two tail} 326 327 \(\Pr(|\overline{X} - \mu| \ge a) \implies\) ``the probability that the distance between \(\overline{\mu}\) and \(\mu\) is \(\ge a\)'' 328 329 \subsection*{Inverse normal} 330 331 \begin{cas} 332 \verb;invNormCdf("L", ;\(\alpha\)\verb;, ;\(\dfrac{\sigma}{n^\alpha}\)\verb;, ;\(\mu\)\verb;); 333 \end{cas} 334 335 \subsection*{Errors} 336 337 \begin{description}[labelwidth=2.5cm, labelindent=0.5cm] 338 \item [Type I error] \(H_0\) is rejected when it is \textbf{true} 339 \item [Type II error] \(H_0\) is \textbf{not} rejected when it is \textbf{false} 340 \end{description} 341 342% \subsection*{Using c.i. to find \(p\)} 343% need more here 344 345\end{document}