class: middle background-image: url(data:image/png;base64,#LTU_logo.jpg) background-position: top left background-size: 30% # STM1001 [Topic 5](https://bookdown.org/content/50a3178d-5432-44a3-bb5c-1718ca3e1fe2/) Workshop ## Hypothesis Testing ### La Trobe University This workshop complements the [Topic 5 readings](https://bookdown.org/content/50a3178d-5432-44a3-bb5c-1718ca3e1fe2/) --- # Topic 5: Hypothesis Testing ## In this week's readings: We will not have time to cover every concept, so please make sure you read this topic's readings thoroughly. <iframe src="https://bookdown.org/content/50a3178d-5432-44a3-bb5c-1718ca3e1fe2/" width="100%" height="400px" data-external="1"></iframe> --- # Today's workshop Today, we will introduce the following: * The `\(t\)`-distribution * What is a hypothesis test? * Example via the one-sample `\(t\)`-test --- name: stat class: middle background-image: url(data:image/png;base64,#slide_1.png) background-size: 110% --- name: stat class: middle background-image: url(data:image/png;base64,#slide_8.png) background-size: 100% --- # Claim * Suppose we made a claim that we believed that on average, people spend a total of 480 minutes (8 hours) sleeping per day. * Today, we will learn how we can test this claim... * We will use your answers from the following Menti question to test the claim --- name: menti class: middle background-image: url(data:image/png;base64,#menti.jpg) background-size: 115% # Menti ## Go to [www.menti.com](https://www.menti.com) and use ## the code provided --- # The `\(t\)`-distribution * The first thing we need to do in order to test the claim is establish the ***distribution of the sample mean*** * We discussed this in the last topic: The Central Limit Theorem allows us to find an approximate distribution for the sample mean .content-box-blue[ .center[ **The Central Limit Theorem (CLT)** ] Let `\(X_1, \ldots, X_n\)` be a random sample from a distribution with finite mean `\(\mu\)` and finite variance `\(\sigma^2\)`. For `\(\overline{X}\)` denoting the sample mean, if `\(n\)` is sufficiently large then `$$\overline{X}\stackrel{\tiny \text{approx.}}\sim N\left(\mu,\frac{\sigma^2}{n}\right)$$` where `\(\stackrel{\tiny \text{approx.}}\sim\)` denotes 'approximately distributed as'. ] --- # The `\(t\)`-distribution * Ideally, we find that the distribution of the sample mean is **Normal** -- * However, this requires knowing the population standard deviation `\(\sigma\)` -- * When we don’t know the population standard deviation `\(\sigma\)`, we can estimate it from our sample -- * BUT, we need to account for the extra uncertainty. We account for this by using the ***t*-distribution** --- # The `\(t\)`-distribution .pull-left[ <img src="data:image/png;base64,#Topic_5_Workshop_files/figure-html/unnamed-chunk-2-1.svg" style="display: block; margin: auto;" /> ] .pull-right[ * The `\(t\)`-distribution is similar to the Standard Normal distribution, and the larger the sample size, the closer to the Standard Normal distribution it gets {{content}} ] -- * The `\(t\)`-distribution is defined by the **degrees of freedom** (df) {{content}} -- * The degrees of freedom is related to the sample size, `\(n\)` {{content}} -- * In this topic, we have `\(\text{df} = n - 1\)` {{content}} --- # Hypothesis testing * So how do we actually test the claim? -- * We can use something called ***Hypothesis testing*** -- * First, we need to set up our hypotheses -- * When carrying out a hypothesis test, we normally consider two hypotheses: * The ***null hypothesis***, denoted `\(H_0\)` * The ***alternative hypothesis***, denoted `\(H_1\)` --- # Hypothesis testing In our example above, we would define the null and alternative hypotheses as follows: `$$H_0:\mu = 480\;\;\text{versus}\;\;H_1:\mu \neq 480,$$` where: -- * `\(\mu\)` denotes the population mean number of minutes people in the population spend sleeping per day -- * `\(H_0\)` denotes the null hypothesis that the average number of minutes people in this population spend sleeping is ***equal*** to 480 -- * `\(H_1\)` denotes the alternative hypothesis that the average number of minutes people in this population spend sleeping is ***not equal*** to 480 -- When we carry out a hypothesis test, to start out with, we ***assume the null hypothesis to be true***. -- If our sample provides evidence that this was not a reasonable assumption to make, then we ***reject the null hypothesis*** and therefore have evidence in favour of the ***alternative hypothesis***. --- # Hypothesis testing * In more general terms, suppose we have a sample of `\(n\)` observations that have been independently sampled from a population with population mean `\(\mu\)`. -- * Consider the hypotheses `$$H_0:\mu = \mu_0\;\;\text{versus}\;\;H_1:\mu \neq \mu_0,$$` where: * `\(\mu_0\)` denotes the population mean under the null hypothesis. -- Then a commonly used statistical test for this type of hypothesis test is the ***one-sample `\(t\)`-test*** based on the data observed in the sample, provided either the sample size `\(n\)` was large or the underlying distribution of the population from which the sample was taken is normally distributed. -- *Note: we will learn how to check these assumptions later on in this topic.* * It is called a `\(t\)`-test because we assume the standardised sample mean (test statistic) follows a `\(t\)`-distribution under `\(H_0\)`; i.e., because we use the `\(t\)`-distribution --- # Hypothesis testing - how does it work? * We start by looking at the distribution of the sample mean ***assuming the null hypothesis is true*** -- * We ***standardise*** this distribution. For example, here is a distribution of `\(\displaystyle (\bar{X} - \mu) / (S / \sqrt{n})\)` supposing we had a sample of `\(n = 72\)` <img src="data:image/png;base64,#Topic_5_Workshop_files/figure-html/unnamed-chunk-3-1.svg" width="50%" style="display: block; margin: auto;" /> --- # Hypothesis testing - how does it work? * Our value of `\(\mu_0\)` is 480, which corresponds to 0 in this curve * Then we calculate the ***test statistic*** based on our ***sample mean*** * Test statistics are similar to `\(z\)`-scores which we learnt about in the previous topic <img src="data:image/png;base64,#Topic_5_Workshop_files/figure-html/unnamed-chunk-4-1.svg" width="50%" style="display: block; margin: auto;" /> --- # Hypothesis testing - how does it work? The ***test statistic*** can be thought of as a ***standardised*** version of the sample mean. In general terms, the test statistic is defined as follows: $$T = \displaystyle \frac{\overline{X} - \mu_0}{\text{SE}} = \frac{\overline{X} - \mu_0}{S/\sqrt{n}}, $$ where: -- * `\(T\)` denotes the ***test statistic*** * `\(\overline{X}\)` denotes the sample mean * `\(\text{SE}\)` refers to the ***Standard Error***. The standard error is an *estimator* of the *standard deviation of the sample mean*, and is equal to `\(\frac{S}{\sqrt{n}}\)`. -- Note that the test statistic as defined above is ***random***. That is, it is a ***random variable*** and we have that `\(T\)` follows a `\(t\)`-distribution with `\(n – 1\)` degrees of freedom, which we also write as `\(T \sim t_{n-1}\)`. --- # Hypothesis testing - how does it work? The ***observed test statistic*** can be be calculated as $$t = \displaystyle \frac{\bar{x} - \mu_0}{\text{se}} = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}, $$ where: -- * `\(t\)` denotes the observed ***test statistic*** * `\(\bar{x}\)` denotes the observed sample mean * `\(\text{se}\)` refers to the ***observed standard error***. The standard error is an *estimate* of the *standard deviation of the sample mean*, and is equal to `\(\frac{s}{\sqrt{n}}\)`. -- Note the difference in notation between the ***random*** and ***observed*** test statistic definitions where, for example, `\(T\)` is the ***random*** test statistic, and `\(t\)` is the ***observed*** test statistic. --- # Hypothesis testing - how does it work? * If our sample mean is a lot higher than 480, then our test statistic will be above zero – maybe 2, 3, or even higher -- * If our sample mean is a lot lower than 480, then our test statistic will be below zero – maybe -2, -3, or even lower <img src="data:image/png;base64,#Topic_5_Workshop_files/figure-html/unnamed-chunk-5-1.svg" width="50%" style="display: block; margin: auto;" /> --- # Hypothesis testing - how does it work? * Let’s assume we get a sample mean much higher than 480 and it translates to a test statistic of 3. -- * Would it be reasonable to hold onto the assumption that the true average is 480 minutes? -- * Probably not. In this case, we would say we **reject the null hypothesis** and we have evidence that the true mean is different from 480 minutes <img src="data:image/png;base64,#Topic_5_Workshop_files/figure-html/unnamed-chunk-6-1.svg" width="40%" style="display: block; margin: auto;" /> --- # Hypothesis testing - how does it work? .pull-left[ <img src="data:image/png;base64,#Topic_5_Workshop_files/figure-html/unnamed-chunk-7-1.svg" style="display: block; margin: auto;" /> ] .pull-right[ * In general, we want to ask the question: *If the null hypothesis is true, what is the probability we would have got a result as least as extreme as the observed test statistic we got?* {{content}} ] -- * If the probability is small (normally less than 0.05), then this is normally considered enough evidence to reject `\(H_0\)` {{content}} -- * If the probability is not small (normally greater than 0.05), this is normally considered not enough evidence to reject `\(H_0\)` {{content}} --- # Hypothesis testing - how does it work? .pull-left[ <img src="data:image/png;base64,#Topic_5_Workshop_files/figure-html/unnamed-chunk-8-1.svg" style="display: block; margin: auto;" /> * *Note: if `\(p > 0.05\)` we “do not reject `\(H_0\)`”. This is not the same as “accept `\(H_0\)`”. Just because we don’t reject it does not mean we have proven it is true.* ] .pull-right[ * This probability is called a ***p*-value** {{content}} ] -- * Normally a test statistic around 2 or higher will translate into a `\(p\)`-value less than 0.05, but this will depend on the degrees of freedom {{content}} -- * How small does the `\(p\)`-value need to be to reject `\(H_0\)`? {{content}} -- * Typically, we denote the ***significance level*** as `\(\alpha = 0.05\)`, meaning that if we have `\(p < 0.05\)` we reject `\(H_0\)` {{content}} --- # Back to our example .pull-left[ <img src="data:image/png;base64,#Topic_5_Workshop_files/figure-html/unnamed-chunk-9-1.svg" style="display: block; margin: auto;" /> ] .pull-right[ * Let's use our responses to carry out the test * [*t*-test calculator](https://www.socscistatistics.com/tests/tsinglesample/default2.aspx ) ] --- #Group activity * In your group, discuss the result and answer the following: * What is the `\(p\)`-value? * What is the observed test statistic (*t*-value)? * Do we have evidence that the population mean number of minutes people spend sleeping is different from 480 minutes per day? After you have had a chance to discuss, nominate one person who can speak for the group and explain your conclusion to the rest of the class --- #More details in the readings * For more, see [this topic’s readings](https://bookdown.org/content/50a3178d-5432-44a3-bb5c-1718ca3e1fe2/) * There is more detail regarding the `\(t\)`-distribution and hypothesis testing * There are also additional, important topics covered, including: * One-sided vs two-sided tests * Type I and Type II Errors * Confidence intervals * Assumptions we need to make, and how to check them --- background-image: url(data:image/png;base64,#computerlab.jpg) background-position: bottom background-size: 75% class: center # See you in the computer labs! Continue with this topic's readings: [Topic 5 Readings](https://bookdown.org/content/50a3178d-5432-44a3-bb5c-1718ca3e1fe2/) --- class: middle <font color = "grey"> These notes have been prepared by Amanda Shaker. The copyright for the material in these notes resides with the authors named above, with the Department of Mathematics and Statistics and with La Trobe University. Copyright in this work is vested in La Trobe University including all La Trobe University branding and naming. Unless otherwise stated, material within this work is licensed under a Creative Commons Attribution-Non Commercial-Non Derivatives License <a href = "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank"> BY-NC-ND. </a> </font>