Describing the Data [R]

Week 12 · Chapter 12

Today’s Agenda

  • Coming up: what is due, and when
  • Finish Data Wrangling, due Monday: save your codes as a CSV, check the data folder, render, and upload
  • The Twitch job, part 2: the Describing Data worksheet
  • The grammar of graphics: every plot is built from the same three parts
  • Three chart types: a line chart, a bar chart, and a histogram
  • Effect sizes, and the design choices a figure must disclose
  • Figures other people can actually read

Upcoming Assignments

What Due Have done by
Data Wrangling in R, 50 points Mon, Nov 16, 11:59 PM Codes saved as a CSV tonight
Pre-registration file committed Mon, Nov 16, 11:59 PM Research Proposal revised first, if it needs it
Describing Data in R, 100 points Mon, Nov 23, 11:59 PM Started tonight, after Data Wrangling renders
Weekly reading journal Mon, Nov 16 and Mon, Nov 23, 11:59 PM The Week 12, then the Week 13 reading

No class Nov 25: Thanksgiving Break.

Upcoming Assignments (cont.)

What Due Have done by
Inferencing Data in R, 100 points Mon, Dec 7, 11:59 PM Taught Nov 18
Coded dataset pushed (White Paper dated step) Mon, Dec 7, 11:59 PM First coding pass done by Thu, Dec 3
Week 15 reading journal Mon, Dec 7, 11:59 PM The Week 15 reading
White Paper and conference poster, 200 points Fri, Dec 18, 11:59 PM Results built from your own data

Finish Data Wrangling

Where R Starts

list.files()
  • list.files() lists what is in the folder R started in
  • In your workspace, R starts in the folder open in VS Code
    • That folder’s name is at the top of the Explorer
    • It does not matter which file you run a line from

Where R Starts: Output

> list.files()
 [1] "_templates"              "00-check-your-setup.qmd"
 [3] "00_Inbox"                "01_Journal"
 [5] "02_Literature"           "03_Project"
 [7] "04_Resources"            "11-wrangling-data.qmd"
 [9] "data"                    "LICENSE"
[11] "README.md"
  • The same names as your Explorer: R started in the workspace’s top folder
  • data is in the list, beside README.md

No Data Folder?

  • Older copies of the workspace came without a data folder
  • Data Wrangling Task 0.2 makes it when you run that chunk
  • To make it by hand:
    1. In the Explorer, right-click the empty space below the file list (on a Mac, Control-click)
    2. Select New Folder…
    3. Type data and press Enter (Return on a Mac)
  • It worked if data sits beside README.md, not inside another folder

Save Your Codes as a CSV

Data Wrangling worksheet, Task 0.3

CSV: a table saved as plain text, one row per line, with a comma between each column.

  • R reads your codes from data/coding-form.csv, so the file must be a CSV
  • Google Sheets keeps your codes online, so you download them as a CSV
  • Then you move that file into the data folder and name it coding-form.csv
  • Keep the id column exactly as it is

Download It as a CSV

  1. In your coding sheet in Google Sheets, click File
  2. Point to Download
  3. Click Comma Separated Values (.csv)
  4. The file lands in your Downloads folder
  • Its name has the tab’s name added, such as coding-form - Sheet1.csv
  • You fix the name in VS Code, two slides from now

Download It: What You See

Google Sheets with a sheet named coding-form open. The File menu is open with Download highlighted, and its submenu lists Microsoft Excel (.xlsx), OpenDocument (.ods), PDF (.pdf), Web Page (.html), Comma Separated Values (.csv), and Tab Separated Values (.tsv). The pointer rests on Comma Separated Values (.csv).

Move It into the Data Folder

  1. In the VS Code Explorer, right-click the old coding-form.csv inside data, click Delete, and confirm
  2. Open your Downloads folder beside VS Code, as in Put a Worksheet in Your Workspace
  3. Drag the downloaded file onto the folder named data in the VS Code Explorer, and let go
  4. Right-click the file inside data, click Rename…, type coding-form.csv, and press Enter

Check the Coding Sheet in R

read_csv("data/coding-form.csv") %>%
  glimpse()
  • read_csv() reads a CSV file into a table
  • glimpse() prints how many rows and columns it has, and each column’s type
  • "data/coding-form.csv" means: start in the folder open in VS Code, go into data, open coding-form.csv
    • The folder open in VS Code is the name at the top of the Explorer
  • Run it from the worksheet or the R terminal: the start is the same

Check the Coding Sheet: Output

> read_csv("data/coding-form.csv") %>%
+   glimpse()
Rows: 30 Columns: 5
── Column specification ────────────────────────────────────────────────
Delimiter: ","
chr (2): channel, message
dbl (2): id, reaction_only
lgl (1): coder_notes

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 30
Columns: 5
$ id            <dbl> 16240927, 182383, 19530370, 12102429, 7123505, 2…
$ channel       <chr> "bobross", "bobross", "bobross", "bobross", "bob…
$ message       <chr> "press F to bring back bob", "BIG TREE", "CoolSt…
$ reaction_only <dbl> 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, …
$ coder_notes   <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …

When the Check Goes Wrong

  • Same line, when the downloaded file still has its long name
read_csv("data/coding-form.csv") %>%
  glimpse()

When the Check Goes Wrong: Output

> read_csv("data/coding-form.csv") %>%
+   glimpse()
Error: 'data/coding-form.csv' does not exist in current working directory ('C:/Users/you/Documents/mc501-workspace').
  • does not exist: no file in data has exactly that name
  • The folder in brackets is the one open in VS Code; yours shows your own

Find the Name It Has

list.files("data")
  • list.files("data") lists every file in the data folder

Find the Name It Has: Output

> list.files("data")
[1] "coding-form - Sheet1.csv" "twitch_analysis.RDS"
  • The download kept its long name
  • Rename it to coding-form.csv in the VS Code Explorer, then run the check again

What Is in the Data Folder

list.files("data")
  • "data" again means: start in the folder open in VS Code, go into data
  • Run this before you submit Data Wrangling

What Is in the Data Folder: Output

> list.files("data")
[1] "coding-form.csv"     "twitch_analysis.RDS"
  • coding-form.csv: your thirty codes, saved as a CSV
  • twitch_analysis.RDS: the table Part 7 saved
  • Both files go to Blackboard with the worksheet

Check the Saved Table

read_rds("data/twitch_analysis.RDS") %>%
  nrow()
  • The last line of worksheet Part 7
  • read_rds() loads the saved file back, and nrow() counts its rows

Check the Saved Table: Output

> read_rds("data/twitch_analysis.RDS") %>%
+   nrow()
[1] 35267
  • 35267: one row per chat message, nothing lost and nothing added
  • Describing Data and Inferencing Data both start from this file

Render: The Final Check

  • Rendering runs the whole worksheet from the top, in a fresh R session
  • If it renders, it runs
  1. Save the worksheet: File, then Save
  2. Open the Command Palette: View, then Command Palette…
  3. Type Quarto: Render Document and press Enter
  4. If a list of formats opens, select Render HTML

Render: Output

The last line of the Terminal panel:

Output created: 11-wrangling-data.html
  • Output created means it worked
  • 11-wrangling-data.html appears beside the worksheet in the Explorer

Render Starts in the File’s Folder

  • Running lines starts in the folder open in VS Code
  • Render starts in the folder the .qmd file is saved in
  • Saved in the top folder, beside README.md: both starts are the same folder
  • Saved inside another folder, such as 03_Project: render looks for data inside that folder, and stops

Render Starts in the File’s Folder: Output

The same worksheet, saved in 03_Project and rendered:

Error:
! 'data/coding-form.csv' does not exist in current working directory ('C:/Users/you/Documents/mc501-workspace/03_Project').
Backtrace:
    ▆
 1. ├─read_csv("data/coding-form.csv") %>% clean_names()
 2. ├─janitor::clean_names(.)
 3. ├─readr::read_csv("data/coding-form.csv")
 4. │ └─vroom::vroom(...)
 5. │   └─vroom:::vroom_(...)
 6. └─vroom (local) `<fn>`("data/coding-form.csv")
 7.   └─vroom:::check_path(path)

Quitting from 11-wrangling-data.qmd:425-429 [read-codes]
Execution halted
  • The folder in brackets ends in 03_Project: that is where render started
  • The fix: drag the worksheet up to the top folder, beside README.md, and render again

Three Reviewer Comments

Data Wrangling worksheet, Part 8

  • Three comments in the code, 40 to 100 words each, at the places marked MC 501 only
    • The non-gaming list (Task 4.2), the viewer-band cutoffs (Task 4.3), and the export (Part 7)
  • Each one names a decision a reviewer could challenge, the rule you applied, and why you chose it
  • Adopting the package’s list or cutoffs is itself a decision: say why it fits
  • A comment that says what the code does is not one of the three

What to Upload

Data Wrangling in R, Blackboard

  • One ZIP file of your whole workspace, the folder open in VS Code, holding:
    • 11-wrangling-data.qmd, with no ___ left
    • 11-wrangling-data.html, the rendered page
    • data/coding-form.csv, your thirty codes
    • data/twitch_analysis.RDS, the saved table
    • The AI-use log, saved beside README.md, with an entry or the no-AI box checked
  • Make the ZIP file: Submit Your Work as One ZIP File

Describing Data

What We Build Today

Describing Data, 100 points, due Monday, November 23, 11:59 PM

  • Three figures and one table of descriptive statistics, built on the example data
    • A line chart for change over time, a bar chart for counts, a histogram for shape
    • Each chart type fits a different kind of question
  • The same figures, built on your own data, go into your Results and onto your poster
  • Plus the rule that turns a picture into a claim: report the effect size

Expect every first version to look wrong. The fix is usually one line.

The Twitch Job, Part 2

  • The Describing Data worksheet is part 2 of the Twitch job
    • It loads data/twitch_analysis.RDS, with your thirty codes inside
  • Frequency tables, mean, median, and sd, a cross-tabulation, and three figures
  • Part 5: the diagnostics behind each figure
  • Your interpretation and your alt text are never filled in for you

MC 501 worksheet · Describing Data risks guide

  • Click the link: your browser saves 12-describing-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

Load the Saved Table

Three lines start every Describing session: two packages, then the table Data Wrangling saved.

library(tidyverse)
library(v2v)
analysis <- read_rds("data/twitch_analysis.RDS")
  • library() switches a package on for this session
  • read_rds() reads the saved file and names the table analysis
  • If R says cannot open the connection, the file is not in your data folder

Load the Table: Output

> library(tidyverse)
── Attaching core tidyverse packages ──────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.1     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.2.0
── Conflicts ────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
> library(v2v)
v2v 0.3.9 loaded.
  setup()  checks that R, Quarto and Git are ready
  ?v2v     lists what this package gives you
> analysis <- read_rds("data/twitch_analysis.RDS")
  • The two masks lines are normal, not errors
  • read_rds() prints nothing: the table went into analysis quietly

A First Look at the Table

glimpse(analysis)
  • glimpse() prints one line per column: its name, its type, and its first few values
  • Use it every time you load a table, before you draw anything

A First Look: Output

> glimpse(analysis)
Rows: 35,267
Columns: 16
$ id             <dbl> 89, 551, 1033, 2094, 2803, 10406, 16104, 22571,…
$ channel        <chr> "sodapoppin", "xqcow", "forsen", "sodapoppin", …
$ sender         <chr> "madzee", "prometheanow", "spectre155", "itsjer…
$ message        <chr> "???????????????????????", "TriEasy Clap TriEas…
$ date           <dbl> 1.542578e+12, 1.542578e+12, 1.542578e+12, 1.542…
$ ts             <dttm> 2018-11-18 21:55:27, 2018-11-18 21:55:35, 2018…
$ message_length <int> 23, 441, 8, 12, 206, 37, 6, 7, 4, 7, 3, 4, 12, …
$ snapshot_ts    <dttm> NA, NA, NA, NA, NA, 2018-11-18 21:56:40, 2018-…
$ game           <chr> NA, NA, NA, NA, NA, "Artifact", "Marble It Up!"…
$ viewers        <int> NA, NA, NA, NA, NA, 15300, 28076, 4703, 19239, …
$ main_game      <chr> "Hand Simulator", "Just Chatting", "The Elder S…
$ is_gaming      <lgl> TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRU…
$ channel_type   <fct> gaming, non-gaming, gaming, gaming, non-gaming,…
$ median_viewers <dbl> 22944, 16176, 10163, 22944, 16176, 10163, 22944…
$ viewer_band    <fct> large, medium, medium, large, medium, medium, l…
$ reaction_only  <fct> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
  • 35,267 rows, one per chat message, and 16 columns
  • reaction_only is NA except on your thirty coded messages

A Table Too Long to Read

  • The analysis table is complete, but too long to read
    • Nobody scrolls through 35,267 rows and learns anything
    • The numbers are present, but the pattern is not visible
  • A figure turns a long column of numbers into a shape you can see

Visualization is not decoration applied afterwards. It is part of the analysis.

The Grammar of Graphics

Three parts do most of the work (Wilkinson, 2005; Wickham, 2016):

ggplot(data, aes(x = ..., y = ...)) +
  geom_line()
  • Data: the table being shown
  • Aesthetic mappings: which column goes to which visual property, such as the x axis or the color
  • Geometry: the kind of mark used to draw the data, such as a line or a bar

Swap geom_line() for geom_col() and the same data is drawn as bars.

Figure 1, a Line Chart for Change Over Time

  • The question: how did viewership move across the week, and how was it split across games?
  • Time goes on the x axis and a rising and falling value on the y axis, so this is a line chart
    • A line implies a sequence, and real distance between the points
    • A line is right for time and wrong for unordered categories
  • The data needs shaping before it can be drawn

Shaping the Data

viewers_over_time <- twitch_viewers_over_time()
viewers_over_time
  • The course package ships this table already shaped for a line chart
  • Typing the table’s name on its own line prints it

The Viewers Table: Output

> viewers_over_time <- twitch_viewers_over_time()
> viewers_over_time
# A tibble: 97 × 3
   six_hour            category                           total_viewers
   <dttm>              <fct>                                      <int>
 1 2018-11-18 18:00:00 Art                                       238217
 2 2018-11-18 18:00:00 Just Chatting                            2034123
 3 2018-11-18 18:00:00 Pokemon: Let's Go, Pikachu!/Eevee!         99909
 4 2018-11-18 18:00:00 Other                                    4333423
 5 2018-11-19 00:00:00 Art                                       870710
 6 2018-11-19 00:00:00 Fortnite                                  258780
 7 2018-11-19 00:00:00 Just Chatting                            4312125
 8 2018-11-19 00:00:00 Pokemon: Let's Go, Pikachu!/Eevee!       1991196
 9 2018-11-19 00:00:00 Other                                    6933016
10 2018-11-19 06:00:00 Art                                        12444
# ℹ 87 more rows
  • Three columns: the six-hour window, the category, and the viewers added up inside it
  • R prints the first ten rows and says how many more there are

Count the Categories

viewers_over_time %>%
  count(category)
  • count() makes one row per category and counts the rows in each

Count the Categories: Output

> viewers_over_time %>%
+   count(category)
# A tibble: 6 × 2
  category                               n
  <fct>                              <int>
1 Art                                   21
2 Fortnite                              17
3 Hearthstone                            9
4 Just Chatting                         18
5 Pokemon: Let's Go, Pikachu!/Eevee!    10
6 Other                                 22
  • Six categories, so six rows; n is how many six-hour windows each one has

Shaping the Data (cont.)

  • The course package ships this table ready to draw
  • The stream snapshots are grouped into six-hour windows
  • Everything past the top five games is lumped into “Other,” and the viewers inside each window are added up
  • Three judgment calls made for you: ?twitch_viewers_over_time says how, and the package source holds the pipeline

Drawing the Line Chart

ggplot(viewers_over_time,
       aes(x = six_hour, y = total_viewers,
           color = category)) +
  geom_line(linewidth = 0.9) +
  scale_y_continuous(labels = scales::label_comma()) +
  labs(title = "Concurrent viewers by game category",
       x = "Date (UTC, six-hour buckets)",
       y = "Total viewers in bucket",
       color = "Category") +
  v2v::scale_color_v2v() +
  v2v::theme_v2v()

label_comma() writes 20,000,000 instead of 2.0e+07, and theme_v2v() applies publication-ready fonts, spacing, and gridlines in one call.

Drawing the Line Chart: Output

A line chart of total viewers per six-hour window from November 18 to 25, 2018, one line per category. The Other line towers over the rest, peaking above 22 million; Art, Fortnite, Hearthstone, Just Chatting, and Pokemon stay mostly under 7.5 million.
  • In VS Code the chart opens in its own Plot tab, beside your code

What Dominates the Chart, and Why

  • The towering line is “Other”, the catch-all for everything beyond the top five games
    • As a finding: viewership really is spread across a long tail of games
    • As a caution: lumping fifty categories into one guarantees that result
  • There is a plain design cost too
    • The five named lines are pressed into the bottom of the panel

A dominant series crowds out the rest. Noticing that is reading the chart honestly.

Figure 2, a Bar Chart for Counts

  • The question: at which hours of the day are channels busiest?
  • Hour of day is 24 separate categories, not a continuous sweep
  • What is measured is a simple count of messages in each hour
  • Counts across categories call for a bar chart
    • One bar per category, the height is the count, the bars sit side by side

Count Messages per Hour

chat_by_hour <- analysis %>%
  mutate(hour = hour(ts)) %>%
  count(hour, name = "messages")
chat_by_hour
  • hour() pulls the hour, 0 to 23, out of each message’s time stamp
  • count() then counts the messages in each hour and names the count messages

Messages per Hour: Output

> chat_by_hour <- analysis %>%
+   mutate(hour = hour(ts)) %>%
+   count(hour, name = "messages")
> chat_by_hour
# A tibble: 24 × 2
    hour messages
   <int>    <int>
 1     0     1816
 2     1     1959
 3     2     1013
 4     3      833
 5     4     1384
 6     5     1317
 7     6     1393
 8     7     1165
 9     8     1016
10     9     1381
# ℹ 14 more rows
  • One row per hour; R shows the first ten and says 14 more are there

Find the Busiest Hour

chat_by_hour %>%
  arrange(desc(messages))
  • arrange() sorts the rows; desc() puts the biggest count first
  • Sorting is how you find the peak before you draw it

Find the Busiest Hour: Output

> chat_by_hour %>%
+   arrange(desc(messages))
# A tibble: 24 × 2
    hour messages
   <int>    <int>
 1    13     2201
 2    16     2132
 3    17     2084
 4     1     1959
 5    12     1915
 6     0     1816
 7    11     1775
 8    18     1717
 9    15     1578
10    10     1449
# ℹ 14 more rows
  • The busiest hour is 13:00 UTC, with 2,201 messages

The Code for the Bar Chart

ggplot(chat_by_hour, aes(x = hour, y = messages)) +
  geom_col(fill = "#2f7d8a") +
  labs(title = "Chat volume by hour of day",
       x = "Hour of day (UTC)",
       y = "Messages in sample") +
  v2v::theme_v2v()

geom_col() draws a bar whose height is a value you already computed.

The Bar Chart: Output

A bar chart titled Chat volume by hour of day: messages in the sample for each hour, 0 to 23 UTC. The tallest bar is 13:00 at about 2,200 messages, with high bars again at 16:00 and 17:00; the shortest is 03:00 at about 830.

Chat Volume by Hour of Day

  • The example chat is busiest through UTC midday, peaking at 13:00 with 2,201 messages
  • It is quietest in the small hours, bottoming out at 03:00 with 833 messages
  • That is a swing of well over two to one
  • The 2018 audience was mostly in the Americas and Europe, which explains the pattern

The chart shows all twenty-four hourly counts at once.

Effect Sizes, and Their Standing

“Effect sizes are the most important outcome of empirical studies.”

Lakens (2013, p. 1)

  • Every figure that shows a comparison must report its effect size
  • A taller bar is a visual impression, not a claim
  • The effect size states the magnitude of a difference in a unit that does not depend on the scale

Exercise: The Most Important Outcome

Lakens (2013)

“Effect sizes are the most important outcome of empirical studies.”

Lakens (2013, p. 1)

  • Lakens says effect sizes are the most important outcome. Name the reader for whom that is true, and say why
  • Articles in your field usually report p before the effect size. Give one reason that habit persists
  • Describe one thing that would change in your field if journals required the effect size first

Figure 3, a Histogram for Shape

Histogram: a bar chart of a number variable, where each bar counts the values in one range. Example: one bar counts the messages 0 to 5 characters long.

  • The central question of the example study: how long is a chat message, and does the answer depend on the kind of channel?
  • The answer is not a total and not a trend. It is a distribution
    • Where the values cluster, and where they thin out
  • Two histograms overlaid let the two shapes be compared directly

The Table Behind the Histogram

msglen <- analysis %>%
  filter(!is.na(is_gaming)) %>%
  mutate(length_shown = pmin(message_length, 120))
msglen %>%
  count(is_gaming)
  • filter() drops the messages from channels with no gaming label
  • pmin() keeps each length, but shows anything over 120 as 120
  • count(is_gaming) checks how many messages each group has left

The Table Behind It: Output

> msglen <- analysis %>%
+   filter(!is.na(is_gaming)) %>%
+   mutate(length_shown = pmin(message_length, 120))
> msglen %>%
+   count(is_gaming)
# A tibble: 2 × 2
  is_gaming     n
  <lgl>     <int>
1 FALSE      3457
2 TRUE      31309
  • FALSE is non-gaming: 3,457 messages, about one in ten
  • TRUE is gaming: 31,309 messages

Check the Cap

msglen %>%
  summarize(
    longest = max(message_length, na.rm = TRUE),
    longest_shown = max(length_shown, na.rm = TRUE)
  )
  • max() finds the biggest value; na.rm = TRUE skips the empty messages
  • One line compares the real longest message with the longest one the chart will show

Check the Cap: Output

> msglen %>%
+   summarize(
+     longest = max(message_length, na.rm = TRUE),
+     longest_shown = max(length_shown, na.rm = TRUE)
+   )
# A tibble: 1 × 2
  longest longest_shown
    <int>         <dbl>
1     501           120
  • The longest message is 501 characters; the chart draws it at 120

The Code for the Histogram

ggplot(msglen,
       aes(x = length_shown, fill = is_gaming)) +
  geom_histogram(binwidth = 5, position = "identity",
                 alpha = 0.55) +
  labs(x = "Message length (characters, capped at 120)",
       y = "Messages",
       fill = "Gaming channel") +
  v2v::scale_fill_v2v() +
  v2v::theme_v2v()
  • binwidth = 5 makes each bar five characters wide; alpha lets the overlap show through

The Histogram: Output

Two overlaid histograms of message length in characters, capped at 120, for gaming (TRUE) and non-gaming (FALSE) channels. Both pile up under 20 characters and thin out to the right, with a small spike in the last bar at 120. The non-gaming bars are so short they barely show.

The Warning Under the Chart

The terminal also prints this under the histogram code:

> ggplot(msglen,
+        aes(x = length_shown, fill = is_gaming)) +
+   geom_histogram(binwidth = 5, position = "identity",
+                  alpha = 0.55) +
+   labs(x = "Message length (characters, capped at 120)",
+        y = "Messages",
+        fill = "Gaming channel") +
+   v2v::scale_fill_v2v() +
+   v2v::theme_v2v()
Warning message:
Removed 4 rows containing non-finite outside the scale range
(`stat_bin()`).
  • A warning is not an error: the chart still drew
  • The 4 rows are the empty messages, which have no length to draw

Counts Hide the Smaller Group

  • Non-gaming is one message in ten, so by count it barely shows
  • The R Companion’s Histogram comparing two groups draws each group as shares instead, so the shapes compare

Two Choices You Must Disclose

  • binwidth = 5 makes each bar cover five characters
    • A wider bin smooths the shape and a narrower bin roughens it
    • The bin width is a judgment, so you report it
  • pmin(message_length, 120) caps the display at 120 characters
    • The longest message is 501 characters, so the last bar is a pile-up of everything longer
    • Capping keeps the bulk of the data legible

An unannounced cap is a quiet distortion. The axis label states the cap.

What the Shape Shows

Skew: a lopsided shape. Right-skewed means most values are small and a few are very large, like message length here.

  • Both groups share one shape: heavily right-skewed
    • A tall stack of very short messages on the left
    • A long thin tail of longer messages to the right
  • Most Twitch chat messages are brief: a word or an emote

The skew is the most important thing the histogram reveals, and no summary number can show it.

What Descriptive Statistics Are

Descriptive statistics: numbers that summarize a set of data, such as how many cases there are, where the middle sits, and how spread out the values are. Example: n, mean, median, and sd of message length for each group.

The Descriptive Statistics

  • Click the AURA Lab R Companion icon on VS Code’s left edge
  • Under Describe, click Summary by group: it writes n, mean, median, and sd for each channel_type
  • To summarize another column, change the column names in the block it writes

The Descriptive Statistics (cont.)

msglen %>%
  group_by(is_gaming) %>%
  summarize(
    n      = sum(!is.na(message_length)),
    mean   = mean(message_length, na.rm = TRUE),
    median = median(message_length, na.rm = TRUE),
    sd     = sd(message_length, na.rm = TRUE),
    .groups = "drop"
  )
  • group_by(is_gaming) splits the table into the two groups; summarize() makes one row per group
  • na.rm = TRUE leaves the four empty messages out of each number

The Descriptive Statistics: Output

> msglen %>%
+   group_by(is_gaming) %>%
+   summarize(
+     n      = sum(!is.na(message_length)),
+     mean   = mean(message_length, na.rm = TRUE),
+     median = median(message_length, na.rm = TRUE),
+     sd     = sd(message_length, na.rm = TRUE),
+     .groups = "drop"
+   )
# A tibble: 2 × 5
  is_gaming     n  mean median    sd
  <lgl>     <int> <dbl>  <int> <dbl>
1 FALSE      3457  33.7     16  60.7
2 TRUE      31305  28.5     17  38.5

The Descriptive Statistics (cont.)

  • In the R Companion panel, under Describe, Line chart over time writes Figure 1
  • Bar chart, then The table already has the numbers, writes Figure 2
  • Histogram comparing two groups writes Figure 3
  • After Run it, the saved chart opens in its own VS Code tab

The Numbers

Mean: the average, the total divided by the count. Median: the middle value once the values are sorted. Example: the mean message is 29.0 characters long, the median 17.

  • Non-gaming: n 3,457, mean 33.7, median 16, sd 60.7
  • Gaming: n 31,305, mean 28.5, median 17, sd 38.5
    • 31,305, not 31,309: the four empty messages have no length to count

Read the means and non-gaming chat is longer. Read the medians, 16 against 17, and the two groups are all but identical, pointing the other way.

When the Mean and the Median Disagree

Standard deviation (sd): how far values typically sit from the mean. Example: non-gaming chat’s sd of 60.7 says its lengths are more spread out than gaming chat’s 38.5.

  • The mean is sensitive to a long tail; the median is not
    • A few very long messages lift the average
    • The middle value is untouched by them
  • Non-gaming chat has the heavier tail, and its larger standard deviation records that
  • The gap in means is the work of the tail, not of the typical message

Report the mean alone and you misreport what a typical message looks like.

Which Effect Size to Report

Effect size: how big a difference or a relationship is, on a scale that does not grow with the sample. Example: Cramer’s V of 0.15 for viewer band by channel type.

  • A difference between two group means: Cohen’s d with a 95% confidence interval
  • A cross-tabulation of two categorical variables: Cramer’s V
  • A correlation between two numeric variables: r and its confidence interval
  • effectsize::cohens_d() and effectsize::cramers_v() print each one with its 95% confidence interval

Put the effect size in the caption or in a companion table, never in a footnote.

Cohen’s d for Message Length

effectsize::cohens_d(message_length ~ is_gaming,
                     data = msglen)
  • message_length ~ is_gaming reads “message length, compared across gaming status”
  • effectsize:: calls the function from the effectsize package without loading the whole package
  • Copy the d and its interval into your caption by hand

Cohen’s d: Output

> effectsize::cohens_d(message_length ~ is_gaming,
+                      data = msglen)
Cohen's d |       95% CI
------------------------
0.13      | [0.09, 0.16]

- Estimated using pooled SD.Warning message:
Missing values detected. NAs dropped.
  • Non-gaming messages run 0.13 standard deviations longer, with a 95% interval of 0.09 to 0.16
  • The warning is the four empty messages again, dropped before the calculation

Three Terms From That List

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: d with its 95% interval shows how far the true gap could plausibly sit from the measured one.

Categorical variable: a variable whose values are categories rather than measured amounts. Example: channel type, gaming or non-gaming.

Cross-tabulation: a table that counts how often each combination of two categorical variables occurs. Example: viewer band by channel type.

Color Never Works Alone

  • About one in twelve men has a color-vision deficiency
  • Use a colorblind-safe palette, such as scale_color_v2v()
  • Also vary the line type, or split the groups into panels

Alt Text Replaces the Figure

  • A screen-reader user hears the alt text instead of seeing the figure
  • Good alt text states the chart type, the axes, and the takeaway
  • In a Quarto chunk it goes on the top line: #| fig-alt: "A histogram of message length..."
  • Write the same sentence in the alt = line inside labs()

A Cross-Tabulation

Example data: episodes_analysis.RDS, Power Rangers episodes coded for threat and focus

Cross-tabulation: a grid that counts every combination of two categories.

episodes <- read_rds("data/episodes_analysis.RDS")

episodes %>%
  filter(!is.na(focus)) %>%
  count(threat, focus) %>%
  pivot_wider(names_from = focus,
              values_from = n,
              values_fill = 0)
  • count() with two columns: one row per combination
  • pivot_wider() turns those rows into a grid, one column per focus code

A Cross-Tabulation: Output

> episodes <- read_rds("data/episodes_analysis.RDS")
>
> episodes %>%
+   filter(!is.na(focus)) %>%
+   count(threat, focus) %>%
+   pivot_wider(names_from = focus,
+               values_from = n,
+               values_fill = 0)
# A tibble: 3 × 4
  threat   team one_ranger other
  <fct>   <int>      <int> <int>
1 monster    15         21     1
2 villain    29         18     9
3 none       10         13     3
  • One row per threat code, one column per focus code
  • 15 episodes were coded monster and team
  • Worksheet Task 3.1 builds the same kind of grid from the Twitch table

Shares Within Each Row

episodes %>%
  filter(!is.na(focus)) %>%
  count(threat, focus) %>%
  group_by(threat) %>%
  mutate(share = round(n / sum(n), 3))
  • group_by(threat) makes sum(n) add up within each threat code
  • So each code’s shares add up to 1

Shares Within Each Row: Output

> episodes %>%
+   filter(!is.na(focus)) %>%
+   count(threat, focus) %>%
+   group_by(threat) %>%
+   mutate(share = round(n / sum(n), 3))
# A tibble: 9 × 4
# Groups:   threat [3]
  threat  focus          n share
  <fct>   <fct>      <int> <dbl>
1 monster team          15 0.405
2 monster one_ranger    21 0.568
3 monster other          1 0.027
4 villain team          29 0.518
5 villain one_ranger    18 0.321
6 villain other          9 0.161
7 none    team          10 0.385
8 none    one_ranger    13 0.5
9 none    other          3 0.115
  • one_ranger: 0.568 of the monster episodes, 0.321 of the villain ones

Explain This Stage to the Client

  • The worksheet ends with one paragraph to the client
    • A channel manager at a small creator agency, about to pitch a sponsor
    • The manager does not read R
  • Say what you counted, measured, and charted
  • Name the numbers that matter for their three questions
  • Say what it does not show yet: whether a difference is bigger than chance
  • No R, no column names, no words the manager would have to look up

Checkpoint

You should now have:

  • The worksheet’s three figures (Tasks 4.1 to 4.3), each saved in figures/ and drawn with theme_v2v()
  • A #| fig-alt: sentence for each figure, with no YOUR TURN left
  • The table of n, mean, median, and sd
  • One disclosure sentence per figure: the cap, the categories kept, or the bin width
  • One interpretation of two to three sentences per figure

Commit Your Pre-Registration

  • Your Methods must cite a dated pre-registration file in your project repository, by its path and commit
  • Revise your Research Proposal first if it needs it, then commit it to your project repository as that file
  • Commit it by Monday, November 16, 11:59 PM, before you analyze your own data
  • Every change after that commit is a departure you disclose in Methods
  • Step by step: Commit and Push with Git

Before Week 13

Before Week 13 (cont.)

  • Click by click: Describe the Data: Tables and Charts and its walkthrough video
  • Finish the first coding pass on your own full corpus by Thursday, December 3, and push it by Monday, December 7, 11:59 PM
    • Your Methods reports stability from your pilot re-code; there is no second re-code
  • Read Chapter 13, Making the Call
    • The assigned article: Lakens et al. (2018), “Justify your alpha”
  • Check yourself on this week’s terms: Week 12 self-check, ungraded, with the answer after each question

The histogram left a precise question: is the gap between the groups real or chance? Week 13 answers it.

Questions, Comments, or Concerns?