No history yet

Z-Tests and T-Tests

Transcript

Beau

Okay Jo, so last time we talked about this whole idea of the null hypothesis—the default assumption—and the p-value, which is like our 'surprise meter'. If something is really surprising, like, low p-value, we can reject the null hypothesis.

Jo

Exactly. We have enough evidence to say, 'Hey, the default assumption is probably wrong.'

Beau

Right. But that feels... conceptual. Like, how do we actually *do* that? If I run a coffee shop and I switch to a new, expensive organic coffee bean, and I *think* my customers are rating their lattes higher... how do I test that for real? How do I get to that p-value?

Jo

That is the perfect question. And the answer is, you'd use a specific statistical test. For your coffee shop example, you're comparing averages, right? The average rating *before* the new beans versus the average rating *after*.

Beau

Yeah, exactly. Out of five stars or something.

Jo

So, for comparing averages, the two most fundamental tools in our toolkit are the Z-test and the T-test. They are the absolute workhorses for a data scientist.

Beau

Z-test and T-test. Okay. Why two? Why not just... the 'average-comparing-test'?

Jo

Well, they do basically the same thing, but they're suited for different situations. The main difference, and this is the key thing to remember, is sample size. How much data you have.

Beau

Oh, okay. So one's for big data, one's for small data?

Jo

Basically, yes. A Z-test is what you'd use when you have a large sample size—usually the rule of thumb is over 30 data points. And, technically, you're supposed to know the true variation, the standard deviation, of the entire population you're studying.

Beau

Wait, how would you know the variation of the *whole population*? Isn't that what I'm trying to figure out?

Jo

Exactly! In the real world, you almost never know that. That's why the T-test is so useful. The T-test is designed for smaller sample sizes—under 30—and it works when you *don't* know the population's standard deviation. It estimates it from your little sample.

Beau

Ah, okay. So the T-test is like the scrappy, resourceful cousin of the Z-test. It works with what it's got.

Jo

Perfect analogy. Think of it this way: a Z-test is for when you're the US Census Bureau comparing the average height of people in California versus New York. You have millions of data points, so your sample is basically the whole population. A T-test is for your coffee shop, where you only have, say, 25 customer ratings for the new bean. You have to be a bit more cautious with your conclusions because your sample is so small.

Beau

Okay, that makes total sense. So in most day-to-day business cases... like testing a new feature on a website, or a new marketing email... I'm probably going to be using a T-test.

Jo

Nine times out of ten, yes. Now, within these tests, there's another distinction: one-sample versus two-sample tests.

Beau

Let me guess... one sample of data versus two samples of data?

Jo

You got it. A one-sample test compares the average of your single sample against some known standard or claim.

Beau

Like what? Give me a 'mental movie' for that.

Jo

Okay. Imagine a factory that makes potato chip bags. They are legally required to have at least 150 grams of chips in every bag. That's the standard. You, as the quality control data scientist, pull 20 bags off the line and weigh them. You'd use a one-sample T-test to see if the average weight of your 20 bags is significantly *less than* the 150-gram standard.

Beau

Got it. So my sample's average versus a fixed number. Then the two-sample test must be... my coffee shop example, right? The average rating of the old beans versus the average rating of the new beans. Two different groups.

Jo

Precisely. Or testing a new website design. Group A sees the old website, Group B sees the new one. You run a two-sample T-test to see if the average time spent on the page is different between the two groups. That's A/B testing in a nutshell.

Beau

So all that A/B testing stuff I hear about is just... a two-sample t-test, most of the time?

Jo

It's the engine running under the hood, yes. So when you run one of these tests, you get a number back. It's called a t-statistic, or a t-score.

Beau

And that... tells me what? I thought the p-value was the important thing.

Jo

The p-value is the final destination, but the t-score is how you get there. The t-score measures the size of the difference relative to the variation in your data. In simple terms: how many standard deviations away is your sample mean from the null hypothesis?

Beau

Okay... break that down for me.

Jo

Imagine two kids' basketball teams. Team A has players who are all about the same height. Team B has a huge mix of really tall and really short players. Now, if you find one player who is 6 inches taller than the average... which team is he more likely to be on?

Beau

Team B, the one with the big mix. Because being 6 inches taller isn't that weird if there's already a lot of height variation.

Jo

Exactly! In Team A, where everyone is the same height, a 6-inch difference is a huge deal. It's a massive signal. In Team B, it's just noise. The t-score captures that. A big t-score means you have a big difference *and* low variation. A strong signal.

Beau

So a big t-score is good. It means my result is probably not just random chance.

Jo

Right. A bigger t-score—either positive or negative, the distance from zero is what matters—leads to a smaller p-value. It's the mathematical link between your data and that final 'surprise meter' we talked about.

Beau

Okay, this is clicking. So for my coffee shop: The null hypothesis is 'the new beans have no effect on ratings.' I collect ratings for the old and new beans. Because it's a small sample, I use a two-sample t-test. That gives me a t-score. If that score is really big, it means the change in average rating is significant compared to the random variation in ratings. Which gives me a tiny p-value, letting me reject the null and... celebrate my expensive new beans.

Jo

You've just perfectly described the entire workflow. That's it. That's the process. From question, to hypothesis, to choosing a test, to interpreting the result.

Beau

It's... actually pretty logical when you lay it out like that. It's a formal way of asking, 'Is this difference I'm seeing real, or am I just fooling myself?'

Jo

And that is one of the most important questions a data scientist can answer.