The Chi-Square Test: What It Measures and How to Use It

UPI Study › Courses › Marketing Research › Free lessons › Lesson 11.1 Free lesson

The Chi-Square Test: What It Measures and How to Use It

Marketing Research · Chapter 11: Hypothesis Testing and Inferential StatisticsSection 11.1 · lesson 75 of 10112 min · free to watch

← Descriptive vs. Inferential Statistics: What They Are and When to Use EachNext lesson: Understanding t-Tests: Assessing Statistical Differences Between Groups →

Earn 3 college credits for Marketing ResearchRecommended for credit by NCCRS · Marketing 300 · self-paced · one payment, lifetime access

In this lesson

Test hypotheses with p-values and the chi-square test of independence.

  • Explain the logic of hypothesis testing, p-values and the significance level alpha
  • Distinguish Type I errors from Type II errors and describe power
  • Run a chi-square test of independence on a cross-tab and interpret the result
  • Check the expected-count assumption before trusting a chi-square p-value

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (1,587 words). Read along, or search it.

Opening Question

Sixty Heads in a Hundred Flips

You flip a coin 100 times, and it lands heads 60 times. Is the coin cheating? Or is that just luck? Most people feel a flicker of suspicion at 60, and none at 52. So where does suspicion turn into evidence? Statisticians built a whole toolbox, to answer that question honestly.

Leo has the same worry about his data. Fernway Snacks is a composite case built for teaching. Leo works there, with Grace and Nadia. Online shoppers seem keener on Fernway's new bar, than corner-store shoppers. Is that a real pattern? Or a lucky roll of the dice? This lesson gives you the steps to decide.

Hypotheses

Assume Nothing Is Going On

First, the logic: assume nothing is going on. Hypothesis testing is a courtroom, for data. The suspect is, "nothing special is happening." We keep that assumption, unless the evidence is strong enough to make it hard to believe.

Two statements are always on the table. The null hypothesis, written H0, says nothing special is going on. The coin is fair. The two groups are the same. The two things are unrelated.

The alternative hypothesis, written H1, or Ha, says something is going on. The coin is biased. The groups differ. The things are related.

The coin shows the logic best. Assume the null hypothesis: the coin is fair. Then ask a question. How often would a fair coin give a result at least as lopsided as 60 heads? Instead of trusting a formula, let Python flip the fair coin 10,000 times, in batches of 100.

P-Value

How Often a Fair Coin Looks This Lopsided

Most runs of a fair coin land near 50 heads. But the tails of the picture are not empty. 297 runs gave 40 heads or fewer. 270 runs gave 60 or more. In all, 567 of the 10,000 runs were this lopsided, or worse.

A result of 60 or more, or 40 or fewer, shows up about once in every 18 runs. That share, 0.057 in the simulation, and 0.0569 exactly, is the p-value.

Read that definition slowly. The p-value is the probability of getting a result at least as extreme as ours, if the null hypothesis were true. It is not the probability that the coin is fair.

Before the experiment, we also fix a cutoff. It is called alpha, the significance level, and it is almost always 0.05. If the p-value is at or below alpha, we reject the null hypothesis, and call the result statistically significant. If it is above alpha, we fail to reject the null hypothesis.

Common Mistake

What a P-Value Does Not Say

Here, p equals 0.057. That is a hair above 0.05. So 60 heads is not quite enough, to call the coin unfair. Notice the careful wording. Failing to reject does not show that the coin is fair. It only says the evidence fell short.

Here is a common mistake. Someone reads p equals 0.04, as a four percent chance that the null hypothesis is true. Or p equals 0.30, as a thirty percent chance that the result is luck. Both readings are wrong.

A p-value is computed, assuming the null hypothesis is true. So it cannot also be the probability that the null hypothesis is true. It only says how surprising the data would be, in a world where nothing is going on.

Two Errors

False Alarms and Missed Links

Next: two ways to be wrong. Because we decide from a sample, we can be wrong in two different ways. Each one has a name. Picture a grid. Across the top, the truth, which nobody sees. Down the side, our decision.

If the null hypothesis is true, and we keep it, we are correct: no false alarm. If a real link exists, and we reject the null hypothesis, we are correct again: a real link is found. The other two boxes are the errors.

A Type I error rejects a true null hypothesis. It is a false alarm. Its chance is alpha. So with alpha at 0.05, we accept a five percent false-alarm risk, when nothing real is happening.

A Type II error keeps a false null hypothesis. It means we miss a real link. Its chance is called beta, and it falls when the sample is larger. And power, one minus beta, is the chance of finding a real link.

Error Trade-Off

Why Alpha Is a Compromise

What does this mean for Fernway? A Type I error means launching a new package, because shoppers "prefer" it, when they do not. A Type II error means shelving a package that shoppers truly prefer.

So why not set alpha very low? Because there is a trade. Lower alpha, and false alarms fall. But the chance of a miss goes up. That is why 0.05 is a compromise, rather than a law of nature. These two ideas, and the p-value, are used unchanged, in every test that follows.

Test of Independence

Channel and Repeat Buying in 300 Shoppers

Now, the chi-square test of independence. The coin had one variable. Leo's question links two categories. Where does a shopper usually buy? And would they buy again? Grace collects 300 shoppers, invented for teaching, and builds a cross-tab, from lesson 10.4. Each cell is a count.

Here are the observed counts. First, online. 62 yes, and 38 no. Next, the grocery. 57 yes, and 63 no. Then, the corner store. 31 yes, and 49 no. The yes rates are 62 percent online, 47.5 percent at the grocery, and 38.8 percent at the corner store.

First, the hypotheses, in words. The null hypothesis: channel and buying again are unrelated. The share who would buy again is the same in every channel. The alternative: they are related. In symbols, the null says the variables are independent. The alternative says they are not. Alpha is 0.05.

Formula

Expected Counts and Degrees of Freedom

Now the formula, in words. For every cell, take the observed count, minus the count we would expect if nothing were going on. Square it. Divide by the expected count. Then add up all the cells.

O is the observed count in a cell. E is the expected count in that cell. And the expected count is the row total, times the column total, divided by the grand total.

The test also needs degrees of freedom. They are the number of rows minus one, times the number of columns minus one. Here, two rows and three columns give one, times two. That is 2 degrees of freedom.

Why expected counts like these? If channel did not matter, half of every channel would say yes, because 150 of the 300 said yes overall. So the online column's 100 shoppers would split 50 and 50.

Test Statistic

A Value of 10.11 Beyond the 5.991 Cutoff

The expected counts are 50, 60 and 40, in each row. The smallest, 40, is comfortably above five. Now compare them with what Grace saw, in the yes row. Online: expected 50, observed 62. Grocery: expected 60, observed 57. Corner store: expected 40, observed 31.

Online shoppers say yes more often than expected. At the corner store, shoppers say yes less often. The test asks one thing. Are gaps this big, just luck?

The statistic is 10.11. A statistic near zero means the observed counts hug the expected ones. A large value means they are far away. To judge "large," we compare it with the chi-square curve, for 2 degrees of freedom.

On that curve, the cutoff that cuts off the top five percent is 5.991. Our 10.11 lands well inside that red region. The p-value is 0.0064.

Decision. The p-value of 0.0064 is below 0.05. And 10.11 is above 5.991. So we reject the null hypothesis.

Interpretation

Strong Evidence, Not Proof of Cause

What does that mean for Fernway? The rates of buying again really do differ by channel. A gap this large would be rare, if channel did not matter. The printed cell contributions show which cells pull the statistic up most. The online cells give 2.88 each. The corner-store cells give 2.025 each.

But be careful. The test does not say how big the effect is. And it does not say that channel causes it, as lesson 6.4 warned. Online shoppers might simply be younger.

Nadia asks Grace, "Did the test prove online shoppers like the bar more?" The colleague smiles. "It says a gap this big would show up about once in 150 tables, if channel made no difference. That is strong evidence, not proof. And it does not say why." The interviewer records both lines.

Pro Tip

Expected Counts of Five or More

A pro tip. Check the assumption, before trusting the p-value. Every expected count should be at least five. Check the expected counts, not the observed ones. If a cell falls short, combine similar categories, such as merging two small age groups. Or collect more data.

Try it yourself. In the Python file, replace the table with a new one: 52, 57, 41 in the yes row, and 48, 63, 39 in the no row. It still has 300 shoppers and the same totals. But the channel gap is much smaller. Guess first. Will the p-value rise, or fall? Then run it, and see.

Key Takeaways

The Testing Steps in Brief

Key takeaways. Assume the null hypothesis, that nothing is going on. Measure how surprising the data would be. Reject the null only when the p-value is at or below alpha. A Type I error is a false alarm. A Type II error means missing a real link. For a table of counts, the chi-square statistic adds up observed minus expected, squared, over expected, across all cells. Compare it with the chi-square curve, with rows minus one, times columns minus one, degrees of freedom. And remember: expected counts of five or more.

Next, in lesson 11.2, you will use t-tests to compare the average ratings of two groups, and of one group with a target. This lesson was made by UPI Study.

About Marketing Research at UPI Study

Marketing Research (Marketing 300) is a self-paced online course of 101 video lessons in 13 chapters, from consumer behavior, segmentation and the research process to qualitative methods, surveys and sampling, measurement, experiments, secondary and syndicated data, descriptive statistics, hypothesis tests, correlation and regression, research ethics and reports. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Principles of Marketing vs Marketing Research

Why take it here

Why students take Marketing Research with UPI Study

Turn customer questions into evidenceMarketing Research teaches how companies find out what customers want: defining the problem, interviews and focus groups, survey design and sampling, measurement scales, experiments, secondary and syndicated data, and data analysis from descriptive statistics to hypothesis tests, cross-tabs and regression, ending with the research report. It suits marketing and business degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Marketing Research carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About The Chi-Square Test: What It Measures and How to Use It

What does a chi-square test of independence tell you?
It tells you whether two categorical variables in a cross-tab are related, by comparing observed cell counts with the counts expected if they were unrelated. In a 300-shopper example, purchase channel and repeat buying give a chi-square of 10.11 with 2 degrees of freedom and a p-value of 0.0064, so independence is rejected. The test does not measure effect size or prove a cause.
How do you calculate expected counts for a chi-square test?
Multiply the cell's row total by its column total and divide by the grand total. If 150 of 300 shoppers said yes overall and a channel has 100 shoppers, its expected yes count is 150 times 100 divided by 300, or 50. Each expected count should be at least 5; if not, combine similar categories or collect more data.
What is a p-value in plain words?
A p-value is the probability of getting a result at least as extreme as the one observed, assuming the hypothesis of no effect, H0, is true. For 60 heads in 100 flips, p is about 0.057, so a fair coin lands at least that far from 50 heads, in either direction, roughly once in 18 tries. It is not the probability that H0 is true.
What is the difference between a Type I and a Type II error?
A Type I error rejects a true H0, a false alarm, and its probability is alpha, commonly 0.05. A Type II error fails to reject a false H0, missing a real effect, and its probability is beta. Lowering alpha cuts false alarms but raises the chance of misses, while a larger sample lowers beta and raises power, which equals 1 minus beta.

About the Marketing Research course

How many college credits is Marketing Research?
Marketing Research (Marketing 300) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Marketing Research cost and what is included?
$250, paid once, with lifetime access: all 101 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Marketing Research take?
It is self-paced with no deadlines. The 101 lessons total about 19 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Marketing Research.

101 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Marketing Research
3 credits · NCCRS
Enroll →