跳转至

T test (Statistics Notes)

That's a great question! Understanding the math background of the t-test helps demystify it and shows you why it works the way it does. Let's break it down step by step, assuming you're a beginner.

The Core Problem the T-Test Solves

Imagine you want to know if the average height of students at your college is different from the national average of 5'7". You can't measure every student, so you take a sample.

  • You calculate the mean height of your sample (\(\bar{x}\)).
  • You want to compare this to the hypothesized national average (\(\mu_0 = 5'7"\)).

The challenge is that your sample mean (\(\bar{x}\)) will almost never be exactly equal to the true population mean, even if your college's average is 5'7". There's always some sampling variability. The t-test helps us determine if the difference we observe in our sample is likely due to real effect or just random chance.

Building Blocks of the T-Test

The t-test relies on a few key statistical concepts: 1. Sample Mean (\(\bar{x}\)): * This is the average of the data points in your sample. * Formula: \(\bar{x} = \frac{\sum x_i}{n}\) * Where: * \(x_i\) are your individual data points. * \(n\) is your sample size (number of data points). 2. Sample Standard Deviation (\(s\)): * This measures the spread or variability of the data within your sample. It tells you, on average, how far each data point is from the sample mean. * Formula: \(s = \sqrt{\frac{\sum (x_i - \bar{x})^2}{n-1}}\) * Why \(n-1\)? This is called "degrees of freedom" and is crucial. We use \(n-1\) instead of \(n\) when calculating the sample standard deviation to make it an unbiased estimate of the population standard deviation. When you calculate the sample mean, you've used up one piece of information, so there are only \(n-1\) independent pieces of information left to estimate the variability. 1. Standard Error of the Mean (SEM): * This is arguably the most critical concept for the t-test's denominator. The sample standard deviation (\(s\)) tells us about the spread of individual data points. The Standard Error of the Mean (SEM) tells us about the spread of sample means. * Imagine you take many, many samples from the same population and calculate the mean for each sample. The SEM is an estimate of the standard deviation of those sample means. It tells you how much you expect sample means to vary from the true population mean. * Formula (when population standard deviation is unknown, which is usually the case): \(SEM = \frac{s}{\sqrt{n}}\) * What it means: A smaller SEM means your sample mean is a more precise estimate of the population mean. It gets smaller with larger sample sizes (because larger samples tend to give more reliable estimates) and smaller sample standard deviations (less spread in the data). * * ### The T-Statistic Formula * * The t-statistic essentially measures how many standard errors your sample mean is away from the hypothesized population mean. * For a one-sample t-test (comparing one sample mean to a known or hypothesized population mean): \(t = \frac{\text{sample mean} - \text{hypothesized population mean}}{\text{estimated standard error of the mean}}\) \(t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}\) * Numerator (\(\bar{x} - \mu_0\)): This is the observed difference. It tells you how much your sample mean deviates from what you expect it to be if the null hypothesis were true. * Denominator (\(s/\sqrt{n}\)): This is the estimated standard error of the mean. It tells you how much difference you would expect to see just due to random chance (sampling variability). * Interpreting the t-statistic: * A large absolute value of \(t\) (e.g., +3 or -3) means that your observed difference is large compared to what you'd expect from random chance alone. This suggests the difference is "statistically significant." * A small absolute value of \(t\) (e.g., +0.5 or -0.5) means your observed difference is small and could easily be due to random sampling variability. * * ### Degrees of Freedom (df) Revisited * * We briefly mentioned \(n-1\) for the sample standard deviation. For the t-test, degrees of freedom (df) are a crucial parameter that determines the exact shape of the t-distribution. * For a one-sample t-test, \(df = n-1\). * Conceptually: Degrees of freedom represent the number of independent pieces of information available to estimate a parameter. If you have \(n\) observations and you use them to estimate the mean, then only \(n-1\) of those observations are free to vary once the mean is fixed. * * ### The T-Distribution * * Unlike the Z-test (which uses the standard normal distribution and requires the population standard deviation to be known), the t-test uses the t-distribution. * Family of Distributions: The t-distribution isn't just one curve; it's a family of curves, with each curve defined by its degrees of freedom. * Shape: * It's bell-shaped and symmetrical, like the normal distribution. * However, it has "fatter tails" than the standard normal (Z) distribution. This means there's more probability in the tails, reflecting the increased uncertainty when we have to estimate the population standard deviation from the sample standard deviation, especially with smaller sample sizes. * As the degrees of freedom increase (i.e., as your sample size \(n\) gets larger), the t-distribution becomes more and more like the standard normal (Z) distribution. This makes sense: with very large samples, your sample standard deviation becomes a very good estimate of the population standard deviation, and the extra uncertainty diminishes.

How it All Connects:

Finding the P-Value 1. You calculate your t-statistic using your sample data. 2. You determine the appropriate degrees of freedom for your test. 3. You then look at the t-distribution curve corresponding to those degrees of freedom. 4. The p-value is the probability of observing a t-statistic as extreme as (or more extreme than) the one you calculated, assuming the null hypothesis is true. It's the area under the t-distribution curve in the tails beyond your calculated t-value. 5. If this p-value is very small (typically less than 0.05), it suggests that your observed difference is unlikely to be due to random chance, and you might reject the null hypothesis.

In summary: The t-test is a powerful tool because it allows us to perform hypothesis tests when we don't know the population standard deviation, which is almost always the case in real-world scenarios. It accounts for the added uncertainty of estimating this parameter by using the fatter-tailed t-distribution, with the specific shape determined by the degrees of freedom related to our sample size.

  • The Z-score that cuts off 2.5% in the upper tail (and -2.5% in the lower tail) is approximately \(\pm 1.96\) sigmas.