Inferencing the Data [R]

Week 13 · Chapter 13

Today’s Agenda

  • The Twitch job, part 3
  • What a test asks
  • Chi-square
  • The t-test
  • ANOVA
  • Regression
  • Your questions, your tests
  • The White Paper and its poster

What We Build Today

  • Four tests
    • Chi-square
    • The t-test
    • ANOVA
    • Regression
  • The checks that decide whether a result holds
  • A model write-up for each test
  • Two deliverables: the White Paper and its poster

The Twitch Job, Part 3

  • The Inferencing Data worksheet is part 3 of the Twitch job
  • Four hypotheses first, then four tests
  • Every test is reported with its effect size

Get the Worksheet

MC 501 worksheet · Inferencing Data risks guide

  • Click the link: your browser saves 13-inferencing-data-mc501.qmd in your Downloads folder
  • Move it into your workspace’s top folder, next to README.md: Put a Worksheet in Your Workspace

What a Test Actually Asks

  • Nobody cares about the 34,762 example messages as such
    • They were measured to learn about chat in general
  • The honest question is not whether a pattern exists in the sample
    • It is whether chance is an unconvincing explanation for that pattern
  • The test starts from the null hypothesis
    • The null hypothesis says there is no pattern: no link, no gap

How a Test Decides

  • Assume the null hypothesis is true: no real link or gap
  • Ask how often a pattern this big would show up anyway, by chance alone
  • That share is the p-value; a small one makes the null hard to believe

What Every Test Reports

p-value: how likely a pattern at least this big would be if the null hypothesis were true. Below .05 is called statistically significant.

Effect size: how big a difference or a relationship is, on a scale that does not grow with the sample. Example: Cramér’s V near 0 means two categories barely go together.

  • The p-value says whether chance explains the pattern; the effect size says how big it is

The Variables Choose the Test

  • Two categorical variables: chi-square
  • A numeric outcome across two groups: the t-test
  • A numeric outcome across three or more groups: ANOVA
  • Two numeric variables: linear regression
  • Write down the level of measurement of each variable first. The test follows from those two levels

The Variables Choose the Test (cont.)

  • A test on the wrong kind of data produces a meaningless number
  • Unsure? Write your choice down, then click the AURA Lab R Companion icon on VS Code’s left edge
  • Under Test, click Check my test choice
  • It says whether your choice fits these rules; it does not choose for you

Name the Variables First

  • In the R Companion panel, under Test, click Settings block (name the test variables), then Run it
  • It reloads data/twitch_analysis.RDS and keeps six columns under fixed names: outcome, group2, group3, predictor, cat_a, cat_b
  • Every test block the R Companion writes uses those names, so run this block first
  • For your own study, change only this block: put your own column after each =
  • These slides use the original column names; each test block writes the same test with the fixed names

Two Categories: Chi-Square

  • In the R Companion panel, under Test, Chi-square test with Cramer’s V writes this same test for cat_a and cat_b
asks <- analysis %>%
  mutate(has_question = str_detect(message,
                                   fixed("?")))

counts <- xtabs(~ has_question + channel_type,
                data = asks)
counts
chi <- chisq.test(counts)
chi
cramers_v(counts, adjust = FALSE)
  • Does a message contain a question mark (str_detect()), and does that depend on the kind of channel? xtabs() counts the grid

Two Categories: Chi-Square (cont.)

            channel_type
has_question gaming non-gaming
       FALSE  28804       3239
       TRUE    2501        218

    Pearson's Chi-squared test with Yates' continuity correction

data:  counts
X-squared = 12, df = 1, p-value = 0.0005321
  • X-squared is 12.00 on 1 df, p < .001; N is the four cells added up, 34,762
  • On a two-by-two grid R applies Yates’ correction; the worksheet’s three-by-two grid does not

Two Categories: Chi-Square (cont.)

Cramer's V |       95% CI
-------------------------
0.02       | [0.01, 1.00]

- One-sided CIs: upper bound fixed at [1.00].
  • Cramér’s V of 0.02 is negligible: significant, and close to no link at all
  • With 34,762 messages, a trivial pattern clears .05; the t-test shows the same thing next

Which Cells Drive It

round(chi$expected, 1)
round(chi$stdres, 2)
            channel_type
has_question gaming non-gaming
       FALSE 28856.4     3186.6
       TRUE   2448.6      270.4
            channel_type
has_question gaming non-gaming
       FALSE   -3.5        3.5
       TRUE     3.5       -3.5
  • expected: each cell’s count if the categories were unrelated; the smallest, 270.4, is well above 5
  • stdres: each cell’s standardized residual; beyond 2 or -2, the cell is off
  • Non-gaming chat holds fewer question-mark messages than expected (-3.5); on a two-by-two grid all four residuals share one size

Reporting the Chi-Square

Chapter 13, two categorical variables

Whether a message contained a question mark was associated with whether its channel was gaming, χ²(1, N = 34,762) = 12.00, p < .001, Cramér’s V = .02.

  • χ²(1, N = 34,762) = 12.00: the statistic, its df, and the number of messages
  • Cramér’s V = .02: the effect size, with no zero before the point because V never passes 1
  • Common mistake: leaving out N, or calling the link strong because p is tiny

The Gap and the Doubt

  • Message length is a number and gaming status has two groups, so the test is the t-test
  • In the example data, gaming channels averaged 28.49 characters per message, non-gaming channels 33.70
    • That is a difference of a little over five characters
  • The doubt about that gap is not idle
    • Split any group in two at random and the two averages differ
  • The gap could be real, or it could be ordinary sampling wobble

The histogram cannot tell the two apart, because both produce a gap.

Running the Test

  • In the R Companion panel, under Test, Welch t-test with Cohen’s d writes this same code with outcome and group2
  • cohens_d() comes from the effectsize package; v2v keeps the older run_t_test() as a deprecated shortcut, and this is the code you write
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)

The Output

# 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
  • FALSE is non-gaming and TRUE is gaming, in the order R sorts them, so the gap is non-gaming minus gaming: 33.70 minus 28.49, or 5.21
  • sd is each group’s spread, 60.68 against 38.47; keep those two numbers for the next slide

The Output (cont.)

    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
  • p-value = 8.077e-07 is scientific notation for 0.0000008077, reported as p < .001
  • The 95 percent confidence interval says the true gap most likely sits between 3.14 and 7.28 characters

Why Welch, and Not Student

  • The ordinary (Student) t-test assumes the two groups have equal spread
    • Week 12 showed standard deviations of 60.68 against 38.47
    • The Welch version drops that assumption, so it is the safer default

Reading t and df

  • t = 4.9418 measures the gap in units of its own noise
    • The sign shows direction only
  • df is not a round number because Welch computes it from both groups

Reading the p-value

  • If the two groups truly shared one mean length,
    • a gap this large would occur in fewer than one sample in a thousand
  • So the data are surprising under that assumption
  • A p-value below .05 counts as significant, and this one clears it easily

Chance alone is an unconvincing explanation for the gap. That is the entire content of the p-value.

What the p-value Does Not Say

  • It is not the probability that the null hypothesis is true
    • The null is either true or false. The p-value is a statement about the data
  • It is not the probability that the result is a fluke
  • It is not a measure of how large the difference is
  • It is not a measure of how much the difference matters

How Big Is the Difference

  • For a gap between two means, the effect size is Cohen’s d
    • It states the gap in units of the natural variation in the data
  • Cohen’s benchmarks: about 0.2 is small, 0.5 is medium, 0.8 is large (Cohen, 1988)
  • A d of 0.13 is below small, and the word for it is negligible

The Effect Size in the Output

Cohen's d |       95% CI
------------------------
0.13      | [0.09, 0.16]

- Estimated using pooled SD.
  • Cohen’s d measures the gap against how much message lengths vary: 0.13, with an interval from 0.09 to 0.16
  • 0.13 does not reach Cohen’s small: negligible
  • The sign of t and d follows the group order: gaming first, as in the write-up, gives -4.94 and -0.13
  • Missing values detected. NAs dropped. is a warning, not an error: the unlabeled messages were left out

Why a Negligible Gap Reached Significance

  • The raw gap is fifteen percent of the non-gaming mean, which does not sound negligible
  • But d measures that gap against standard deviations of 38 and 61 characters
  • And the sample held 34,762 messages

A large enough sample detects a difference far too small to care about.

On the Threshold Itself

“Scientific conclusions and business or policy decisions should not be based only on whether a p-value passes a specific threshold.”

Wasserstein & Lazar (2016, p. 131)

  • A p-value of .049 and one of .051 describe almost identical evidence
  • Ten tests run without correction produce one false positive on average
  • Declare your tests and your correction for multiple tests in advance

Exercise: Justify the Alpha

Lakens et al. (2018)

“we propose that researchers should transparently report and justify all choices they make when designing a study, including the alpha level.”

Lakens et al. (2018, p. 168)

  • A study compares gaming and non-gaming message length and calls p below .05 significant
  • What one sentence would justify .05 for this study, rather than leaving it as habit?

Retiring the Phrase

“it is time to stop using the term ‘statistically significant’ entirely.”

Wasserstein, Schirm, and Lazar (2019, p. 2)

  • Write your own result in one sentence without the phrase “statistically significant”
  • Then write down one thing the sentence lost and one thing it gained

Standard Error and the Interval

Standard error: how much an estimate, such as a group’s mean, would shift from one sample to the next. Example: a mean from a large group has a smaller standard error than one from a small group.

Confidence interval: a range around an estimate, built by a method that captures the true value in a stated share of repeated samples, such as 95 in 100. Example: a group’s mean plus or minus 1.96 standard errors gives its 95% interval.

  • A 95% interval does not mean a 95% chance that this one interval holds the true value

Seeing the Gap and Its Uncertainty

means_ci <- analysis %>%
  filter(!is.na(is_gaming)) %>%
  group_by(is_gaming) %>%
  summarize(
    mean = mean(message_length, na.rm = TRUE),
    se   = sd(message_length, na.rm = TRUE) / sqrt(n()),
    .groups = "drop"
  ) %>%
  mutate(lower = mean - 1.96 * se,
         upper = mean + 1.96 * se)

This code computes each group’s mean and standard error, then turns the standard error into a ninety-five percent confidence interval you can plot.

What the Intervals Show

  • The two confidence intervals are tiny, and they do not overlap
    • That is the visual signature of statistical significance
  • Both points still sit close together, far above zero
    • That is the negligible effect size made visible

Writing the Result Up

Gaming channels produced shorter chat messages on average than non-gaming channels (28.49 vs. 33.70 characters; n = 31,305 and 3,457), Welch’s t(3768.7) = -4.94, p < .001, Cohen’s d = -0.13.

  • In the R Companion panel, under Test, APA numbers to check your sentence prints these numbers from your own run
  • Check your sentence against it

Then Say It Plainly

The two kinds of channel do differ in message length, but so slightly that they are better thought of as alike than as different.

  • A reader who cannot follow the notation still has to be able to follow the claim
  • The R Companion’s APA numbers to check your sentence prints the numbers to check; the statistics line, the plain sentence, and the interpretation are yours to write

When p Is Above .05

set.seed(2026)
small <- analysis %>%
  filter(!is.na(is_gaming)) %>%
  slice_sample(n = 30)

small %>%
  count(is_gaming)
t.test(message_length ~ is_gaming, data = small)
cohens_d(message_length ~ is_gaming, data = small)
  • The same comparison, on 30 messages drawn at random instead of 34,762
  • set.seed() makes the random draw the same every time it runs

When p Is Above .05 (cont.)

# A tibble: 2 × 2
  is_gaming     n
  <lgl>     <int>
1 FALSE         4
2 TRUE         26

    Welch Two Sample t-test

data:  message_length by is_gaming
t = -1.7881, df = 27.665, p-value = 0.08473
  • p = .085 is above .05: this test cannot rule out chance
  • Four non-gaming messages against 26 gaming ones: the draw is lopsided, and nothing in the test fixes that

When p Is Above .05 (cont.)

Cohen's d |        95% CI
-------------------------
-0.39     | [-1.44, 0.68]

- Estimated using pooled SD.
  • The sign has even flipped: in this draw gaming messages run longer
  • d’s interval runs from -1.44 to 0.68, so the data fit a large gap either way, or none
  • A null result is reported in full, with the means, t, df, p, and d, and never as “no difference”

What Thirty Messages Could Detect

pwr::pwr.t2n.test(n1 = 4, n2 = 26,
                  sig.level = .05,
                  power = .80)
             n1 = 4
             n2 = 26
              d = 1.558841
      sig.level = 0.05
          power = 0.8
  • Leave d out and pwr solves for it: the smallest gap these group sizes detect 80% of the time
  • Here that is d = 1.56, far past large, so this sample could only have found a huge difference
  • Task 3.3 of the worksheet runs the same check on your thirty hand-coded messages

Four Groups, Four Means

game category       n     mean length
Fortnite          4000       33.23
Hearthstone       3004       36.82
Just Chatting     2429       39.03
League of Legends 4000       22.63
  • A t-test compares two means, and here there are four
  • Six pairwise t-tests would each carry their own false-positive chance, and those chances pile up

ANOVA

  • In the R Companion panel, under Test, One-way ANOVA with eta squared writes this same code, with Welch’s version, omega squared, and Tukey’s pairs after it
four_games <- analysis %>%
  filter(main_game == "Fortnite" |
         main_game == "Hearthstone" |
         main_game == "Just Chatting" |
         main_game == "League of Legends")

fit_anova <- aov(message_length ~ main_game,
                 data = four_games)
summary(fit_anova)
eta_squared(fit_anova)

ANOVA (cont.)

               Df   Sum Sq Mean Sq F value Pr(>F)
main_game       3   547281  182427   92.26 <2e-16 ***
Residuals   13429 26552407    1977
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  • main_game is the channel’s usual category, the one the gaming label was built from
  • Df is 3 for the groups (four minus one) and 13429 for the messages left over
  • Pr(>F) is the p-value: <2e-16 means smaller than R will print, so p < .001; the *** is R’s star code for it

Reading F, Then Eta Squared

Parameter | Eta2 |       95% CI
-------------------------------
main_game | 0.02 | [0.02, 1.00]

- One-sided CIs: upper bound fixed at [1.00].
  • F compares the variation between the group means against the variation within the groups
    • If all four groups shared one mean, F would sit near one
    • Here F(3, 13429) = 92.26, with a minuscule p-value
  • League of Legends at 22.63 characters runs visibly shorter than Just Chatting at 39.03
  • Eta squared is 0.02: game category accounts for two percent of the variation in message length

The Assumptions Underneath

  • ANOVA and ordinary regression assume homoscedasticity: equal spread in every group, which Week 12 showed these groups lack
  • Welch’s ANOVA, oneway.test(), drops that assumption, so it is the safer choice over pooled aov()
oneway.test(message_length ~ main_game,
            data = four_games)
    One-way analysis of means (not assuming equal variances)

data:  message_length and main_game
F = 151.05, num df = 3.0, denom df = 6341.7, p-value < 2.2e-16
  • If the two disagree, the assumption was doing real work; report the robust one

Omega Squared

omega_squared(fit_anova)
Parameter | Omega2 |       95% CI
---------------------------------
main_game |   0.02 | [0.02, 1.00]

- One-sided CIs: upper bound fixed at [1.00].
  • Eta squared is a little optimistic in small samples; omega squared corrects for that
  • Here the two agree at 0.02, which is what a sample of 13,433 messages buys you
  • Report whichever one your field expects, and say which

Which Pair Actually Differs

  • A significant ANOVA says that some pair of groups differs, not which pair
  • Naming the pairs takes post-hoc comparisons, and Tukey’s test, TukeyHSD(), is the standard one
    • It corrects for the multiple comparisons you are making
    • Six separate t-tests would lack that correction
  • Report the adjusted p-values, p adj, not the raw ones
TukeyHSD(fit_anova)

Which Pair Actually Differs (cont.)

  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = message_length ~ main_game, data = four_games)

$main_game
                                      diff         lwr        upr     p adj
Hearthstone-Fortnite              3.588237   0.8299016   6.346572 0.0046236
Just Chatting-Fortnite            5.798935   2.8600549   8.737816 0.0000024
League of Legends-Fortnite      -10.605000 -13.1596944  -8.050306 0.0000000
Just Chatting-Hearthstone         2.210698  -0.9068277   5.328224 0.2629221
League of Legends-Hearthstone   -14.193237 -16.9515724 -11.434902 0.0000000
League of Legends-Just Chatting -16.403935 -19.3428158 -13.465055 0.0000000
  • Each row is one pair: diff is the gap in characters, lwr and upr its interval, and p adj the corrected p-value
  • Five of the six pairs differ; Just Chatting and Hearthstone do not (p adj 0.26)
  • With eta squared at 0.02, the separations are clean and small

Reporting the ANOVA

Chapter 13, more than two groups

Mean message length differed across the four game categories (N = 13,433), F(3, 13429) = 92.26, p < .001, η² = .02. Tukey’s HSD showed that five of the six pairs differed; Just Chatting and Hearthstone did not (p = .26).

  • F(3, 13429): categories minus 1, then messages minus categories
  • η² = .02: game category accounts for about two percent of the variation
  • Common mistake: naming which pairs differ from F alone; the Tukey line does that

What Regression Is

Regression: a model that estimates how an outcome variable changes with one or more other variables. Example: predicting message length from the hour of the day.

A Number or a Category

Dummy variable: a category recoded as 0 and 1 so a regression can use it. Example: non-gaming is 0 and gaming is 1.

  • The outcome is always a number, such as message length
  • A number as predictor: the slope is the change per one-unit step, such as characters per hour
  • A category as predictor: R turns it into a dummy, and the slope is the gap between the two group means
    • A category with k groups takes k - 1 dummies, each compared with one baseline group
  • In your worksheet and paper, regression takes two numbers; a category goes to the t-test or ANOVA

Regression Re-Derives the t-test

  • In the R Companion panel, under Test, Linear regression writes lm(outcome ~ predictor), and the Settings block keeps predictor a number (the hour of the day)
  • Pick linear regression for a number and a category, and Check my test choice says it does not fit
  • The code below gives lm() the gaming dummy only to show what a t-test is underneath
fit_lm <- lm(message_length ~ is_gaming, data = analysis)
summary(fit_lm)
standardize_parameters(fit_lm)

Regression Re-Derives the t-test (cont.)

Call:
lm(formula = message_length ~ is_gaming, data = analysis)

Residuals:
   Min     1Q Median     3Q    Max
-32.70 -21.49 -12.49   6.30 471.51
  • Call repeats the model you asked for
  • Residuals summarize how far each message falls from its group’s mean; they are not the part to read

Regression Re-Derives the t-test (cont.)

Coefficients:
              Estimate Std. Error t value Pr(>|t|)
(Intercept)    33.7023     0.7010  48.077  < 2e-16 ***
is_gamingTRUE  -5.2122     0.7387  -7.056 1.75e-12 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  • (Intercept), 33.70, is the non-gaming mean
  • is_gamingTRUE is the dummy (gaming is 1); its slope, -5.21, is exactly the gap the t-test found, written as a baseline plus an adjustment
  • Pr(>|t|) is each row’s p-value; 1.75e-12 reads as p < .001

Regression Re-Derives the t-test (cont.)

Residual standard error: 41.22 on 34760 degrees of freedom
  (505 observations deleted due to missingness)
Multiple R-squared:  0.00143,   Adjusted R-squared:  0.001401
F-statistic: 49.79 on 1 and 34760 DF,  p-value: 1.747e-12
  • Multiple R-squared: 0.00143 is the share of the variation the model explains
  • 505 observations deleted are the unlabeled messages

The Standardized Slope

# Standardization method: refit

Parameter        | Std. Coef. |         95% CI
----------------------------------------------
(Intercept)      |       0.11 | [ 0.08,  0.15]
is gaming [TRUE] |      -0.13 | [-0.16, -0.09]
  • standardize_parameters(), from effectsize, puts the slope in standard deviations of the outcome
  • -0.13 means gaming messages sit 0.13 standard deviations of message length below non-gaming, close to Cohen’s d (also -0.13), which divides by the within-group spread instead
  • With a yes/no predictor that is all it means; with a number predictor, as in the worksheet, it is the change per standard deviation of the predictor

One Framework, Three Faces

  • A t-test is a regression with one dummy variable: two groups
  • An ANOVA is a regression with k - 1 dummies: three for the four games
  • Regression is the general form of both
    • Its t differs from Welch’s because regression pools the two spreads
    • The coefficient itself is identical
    • R² is about 0.001, so gaming status accounts for almost none of the variation

All three are the general linear model, wearing three different names.

Residuals

Residual: the gap between a real value and the value the model predicts for it. Example: if the model predicts 29 characters and the message has 400, the residual is 371.

  • A model’s credibility rests on its residuals; plot(fit_lm) draws four diagnostic plots of the Linear regression block’s model
    • Residuals against fitted values: checks linearity and equal spread
    • A Q-Q plot: checks whether the residuals are normally distributed
    • Leverage: checks whether one point is carrying the result

Whether a Variable Earns Its Place

  • Whether an added variable earns its place in the model is a model-comparison question
    • Compare adjusted R², AIC, or a nested F-test, never raw R²

Reporting the Regression

Chapter 13, from difference to model

Gaming status, coded 1 for gaming and 0 for non-gaming channels, was associated with message length, b = -5.21, SE = 0.74, t(34760) = -7.06, p < .001, R² = .001.

  • Coded 1 and 0: gaming status is a dummy variable, so the slope is the gap between the groups
  • b = -5.21: the slope, in characters; R² = .001: the share of variation it explains
  • Common mistake: writing that gaming causes shorter messages; a slope describes an association
  • In the worksheet the predictor is a number, so the slope is characters per hour; the sentence keeps this shape

Discrete or Continuous

Discrete (categorical): each value is a category you count, not a number you average. Example: gaming or non-gaming, or a code from your codebook.

Continuous (numeric): each value is a measured number where an average makes sense. Example: message length in characters.

  • A code stored as a number is still discrete

Which Test Fits

Outcome Other variable Test
Discrete Discrete Chi-square, with Cramér’s V
Continuous Two groups Welch t-test, with Cohen’s d
Continuous Three or more groups One-way ANOVA, with eta squared
Continuous Continuous Linear regression, with R²
One variable alone None Counts and percents, no test
  • In your paper, regression takes two numbers. A category goes to the t-test or ANOVA

Exercise: Your Questions, Your Tests

  • Download the RQ and hypothesis worksheet (Word)
  • Copy each research question or hypothesis from your Research Proposal into it, word for word
  • For each one, which test fits? Name its variables, mark each discrete or continuous, then pick from the table
  • Check each pick: in the R Companion panel, under Test, click Check my test choice
  • Only one variable? When Your Question Has One Variable

The White Paper and Its Poster

  • The White Paper: IMRaD, one citation style used consistently, with effect sizes, confidence intervals, and power statistics
    • Its Methods carry three transparency markers: data provenance, the reliability report, and the pre-registration disclosure, citing the dated file in your repository
    • Its Discussion situates the finding in your theoretical literature

The White Paper and Its Poster (cont.)

  • The poster: appropriately large (48 by 36 inches recommended), landscape, from title to implications
    • A QR code to your pre-registration or portfolio
    • Your ninety-second pitch, built from one or two figures
  • Due Friday, December 18, 11:59 PM: White Paper and conference poster, 200 points: one ZIP file holding the paper PDF, the poster PDF, and your AI-use log, plus the live URL of your site pasted into the submission

Before Week 15

Before Week 15 (cont.)

Before Week 15 (cont.)

Questions, Comments, or Concerns?