Inferencing Data: Testing Relationships
The graded work for this chapter is Inferencing Data in R (MC 501). Get the worksheet, the guide, and the rubric there.
Describing data tells you what is. Inferencing tells you what it means, specifically, whether the patterns you see are real or could have happened by chance.
This chapter walks you through a chi-square test of independence, the statistical test you’ll use to determine whether two categorical variables are related. You’ll also learn to calculate effect size (Cramér’s V), interpret standardized residuals, and write your findings in two registers: formal APA and plain-English “journalist translation.”
Steps on this page
The Big Question
Look at the stacked bar chart from Chapter 5. The mix of gaming and non-gaming channels appears to differ across audience-size bands. But is that difference real, or is it just noise in the data?
This is what statistical inference answers. We set up a test, let the math run, and then interpret the result.
There is not one hypothesis test. There are many, and which one applies depends on the kind of data in hand. Two categorical variables call for a chi-square test, which is what this chapter runs. One continuous outcome across two groups calls for a t-test, which appears later in the chapter. Three or more groups call for an ANOVA. A test applied to the wrong kind of data still produces a number, and the number is meaningless. Before you run anything, run AURA: Check my test choice from the Command Palette: it asks about your variables and says whether the test fits. The reason is yours to write.
Step 1: State Your Hypotheses (Before Any Code)
Write your hypotheses before you run any code. This is not optional. It’s how science works. You decide what you’re testing, then test it. You don’t look at the results and then decide what you were testing.
Every chi-square test has two hypotheses:
Null Hypothesis (H₀): There is no relationship between the two variables. Any differences you see are due to chance.
H₀: There is no association between a channel’s audience-size band and whether it is a gaming channel.
Alternative Hypothesis (H₁): There is a relationship between the two variables. The differences are too large to be explained by chance alone.
H₁: There is an association between a channel’s audience-size band and whether it is a gaming channel.
The chi-square test evaluates how much the observed data differs from what you’d expect if H₀ were true.
Step 2: Build the Contingency Table
library(tidyverse)
library(v2v)
library(effectsize)
analysis <- read_rds("data/twitch_analysis.RDS")
tested <- analysis %>%
filter(!is.na(channel_type), !is.na(viewer_band))A contingency table is the raw input for the chi-square test. It shows the count for every combination of your two variables, and the count() and pivot_wider() pipe from Chapter 5 prints it:
tested %>%
count(viewer_band, channel_type) %>%
pivot_wider(names_from = channel_type, values_from = n, values_fill = 0)# A tibble: 3 × 3
viewer_band gaming `non-gaming`
<fct> <int> <int>
1 small 25309 2457
2 medium 4000 1000
3 large 2000 0
Look at that bottom-right cell before running anything. Not one message in the sample comes from a large non-gaming channel. That zero is a real feature of this corpus, not a coding error, and it is doing a lot of the work in the test you are about to run. Say so when you report the result.
Chapter 5’s second pipe, group_by(viewer_band) then mutate(share = round(n / sum(n), 3)) after the count(), prints the proportions, each band’s share of its own messages. This helps you see the pattern before running the test. Look at the proportions. Do the audience-size bands differ in their gaming and non-gaming mix? If every band had roughly the same proportions, there would be no association. If they differ, the chi-square test will tell you whether that difference is statistically significant.
Step 3: Run the Chi-Square Test
The test functions want the table as a base R object, and xtabs() builds one from a formula: the two variables after the ~. sum() of that table is the sample size, chisq.test() runs the test, and cramers_v() from the effectsize package adds the effect size.
counts <- xtabs(~ viewer_band + channel_type, data = tested)
sum(counts)
chi <- chisq.test(counts)
chi
cramers_v(counts, adjust = FALSE)[1] 34766
Pearson's Chi-squared test
data: counts
X-squared = 822.66, df = 2, p-value < 2.2e-16
Cramer's V | 95% CI
-------------------------
0.15 | [0.14, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
[1] 34766 is N, the number of messages in the table. The test result is saved as chi so that Step 5 can pull the expected counts and residuals out of it; typing chi on its own line prints it. AURA: Write R code, under R4 Test, writes these same lines. (Older worksheets called run_chi_square(); v2v keeps it as a deprecated shortcut.)
Reading the Output
The test gives you three numbers:
| Value | What It Means |
|---|---|
| X-squared (χ²) | How much the observed data deviates from what you’d expect under H₀. Bigger = more deviation. |
| df | Degrees of freedom, based on the table dimensions: (rows - 1) × (columns - 1) |
| p-value | The probability of seeing data this extreme if the null hypothesis were true |
Interpreting the p-value
The p-value is the most important number, and the most misread number in statistics. Here’s what it means in plain terms:
- p < .05: The pattern is statistically significant. The probability of seeing this result by chance (if there’s really no relationship) is less than 5%. We reject H₀.
- p ≥ .05: The pattern is not statistically significant. We cannot reject H₀. This doesn’t prove there’s no relationship, just that we don’t have enough evidence to claim one.
Be precise about what the p-value does not say. It is not the probability that the null hypothesis is true. It is not the probability that the result is a fluke. And it is not a measure of how large the difference is. A small p-value says the pattern is probably not nothing. It says nothing at all about whether the pattern is big.
Read the three numbers off the output above. The chi-square statistic is 822.66 on 2 degrees of freedom, and the p-value, < 2.2e-16, is smaller than R will print, so report it as below .001, far under .05. The result is significant, so you reject the null hypothesis: there is evidence of an association between audience size and channel type.
It has no deep justification. A p-value of .049 and one of .051 describe almost identical evidence, and treating one as a discovery and the other as a non-event is a habit the field is right to question. Report the exact p-value, not just whether it cleared the bar.
Step 4: Calculate Cramér’s V (Effect Size)
Statistical significance tells you whether there’s a relationship. Effect size tells you how strong it is. A significant result with a tiny effect size means the relationship is real but practically unimportant.
Cramér’s V ranges from 0 (no association) to 1 (perfect association). cramers_v(counts, adjust = FALSE) reports it with a 95% interval; the upper bound of 1.00 is the package’s one-sided convention, not a finding. Use the benchmarks below for the word that goes with the number.
Effect Size Benchmarks (Cohen’s Guidelines)
| Cramér’s V | Interpretation |
|---|---|
| .10 | Small effect |
| .30 | Medium effect |
| .50 | Large effect |
A small effect means the relationship exists but is weak. A large effect means the variables are strongly associated. Most social science research finds small-to-medium effects, and that’s normal and expected.
Here Cramér’s V is 0.15. That is above .10 and below .30, so by the benchmarks above the association is small.
In the R Companion, AURA: Write R code, under R4 Test, writes the chi-square with Cramér’s V, the Welch t-test with Cohen’s d, the ANOVA with eta squared, and the regression into your script, as the same real code this chapter shows. Its APA numbers to check your sentence prints a test’s numbers in APA form; the sentence, and the journalist translation, are yours to write.
The chat sample runs to tens of thousands of messages. With a sample that large, a hypothesis test will detect associations far too small to care about. This is the single most important habit to build: report the effect size next to the p-value, every time. Significance and size are different questions, and big samples pull them apart.
Step 5: Standardized Residuals
The chi-square test tells you there’s a relationship (or not), but it doesn’t tell you which specific combinations are driving it. Standardized residuals do.
A standardized residual tells you, for each cell in the table, how much the observed count differs from what you’d expect:
- Residual > 2: This cell has more observations than expected (strong positive contribution)
- Residual < -2: This cell has fewer observations than expected (strong negative contribution)
- Residual between -2 and 2: This cell is roughly what you’d expect
Both come out of the saved test result: chi$expected holds the counts the null hypothesis predicts for each cell, and chi$stdres holds the standardized residuals. round() trims the decimals.
round(chi$expected, 1)
round(chi$stdres, 2) channel_type
viewer_band gaming non-gaming
small 25005.1 2760.9
medium 4502.8 497.2
large 1801.1 198.9
channel_type
viewer_band gaming non-gaming
small 13.58 -13.58
medium -25.68 25.68
large 15.31 -15.31
The first grid is the expected counts. The chi-square test is trustworthy when every expected count is at least 5, and the smallest here, 198.9 in the large non-gaming cell, clears that easily. The second grid is the residuals, and beyond 2 or -2 in either direction is what drives the result. These are the combinations driving the result. The large, non-gaming cell holds no messages at all, far fewer than chance would put there, so its residual is negative: the biggest channels in this corpus are all gaming channels.
When the Outcome Is Continuous: The t-test
Chi-square needs two categorical variables. The study’s central question pairs a categorical split with a continuous outcome: is message_length different on gaming and non-gaming channels? A continuous outcome compared across two groups is the textbook setting for the t-test.
Three steps: print the two groups side by side, run the test, and add the effect size. The filter() keeps the messages that have both a length and a gaming label, so the n column matches what the test uses.
analysis %>%
filter(!is.na(message_length), !is.na(is_gaming)) %>%
group_by(is_gaming) %>%
summarize(n = n(), mean = mean(message_length), sd = sd(message_length))
t.test(message_length ~ is_gaming, data = analysis)
cohens_d(message_length ~ is_gaming, data = analysis)# A tibble: 2 × 4
is_gaming n mean sd
<lgl> <int> <dbl> <dbl>
1 FALSE 3457 33.7 60.7
2 TRUE 31305 28.5 38.5
Welch Two Sample t-test
data: message_length by is_gaming
t = 4.9418, df = 3768.7, p-value = 8.077e-07
alternative hypothesis: true difference in means between group FALSE and group TRUE is not equal to 0
95 percent confidence interval:
3.144345 7.280115
sample estimates:
mean in group FALSE mean in group TRUE
33.70234 28.49011
Cohen's d | 95% CI
------------------------
0.13 | [0.09, 0.16]
- Estimated using pooled SD.
FALSE is the non-gaming group and TRUE the gaming group, printed in the order R sorts them, so the difference is non-gaming minus gaming: 33.70 minus 28.49, or 5.21 characters. In the t.test() block, t is the test statistic, df is the degrees of freedom, p-value = 8.077e-07 is scientific notation for 0.0000008077, and the 95 percent confidence interval says the true gap most likely sits between 3.14 and 7.28 characters. cohens_d() prints the effect size with its own interval, and its NAs dropped warning only says the unlabeled messages were left out. AURA: Write R code, under R4 Test, writes these same lines. (Older worksheets called run_t_test(); v2v keeps it as a deprecated shortcut.)
Read that output slowly, because it is the whole lesson of this chapter in one block.
The test is a Welch t-test, and the choice is deliberate. The ordinary t-test assumes the two groups have the same spread, and Chapter 5 showed plainly that they do not: the non-gaming standard deviation of 60.68 is far larger than the gaming standard deviation of 38.47. Welch’s version drops that assumption, which makes it the safer default whenever two groups might vary by different amounts.
The p-value is below .001 (report 8.077e-07 that way). If the two kinds of channel truly had the same mean message length, a gap this large would turn up less than one time in a thousand. Chance is an unconvincing explanation.
And the effect size, Cohen’s d of 0.13 with an interval from 0.09 to 0.16, says the difference is negligible. Cohen’s benchmarks put a d of 0.2 at small, 0.5 at medium, and 0.8 at large, so 0.13 does not even reach small. The raw gap is about five characters, roughly fifteen percent of the non-gaming average, and fifteen percent does not sound negligible. But Cohen’s d measures the gap against how much the data naturally vary, and message lengths vary enormously, with standard deviations of thirty-eight and sixty-one characters. Five characters set against that much variation is a ripple.
So how did a negligible difference come back significant? Sample size. The test ran on 34,762 messages, every labeled message with a length. A large enough sample will make almost any difference, however tiny, statistically significant. Both halves of the finding are true, and a report giving only the first half would mislead.
ANOVA, when the split has more than two groups. Restrict the data to the four largest values of main_game, the channel’s usual category, and summary(aov(message_length ~ main_game, data = four_games)) returns F(3, 13429) = 92.26, p < 2e-16. Group by game, the category at each message, and you get a different and wrong answer with no error. The categories do not all share a mean. And the effect size, eta-squared, is 0.02: category explains about two percent of the variation in message length. The same honest pair of facts the t-test forced.
Linear regression, when you want a model rather than a comparison. summary(lm(message_length ~ is_gaming, data = analysis)) returns an intercept of 33.70, the mean for the reference group (non-gaming), and a coefficient on is_gamingTRUE of -5.21, which is exactly the gap the t-test found. That is not a coincidence: a t-test is a regression with one two-level predictor, and an ANOVA is a regression with one many-level predictor. All three belong to one framework, the general linear model.
Step 6: Write It Up, APA Format
The American Psychological Association (APA) format is one widely used style for reporting statistical results, and the one this template follows:
A chi-square test of independence was conducted to examine the relationship between [Variable 1] and [Variable 2]. The analysis revealed a [significant/non-significant] association, χ²([df]) = [X.XX], p [< .001 / = .XXX]. The effect size was [small/medium/large] (Cramér’s V = [.XXX]). Examination of standardized residuals indicated that [specific finding about which cells deviated from expected values].
To check the numbers in your sentence, run AURA: Write R code and, under R4 Test, select APA numbers to check your sentence, then Run it. It prints the test’s numbers in APA form.
A t-test result is written up the same compact way. Here is the message-length finding, in the form a journal expects:
Gaming channels produced shorter chat messages on average than non-gaming channels (28.49 vs. 33.70 characters), Welch’s t(3768.7) = 4.94, p < .001, Cohen’s d = 0.13, a negligible difference.
Step 7: The Journalist Translation
This is the most important paragraph you’ll write in this assignment, and arguably in the entire course. Communication students need to explain statistics to people who have never taken a research methods class.
The rule: No jargon. No p-values. No chi-square. No “statistically significant.” Just plain English.
Template:
This analysis asked whether [plain-English version of the research question]. After examining [sample size] [items], the data [showed/did not show] a clear pattern: [describe the key finding in concrete terms]. In practical terms, this means [so-what statement, why does this matter?].
Example:
This analysis asked whether people type differently in the chat of a gaming stream than in the chat of a non-gaming one. After examining nearly 35,000 messages from fifty Twitch channels, the data showed a difference so small it barely counts: messages on non-gaming channels ran about five characters longer on average, roughly one short word. The typical message was the same length in both places. What separates the two is a handful of unusually long messages on the non-gaming side, not any everyday difference in how people talk. For anyone building tools around chat, this suggests the two kinds of channel are better thought of as alike than as different.
Notice what that paragraph does. It reports the real difference, it refuses to inflate it, and it tells the reader what the study actually found. A translation that said “gaming and non-gaming chat differ significantly” and stopped there would leave a reader picturing a real divide between two communities. There is a divide, and it is almost too small to see.
The statistics paragraph is for researchers. The journalist translation is for everyone else. You need both in your assignment and in your White Paper. Being able to write in both registers is what makes a communication researcher different from a statistics student.
Try It Yourself
These exercises map directly to the Inferencing Data [R] assignment:
Write your hypotheses for the audience-size by channel-type relationship before looking at any output.
Build a contingency table and its proportional version. Which band has the most extreme mix?
Run the chi-square test. Report the χ², df, and p-value.
Calculate Cramér’s V and interpret its magnitude using Cohen’s benchmarks. Then check your work against the output above.
Examine standardized residuals. Which band-by-type combinations are driving the result? Why do you think that might be?
Run the t-test on
message_lengthbyis_gamingand confirm you reproduce the output above. Then explain, in one sentence, how a result can be significant and negligible at the same time.Write the APA results paragraph using the template above.
Write the journalist translation, explaining the finding to someone who has never taken a statistics course.
For your White Paper, you’ll run this test on your own variables. The code is the same. Only the variable names change. Your Results section needs both the frequency table and chart from Chapter 5 and the test from this chapter. Together, they tell the complete story: here’s what the data looks like (descriptive) and here’s what it means (inferential).