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) \ge0\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\begin{figure*}[hb] 109\centering 110\include{normal-dist-graph} 111\end{figure*} 112 113\subsection*{Central limit theorem} 114 115 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}}\). 116 117\subsection*{Confidence intervals} 118 119\begin{itemize} 120\item \textbf{Point estimate:} single-valued estimate of the population mean from the value of the sample mean \(\overline{x}\) 121\item \textbf{Interval estimate:} confidence interval for population mean \(\mu\) 122\item \(C\)\% confidence interval \(\implies\) \(C\)\% of samples will contain population mean \(\mu\) 123\end{itemize} 124 125\subsubsection*{95\% confidence interval} 126 127 For 95\% c.i. of population mean \(\mu\): 128 129 \[ x \in \left(\overline{x}\pm1.96\dfrac{\sigma}{\sqrt{n}}\right)\] 130 131 where: 132\begin{description}[nosep, labelindent=0.5cm] 133\item \(\overline{x}\) is the sample mean 134\item \(\sigma\) is the population sd 135\item \(n\) is the sample size from which \(\overline{x}\) was calculated 136\end{description} 137 138\begin{cas} 139 Menu \(\rightarrow\) Stats \(\rightarrow\) Calc \(\rightarrow\) Interval \\ 140 Set \textit{Type = One-Sample Z Int} \\ \-\hspace{1em} and select \textit{Variable} 141\end{cas} 142 143\subsection*{Margin of error} 144 145 For 95\% confidence interval of \(\mu\): 146\begin{align*} 147 M &= 1.96\times \dfrac{\sigma}{\sqrt{n}} \\ 148\implies n &= \left( \dfrac{1.96\sigma}{M}\right)^2 149\end{align*} 150 151 Always round \(n\) up to a whole number of samples. 152 153\subsection*{General case} 154 155 For \(C\)\% c.i. of population mean \(\mu\): 156 157 \[ x \in \left( \overline{x}\pm k \dfrac{\sigma}{\sqrt{n}}\right) \] 158\hfill where \(k\) is such that \(\Pr(-k < Z < k) = \frac{C}{100}\) 159 160\subsection*{Confidence interval for multiple trials} 161 162 For a set of \(n\) confidence intervals (samples), there is \(0.95^n\) chance that all \(n\) intervals contain the population mean \(\mu\). 163 164\section{Hypothesis testing} 165 166\begin{warning} 167 Note hypotheses are always expressed in terms of population parameters 168\end{warning} 169 170\subsection*{Null hypothesis \(\textbf{H}_0\)} 171 172 Sample drawn from population has same mean as control population, and any difference can be explained by sample variations. 173 174\subsection*{Alternative hypothesis \(\textbf{H}_1\)} 175 176 Amount of variation from control is significant, despite standard sample variations. 177 178\subsection*{\(p\)-value} 179 180 Probability of observing a value of the sample statistic as significant as the one observed, assuming null hypothesis is true. 181 182 For one-tail tests: 183\begin{align*} 184 p\text{-value} &= \Pr\left( \> \overline{X}\lessgtr \mu(\textbf{H}_1) \> \given \> \mu = \mu(\textbf{H}_0)\> \right) \\ 185 &= \Pr\left( Z \lessgtr \dfrac{\left( \mu(\textbf{H}_1) - \mu(\textbf{H}_0) \right) \cdot \sqrt{n} }{\operatorname{sd}(X)}\right) \\ 186 &\text{then use \texttt{normCdf} with std. norm.} 187\end{align*} 188 189\vspace{0.5em} 190\begin{tabularx}{23em}{|l|X|} 191\hline 192\rowcolor{cas} 193 \(\boldsymbol{p}\) & \textbf{Conclusion} \\ 194\hline 195 \(> 0.05\) & insufficient evidence against \(\textbf{H}_0\) \\ 196 \(< 0.05\) (5\%) & good evidence against \(\textbf{H}_0\) \\ 197 \(< 0.01\) (1\%) & strong evidence against \(\textbf{H}_0\) \\ 198 \(< 0.001\) (0.1\%) & very strong evidence against \(\textbf{H}_0\) \\ 199\hline 200\end{tabularx} 201 202\subsection*{Significance level \(\alpha\)} 203 204 The condition for rejecting the null hypothesis. 205 206 \-\hspace{1em} If \(p<\alpha\), null hypothesis is \textbf{rejected} \\ 207 \-\hspace{1em} If \(p>\alpha\), null hypothesis is \textbf{accepted} 208 209\subsection*{\(z\)-test} 210 211 Hypothesis test for a mean of a sample drawn from a normally distributed population with a known standard deviation. 212 213\begin{cas} 214 Menu \(\rightarrow\) Statistics \(\rightarrow\) Calc \(\rightarrow\) Test. \\ 215 Select \textit{One-Sample Z-Test} and \textit{Variable}, then input: 216\begin{description}[nosep, style=multiline, labelindent=0.5cm, leftmargin=2cm, font=\normalfont] 217\item[\(\mu\) cond:] same operator as \(\textbf{H}_1\) 218\item[\(\mu_0\):] expected sample mean (null hypothesis) 219\item[\(\sigma\):] standard deviation (null hypothesis) 220\item[\(\overline{x}\):] sample mean 221\item[\(n\):] sample size 222\end{description} 223\end{cas} 224 225\subsection*{One-tail and two-tail tests} 226 227 \[ p\text{-value (two-tail)} = 2\times p\text{-value (one-tail)} \] 228 229\subsubsection*{One tail} 230 231\begin{itemize} 232\item \(\mu\) has changed in one direction 233\item State ``\(\textbf{H}_1: \mu \lessgtr \) known population mean'' 234\end{itemize} 235 236\subsubsection*{Two tail} 237 238\begin{itemize} 239\item Direction of \(\Delta \mu\) is ambiguous 240\item State ``\(\textbf{H}_1: \mu \ne\) known population mean'' 241\end{itemize} 242 243\begin{align*} 244 p\text{-value} &= \Pr(|\overline{X} - \mu| \ge |\overline{x}_0 - \mu|) \\ 245 &= \left( |Z| \ge \left|\dfrac{\overline{x}_0 - \mu}{\sigma \div \sqrt{n}}\right| \right) \\ 246\end{align*} 247 248 where 249\begin{description}[nosep, labelindent=0.5cm] 250\item[\(\mu\)] is the population mean under \(\textbf{H}_0\) 251\item[\(\overline{x}_0\)] is the observed sample mean 252\item[\(\sigma\)] is the population s.d. 253\item[\(n\)] is the sample size 254\end{description} 255 256\subsection*{Modulus notation for two tail} 257 258 \(\Pr(|\overline{X} - \mu| \ge a) \implies\) ``the probability that the distance between \(\overline{\mu}\) and \(\mu\) is \(\ge a\)'' 259 260\subsection*{Inverse normal} 261 262\begin{cas} 263\verb;invNormCdf("L", ;\(\alpha\)\verb;, ;\(\dfrac{\sigma}{n^\alpha}\)\verb;, ;\(\mu\)\verb;); 264\end{cas} 265 266\subsection*{Errors} 267 268\begin{description}[labelwidth=2.5cm, labelindent=0.5cm] 269\item[Type I error] \(\textbf{H}_0\) is rejected when it is \textbf{true} 270\item[Type II error] \(\textbf{H}_0\) is \textbf{not} rejected when it is \textbf{false} 271\end{description} 272 273\begin{tabularx}{\columnwidth}{|X|l|l|} 274\rowcolor{cas}\hline 275\cellcolor{white}&\multicolumn{2}{c|}{\textbf{Actual result}} \\ 276\hline 277\cellcolor{cas}\(\boldsymbol{z}\)\textbf{-test} & \cellcolor{light-gray}\(\textbf{H}_0\) true & \cellcolor{light-gray}\(\textbf{H}_0\) false \\ 278\hline 279\cellcolor{light-gray}Reject \(\textbf{H}_0\) & Type I error & Correct \\ 280\hline 281\cellcolor{light-gray}Do not reject \(\textbf{H}_0\) & Correct& Type II error \\ 282\hline 283\end{tabularx} 284 285% \subsection*{Using c.i. to find \(p\)} 286% need more here 287 288\end{document}