Skip to:

Data

Graphing the data

Analysis

Let’s create & compare four time periods:

Let’s do the same, but for each outlet individually

Coverage volume of other issues, by period

The full script

Overview

The general goal of this research is to look for evidence of a “bandwidth limit” on the volume of war coverage by cable television news outlets CNN, Fox News, and MSNBC. Specifically, the study explores whether the explosion of reporting about the onset of war between Israel and Hamas in Gaza corresponded to a reduction in the volume of reporting about the Russian invasion of Ukraine. The analysis also explores whether changes in the volumn of coverage about these two conflicts corresponded to changes in the volume of reporting about other issues, like abortion, inflation, climate change, and more.

Data

Data come from GDELT’s 2.0 Television API, which makes programming from major television news outlets searchable in 15-second snippets. API output reports the volume of 15-second snippets, over time, that include specified search terms. We begin with code that loads required packages and builds an “AllData” data frame containing, for each of several TV news outlets, weekly counts from Feb. 14, 2022 through the present of 15-second snippets mentioning any of seven topics:

if (!require("tidyverse"))
  install.packages("tidyverse")
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── 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
if (!require("plotly"))
  install.packages("plotly")
## Loading required package: plotly
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(tidyverse)
library(plotly)

# Defining date range

startdate <- "20220214"
enddate <- "20241114"

# Defining query

query <- "(russia%20OR%20ukrain)"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
## [1] "https://api.gdeltproject.org/api/v2/tv/tv?query=(russia%20OR%20ukrain)%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime=20220214000000&enddatetime=20241114000000"
Ukraine <- read_csv(v_url)
## Rows: 8739 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): Series
## dbl  (1): Value
## date (1): Date (Daily +00:00: 02/14/2022 - 11/14/2024)
## 
## ℹ 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.
Ukraine <- Ukraine %>%
  rename(Date = 1, Ukraine = 3)

### Gaza

# Defining query

query <- "(gaza%20OR%20israel)"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
## [1] "https://api.gdeltproject.org/api/v2/tv/tv?query=(gaza%20OR%20israel)%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime=20220214000000&enddatetime=20241114000000"
Gaza <- read_csv(v_url)
## Rows: 8739 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): Series
## dbl  (1): Value
## date (1): Date (Daily +00:00: 02/14/2022 - 11/14/2024)
## 
## ℹ 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.
Gaza <- Gaza %>%
  rename(Date = 1, Gaza = 3)

AllData <- left_join(Ukraine, Gaza)
## Joining with `by = join_by(Date, Series)`
### Mass shooting

# Defining query

query <- "mass%20shooting"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
## [1] "https://api.gdeltproject.org/api/v2/tv/tv?query=mass%20shooting%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime=20220214000000&enddatetime=20241114000000"
Mass_shooting <- read_csv(v_url)
## Rows: 8739 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): Series
## dbl  (1): Value
## date (1): Date (Daily +00:00: 02/14/2022 - 11/14/2024)
## 
## ℹ 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.
Mass_shooting <- Mass_shooting %>%
  rename(Date = 1, Mass_shooting = 3)

AllData <- left_join(AllData, Mass_shooting)
## Joining with `by = join_by(Date, Series)`
### Abortion

# Defining query

query <- "abortion"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
## [1] "https://api.gdeltproject.org/api/v2/tv/tv?query=abortion%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime=20220214000000&enddatetime=20241114000000"
Abortion <- read_csv(v_url)
## Rows: 8739 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): Series
## dbl  (1): Value
## date (1): Date (Daily +00:00: 02/14/2022 - 11/14/2024)
## 
## ℹ 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.
Abortion <- Abortion %>%
  rename(Date = 1, Abortion = 3)

AllData <- left_join(AllData, Abortion)
## Joining with `by = join_by(Date, Series)`
### Election

# Defining query

query <- "election"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
## [1] "https://api.gdeltproject.org/api/v2/tv/tv?query=election%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime=20220214000000&enddatetime=20241114000000"
Election <- read_csv(v_url)
## Rows: 8739 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): Series
## dbl  (1): Value
## date (1): Date (Daily +00:00: 02/14/2022 - 11/14/2024)
## 
## ℹ 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.
Election <- Election %>%
  rename(Date = 1, Election = 3)

AllData <- left_join(AllData, Election)
## Joining with `by = join_by(Date, Series)`
### Climate change

# Defining query

query <- "climate%20change"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
## [1] "https://api.gdeltproject.org/api/v2/tv/tv?query=climate%20change%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime=20220214000000&enddatetime=20241114000000"
Climate_change <- read_csv(v_url)
## Rows: 8739 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): Series
## dbl  (1): Value
## date (1): Date (Daily +00:00: 02/14/2022 - 11/14/2024)
## 
## ℹ 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.
Climate_change <- Climate_change %>%
  rename(Date = 1, Climate_change = 3)

AllData <- left_join(AllData, Climate_change)
## Joining with `by = join_by(Date, Series)`
### Inflation

# Defining query

query <- "inflation"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
## [1] "https://api.gdeltproject.org/api/v2/tv/tv?query=inflation%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime=20220214000000&enddatetime=20241114000000"
Inflation <- read_csv(v_url)
## Rows: 8739 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): Series
## dbl  (1): Value
## date (1): Date (Daily +00:00: 02/14/2022 - 11/14/2024)
## 
## ℹ 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.
Inflation <- Inflation %>%
  rename(Date = 1, Inflation = 3)

AllData <- left_join(AllData, Inflation)
## Joining with `by = join_by(Date, Series)`
# Filter AllData for Fox News, CNN, and MSNBC

AllData <- AllData %>%
  arrange(Date) %>% 
  filter(Series == "FOXNEWS"|
           Series == "CNN"|
           Series == "MSNBC")

Graphing the data

Here are interactive stream graphs of the volume for each topic, first for all outlets combined, then for each outlet separately.

### Graphic

# Add "WeekOf" variable to the data frame

if (!require("lubridate"))
  install.packages("lubridate")
library(lubridate)

AllData$WeekOf <- round_date(AllData$Date,
                             unit = "week",
                             week_start = getOption("lubridate.week.start", 1))


CombinedCoverage <- AllData %>%
  group_by(WeekOf) %>%
  summarize(
    Ukraine = sum(Ukraine, na.rm = TRUE),
    Gaza = sum(Gaza, na.rm = TRUE),
    Mass_shooting = sum(Mass_shooting, na.rm = TRUE),
    Abortion = sum(Abortion, na.rm = TRUE),
    Election = sum(Election, na.rm = TRUE),
    Climate_change = sum(Climate_change, na.rm = TRUE),
    Inflation = sum(Inflation, na.rm = TRUE)
  )


fig <- plot_ly(
  CombinedCoverage,
  x = ~ WeekOf,
  y = ~ Ukraine,
  name = 'Ukraine',
  type = 'scatter',
  mode = 'none',
  stackgroup = 'one',
  fillcolor = '#264653'
)
fig <- fig %>% add_trace(y = ~ Gaza,
                         name = 'Gaza',
                         fillcolor = '#287271')
fig <- fig %>% add_trace(
  y = ~ Mass_shooting,
  name = 'Mass shooting',
  fillcolor = '#2a9d8f'
)
fig <- fig %>% add_trace(y = ~ Abortion,
                         name = 'Abortion',
                         fillcolor = '#8ab17d')
fig <- fig %>% add_trace(y = ~ Election,
                         name = 'Election',
                         fillcolor = '#e9c46a')
fig <- fig %>% add_trace(
  y = ~ Climate_change,
  name = 'Climate change',
  fillcolor = '#f4a261'
)
fig <- fig %>% add_trace(y = ~ Inflation,
                         name = 'Inflation',
                         fillcolor = '#e76f51')
fig <- fig %>% layout(
  title = 'Segment counts, by topic and week, all outlets',
  xaxis = list(title = "Week of", showgrid = FALSE),
  yaxis = list(title = "Count", showgrid = TRUE)
)

fig
### Results for Fox News, CNN, and MSNBC, separately

#Fox News

FoxNews <- AllData %>%
  filter(Series == "FOXNEWS")
figfox <- plot_ly(
  FoxNews,
  x = ~ WeekOf,
  y = ~ Ukraine,
  name = 'Ukraine',
  type = 'scatter',
  mode = 'none',
  stackgroup = 'one',
  fillcolor = '#264653'
)
figfox <- figfox %>% add_trace(y = ~ Gaza,
                               name = 'Gaza',
                               fillcolor = '#287271')
figfox <- figfox %>% add_trace(
  y = ~ Mass_shooting,
  name = 'Mass shooting',
  fillcolor = '#2a9d8f'
)
figfox <- figfox %>% add_trace(y = ~ Abortion,
                               name = 'Abortion',
                               fillcolor = '#8ab17d')
figfox <- figfox %>% add_trace(y = ~ Election,
                               name = 'Election',
                               fillcolor = '#e9c46a')
figfox <- figfox %>% add_trace(
  y = ~ Climate_change,
  name = 'Climate change',
  fillcolor = '#f4a261'
)
figfox <- figfox %>% add_trace(y = ~ Inflation,
                               name = 'Inflation',
                               fillcolor = '#e76f51')
figfox <- figfox %>% layout(
  title = 'Segment counts, by topic and week, Fox News',
  xaxis = list(title = "Week of", showgrid = FALSE),
  yaxis = list(title = "Count", showgrid = TRUE)
)

figfox
# CNN

CNN <- AllData %>%
  filter(Series == "CNN")
figCNN <- plot_ly(
  CNN,
  x = ~ WeekOf,
  y = ~ Ukraine,
  name = 'Ukraine',
  type = 'scatter',
  mode = 'none',
  stackgroup = 'one',
  fillcolor = '#264653'
)
figCNN <- figCNN %>% add_trace(y = ~ Gaza,
                               name = 'Gaza',
                               fillcolor = '#287271')
figCNN <- figCNN %>% add_trace(
  y = ~ Mass_shooting,
  name = 'Mass shooting',
  fillcolor = '#2a9d8f'
)
figCNN <- figCNN %>% add_trace(y = ~ Abortion,
                               name = 'Abortion',
                               fillcolor = '#8ab17d')
figCNN <- figCNN %>% add_trace(y = ~ Election,
                               name = 'Election',
                               fillcolor = '#e9c46a')
figCNN <- figCNN %>% add_trace(
  y = ~ Climate_change,
  name = 'Climate change',
  fillcolor = '#f4a261'
)
figCNN <- figCNN %>% add_trace(y = ~ Inflation,
                               name = 'Inflation',
                               fillcolor = '#e76f51')
figCNN <- figCNN %>% layout(
  title = 'Segment counts, by topic and week, CNN',
  xaxis = list(title = "Week of", showgrid = FALSE),
  yaxis = list(title = "Count", showgrid = TRUE)
)

figCNN
# MSNBC

MSNBC <- AllData %>%
  filter(Series == "MSNBC")
figMSNBC <- plot_ly(
  MSNBC,
  x = ~ WeekOf,
  y = ~ Ukraine,
  name = 'Ukraine',
  type = 'scatter',
  mode = 'none',
  stackgroup = 'one',
  fillcolor = '#264653'
)
figMSNBC <- figMSNBC %>% add_trace(y = ~ Gaza,
                                   name = 'Gaza',
                                   fillcolor = '#287271')
figMSNBC <- figMSNBC %>% add_trace(
  y = ~ Mass_shooting,
  name = 'Mass shooting',
  fillcolor = '#2a9d8f'
)
figMSNBC <- figMSNBC %>% add_trace(y = ~ Abortion,
                                   name = 'Abortion',
                                   fillcolor = '#8ab17d')
figMSNBC <- figMSNBC %>% add_trace(y = ~ Election,
                                   name = 'Election',
                                   fillcolor = '#e9c46a')
figMSNBC <- figMSNBC %>% add_trace(
  y = ~ Climate_change,
  name = 'Climate change',
  fillcolor = '#f4a261'
)
figMSNBC <- figMSNBC %>% add_trace(y = ~ Inflation,
                                   name = 'Inflation',
                                   fillcolor = '#e76f51')
figMSNBC <- figMSNBC %>% layout(
  title = 'Segment counts, by topic and week, MSNBC',
  xaxis = list(title = "Week of", showgrid = FALSE),
  yaxis = list(title = "Count", showgrid = TRUE)
)

figMSNBC
rm(
  Abortion,
  Climate_change,
  CNN,
  CombinedCoverage,
  Election,
  fig,
  figCNN,
  figfox,
  figMSNBC,
  FoxNews,
  Gaza,
  Inflation,
  Mass_shooting,
  MSNBC,
  Ukraine,
  enddate,
  query,
  startdate,
  text_v_url,
  v_url,
  vp1,
  vp2,
  vp3,
  vp4
)

Analysis

Let’s create & compare four time periods:

  • Period 1: Outbreak of war in Ukraine up to the “leveling off” of initial coverage about the war.

  • Period 2: The “leveling off” of initial Ukraine war coverage up to the outbreak of war in Israel and Gaza.

  • Period 3: The outbreak of war in Israel and Gaza up to the “leveling off” of initial coverage of the war.

  • Period 4: “Leveling off” of coverage about the war in Israel and Gaza through the latest-available week (presently early October).

Next, let’s compare typical coverage volume about war in Ukraine for each of these three periods. The analysis uses a Kruskal-Wallis test and a Dunn’s post-hoc test, because the data do not fit the assumptions needed for the more familiar one-way ANOVA procedure. But one-way ANOVA results are included for comparison.

Results indicate that combined coverage by CNN, MSNBC, and Fox News dropped significantly between Period 1 and Period 2, dropped significantly once again between Period 2 and Period 3 (when war in Israel and Gaza was breaking out and producing high-volume coverage), then rose significantly, but moderately, between Period 3 and Period 4 (when coverage of war in Israel leveled off in volume).

######################### ANALYSES ###############################

### DV = Ukraine

# Creating groups by date

AllData <- AllData %>% 
  mutate(Period = case_when(
    (Date < ymd("2022-06-06")) ~ "Period 1",
    (Date < ymd("2023-10-07")) ~ "Period 2",
    (Date < ymd("2024-01-22")) ~ "Period 3",
    TRUE ~ "Period 4"
  ))

# Group median and mean comparisons

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData
  
# Specify the DV and IV
mydata$DV <- mydata$Ukraine
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   336 296.  190.      2   850  272.
## 2 Period 2  1464  62.1  67.6     0   826   44 
## 3 Period 3   321  22.1  19.0     0   153   18 
## 4 Period 4   792  39.4  47.0     0   375   25
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
## Loading required package: FSA
## ## FSA v0.9.5. See citation('FSA') if used in publication.
## ## Run fishR() for related website and fishR('IFAR') for related book.
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 938.08, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
## Warning: IV was coerced to a factor.
## Dunn (1964) Kruskal-Wallis multiple comparison
##   p-values adjusted with the Holm method.
##            Comparison         Z       P.unadj         P.adj
## 1 Period 1 - Period 2 19.620477  1.033790e-85  4.135161e-85
## 2 Period 1 - Period 3 26.981815 2.416051e-160 1.449631e-159
## 3 Period 2 - Period 3 14.911335  2.781339e-50  8.344016e-50
## 4 Period 1 - Period 4 26.495122 1.103164e-154 5.515821e-154
## 5 Period 2 - Period 4 12.199516  3.126788e-34  6.253575e-34
## 6 Period 3 - Period 4 -5.756372  8.594098e-09  8.594098e-09
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 342.44, num df = 3.0, denom df = 1056.1, p-value <
## 0.00000000000000022
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                         diff         lwr        upr     p adj
## Period 2-Period 1 -234.28142 -247.366280 -221.19656 0.0000000
## Period 3-Period 1 -274.35748 -291.239850 -257.47510 0.0000000
## Period 4-Period 1 -257.06061 -271.143610 -242.97760 0.0000000
## Period 3-Period 2  -40.07606  -53.407249  -26.74486 0.0000000
## Period 4-Period 2  -22.77919  -32.320526  -13.23784 0.0000000
## Period 4-Period 3   17.29687    2.984702   31.60904 0.0103085

Let’s do the same, but for each outlet individually

This section repeats the above analysis, but for each news outlet individually rather than for all of them collectively. Results show more or less the same pattern across all three outlets individually as across all three outlets combined.

# Fox News only

mydata <- AllData %>% 
  filter(Series == "FOXNEWS")

# Specify the DV and IV
mydata$DV <- mydata$Ukraine
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   112 224.  178.     20   763  158.
## 2 Period 2   488  44.4  42.2     4   456   34 
## 3 Period 3   107  22.3  13.7     3    78   20 
## 4 Period 4   264  29.4  31.9     0   282   21
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 307.18, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
##            Comparison         Z      P.unadj        P.adj
## 1 Period 1 - Period 2 11.841515 2.381130e-32 9.524519e-32
## 2 Period 1 - Period 3 14.479879 1.623823e-47 8.119116e-47
## 3 Period 2 - Period 3  6.714341 1.889183e-11 3.778365e-11
## 4 Period 1 - Period 4 16.128244 1.615489e-58 9.692936e-58
## 5 Period 2 - Period 4  7.565977 3.849587e-14 1.154876e-13
## 6 Period 3 - Period 4 -1.210202 2.262016e-01 2.262016e-01
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 74.166, num df = 3.00, denom df = 343.21, p-value <
## 0.00000000000000022
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                          diff        lwr         upr     p adj
## Period 2-Period 1 -179.895638 -198.64971 -161.141566 0.0000000
## Period 3-Period 1 -201.959029 -226.15595 -177.762111 0.0000000
## Period 4-Period 1 -194.852543 -215.03722 -174.667865 0.0000000
## Period 3-Period 2  -22.063391  -41.17053   -2.956255 0.0160273
## Period 4-Period 2  -14.956905  -28.63218   -1.281634 0.0256193
## Period 4-Period 3    7.106485  -13.40665   27.619618 0.8092590
# CNN only
mydata <- AllData %>% 
  filter(Series == "CNN")

# Specify the DV and IV
mydata$DV <- mydata$Ukraine
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   112 362.  169.      2   695 393  
## 2 Period 2   488  88.7  76.6     4   703  68.5
## 3 Period 3   107  23.9  23.6     0   153  17  
## 4 Period 4   264  52.5  57.5     0   375  35
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 407.76, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
##            Comparison         Z      P.unadj        P.adj
## 1 Period 1 - Period 2 11.072290 1.709751e-28 5.129253e-28
## 2 Period 1 - Period 3 17.877398 1.769013e-71 1.061408e-70
## 3 Period 2 - Period 3 11.771907 5.447911e-32 2.179164e-31
## 4 Period 1 - Period 4 16.347706 4.516699e-60 2.258350e-59
## 5 Period 2 - Period 4  8.944807 3.726014e-19 7.452029e-19
## 6 Period 3 - Period 4 -5.001906 5.676635e-07 5.676635e-07
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 210.61, num df = 3.00, denom df = 348.03, p-value <
## 0.00000000000000022
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                         diff         lwr        upr     p adj
## Period 2-Period 1 -273.03001 -295.923710 -250.13630 0.0000000
## Period 3-Period 1 -337.79715 -367.335108 -308.25918 0.0000000
## Period 4-Period 1 -309.28653 -333.926617 -284.64643 0.0000000
## Period 3-Period 2  -64.76714  -88.091839  -41.44244 0.0000000
## Period 4-Period 2  -36.25652  -52.950366  -19.56267 0.0000002
## Period 4-Period 3   28.51062    3.469574   53.55167 0.0181950
# MSNBC only

mydata <- AllData %>% 
  filter(Series == "MSNBC")

# Specify the DV and IV
mydata$DV <- mydata$Ukraine
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   112 303.  196.      7   850  284.
## 2 Period 2   488  53.3  70.6     0   826   35 
## 3 Period 3   107  19.9  18.4     0   139   15 
## 4 Period 4   264  36.2  45.1     0   336   23
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 286.23, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
##            Comparison         Z      P.unadj        P.adj
## 1 Period 1 - Period 2 12.170289 4.474926e-34 1.789970e-33
## 2 Period 1 - Period 3 15.165591 5.975848e-52 3.585509e-51
## 3 Period 2 - Period 3  7.260014 3.870504e-13 1.161151e-12
## 4 Period 1 - Period 4 14.843689 7.643486e-50 3.821743e-49
## 5 Period 2 - Period 4  5.219099 1.797957e-07 3.595914e-07
## 6 Period 3 - Period 4 -3.283042 1.026934e-03 1.026934e-03
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 101.85, num df = 3.00, denom df = 352.49, p-value <
## 0.00000000000000022
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                         diff         lwr           upr     p adj
## Period 2-Period 1 -249.91862 -273.302713 -226.53452383 0.0000000
## Period 3-Period 1 -283.31626 -313.486929 -253.14558112 0.0000000
## Period 4-Period 1 -267.04275 -292.210639 -241.87485927 0.0000000
## Period 3-Period 2  -33.39764  -57.221958   -9.57331549 0.0018426
## Period 4-Period 2  -17.12413  -34.175564   -0.07269701 0.0485692
## Period 4-Period 3   16.27351   -9.303927   41.85093910 0.3580536

Coverage volume of other issues, by period

Finally, let’s examine how coverage volume of the remaining five topics - mass shootings, abortion, the election, climate change, and inflation - changed during the four time periods.

Here, results indicate that, for all issues except abortion, coverage volume fell significantly during periods 1 and 3, when war news was “breaking” compared to periods 2 and 4, when war news was “leveling off.”

#--------------- DV = Inflation ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Inflation
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   336  47.5  47.0     0   296    32
## 2 Period 2  1464  41.3  45.2     0   382    25
## 3 Period 3   321  12.7  12.0     0    80     9
## 4 Period 4   792  24.1  24.5     0   190    17
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 331.08, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
##            Comparison         Z      P.unadj        P.adj
## 1 Period 1 - Period 2  2.628592 8.573918e-03 8.573918e-03
## 2 Period 1 - Period 3 14.317099 1.711180e-46 8.555900e-46
## 3 Period 2 - Period 3 15.550885 1.569214e-54 9.415283e-54
## 4 Period 1 - Period 4  9.162704 5.061304e-20 1.518391e-19
## 5 Period 2 - Period 4  9.919323 3.430762e-23 1.372305e-22
## 6 Period 3 - Period 4 -7.872198 3.484642e-15 6.969284e-15
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 188.81, num df = 3.0, denom df = 1075.4, p-value <
## 0.00000000000000022
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                         diff        lwr         upr     p adj
## Period 2-Period 1  -6.191159 -12.129350  -0.2529681 0.0371568
## Period 3-Period 1 -34.816644 -42.478229 -27.1550594 0.0000000
## Period 4-Period 1 -23.461941 -29.853112 -17.0707702 0.0000000
## Period 3-Period 2 -28.625485 -34.675468 -22.5755022 0.0000000
## Period 4-Period 2 -17.270782 -21.600848 -12.9407156 0.0000000
## Period 4-Period 3  11.354704   4.859533  17.8498743 0.0000430
#--------------- DV = Climate change ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Climate_change
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   336  3.79  3.93     0    21     3
## 2 Period 2  1464  8.32  9.26     0    82     6
## 3 Period 3   321  3.85  5.27     0    50     2
## 4 Period 4   792  4.27  5.25     0    42     3
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 262.6, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
##            Comparison          Z      P.unadj        P.adj
## 1 Period 1 - Period 2 -9.6796510 3.679698e-22 1.471879e-21
## 2 Period 1 - Period 3  1.3735063 1.695950e-01 3.391900e-01
## 3 Period 2 - Period 3 11.2401727 2.588754e-29 1.294377e-28
## 4 Period 1 - Period 4 -0.3760771 7.068596e-01 7.068596e-01
## 5 Period 2 - Period 4 12.7194471 4.611116e-37 2.766669e-36
## 6 Period 3 - Period 4 -1.9902184 4.656688e-02 1.397007e-01
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 83.364, num df = 3.0, denom df = 1045.9, p-value <
## 0.00000000000000022
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                          diff        lwr       upr     p adj
## Period 2-Period 1  4.53327479  3.3753154  5.691234 0.0000000
## Period 3-Period 1  0.06786827 -1.4261565  1.561893 0.9994309
## Period 4-Period 1  0.48575036 -0.7605410  1.732042 0.7483132
## Period 3-Period 2 -4.46540652 -5.6451656 -3.285647 0.0000000
## Period 4-Period 2 -4.04752442 -4.8918962 -3.203153 0.0000000
## Period 4-Period 3  0.41788209 -0.8486895  1.684454 0.8313825
#--------------- DV = Election ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Election
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   336  55.6  55.0     0   311  40.5
## 2 Period 2  1464 115.   98.3     1   746  84  
## 3 Period 3   321 100.   71.3     0   365  89  
## 4 Period 4   792 144.   68.4     0   510 130
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 471.47, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
##            Comparison          Z      P.unadj        P.adj
## 1 Period 1 - Period 2 -12.952233 2.282185e-38 9.128740e-38
## 2 Period 1 - Period 3  -9.209135 3.287647e-20 6.575295e-20
## 3 Period 2 - Period 3   1.050625 2.934307e-01 2.934307e-01
## 4 Period 1 - Period 4 -21.090711 9.679532e-99 5.807719e-98
## 5 Period 2 - Period 4 -13.367349 9.382585e-41 4.691292e-40
## 6 Period 3 - Period 4  -9.890082 4.596535e-23 1.378961e-22
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 176.16, num df = 3.00, denom df = 989.98, p-value <
## 0.00000000000000022
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                        diff       lwr        upr     p adj
## Period 2-Period 1  59.35036  46.30971  72.391010 0.0000000
## Period 3-Period 1  44.87503  28.04970  61.700360 0.0000000
## Period 4-Period 1  87.95319  73.91777 101.988613 0.0000000
## Period 3-Period 2 -14.47533 -27.76148  -1.189183 0.0263868
## Period 4-Period 2  28.60283  19.09373  38.111934 0.0000000
## Period 4-Period 3  43.07816  28.81435  57.341976 0.0000000
#--------------- DV = Abortion ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Abortion
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   336  33.1  85.9     0   761     3
## 2 Period 2  1464  40.2  66.7     0   950    17
## 3 Period 3   321  27.4  53.4     0   454    10
## 4 Period 4   792  38.9  49.9     0   392    22
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 200.27, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
##            Comparison          Z      P.unadj        P.adj
## 1 Period 1 - Period 2 -11.001607 3.753820e-28 1.876910e-27
## 2 Period 1 - Period 3  -4.189594 2.794537e-05 5.589074e-05
## 3 Period 2 - Period 3   5.492695 3.958456e-08 1.187537e-07
## 4 Period 1 - Period 4 -13.040148 7.231682e-39 4.339009e-38
## 5 Period 2 - Period 4  -4.159790 3.185404e-05 3.185404e-05
## 6 Period 3 - Period 4  -7.889381 3.036888e-15 1.214755e-14
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 5.1691, num df = 3.0, denom df = 881.7, p-value = 0.001518
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                         diff         lwr       upr     p adj
## Period 2-Period 1   7.168374  -2.7601284 17.096877 0.2475335
## Period 3-Period 1  -5.673092 -18.4830649  7.136881 0.6657434
## Period 4-Period 1   5.884470  -4.8014032 16.570343 0.4896572
## Period 3-Period 2 -12.841466 -22.9568821 -2.726050 0.0061281
## Period 4-Period 2  -1.283905  -8.5236635  5.955854 0.9684999
## Period 4-Period 3  11.557562   0.6978033 22.417320 0.0317888
#--------------- DV = Mass shooting ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Mass_shooting
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )
## # A tibble: 4 × 7
##   IV       count  mean    sd   min   max   med
##   <chr>    <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Period 1   336  7.47 16.6      0   104     0
## 2 Period 2  1464  4.53 11.2      0   110     1
## 3 Period 3   321  3.76 12.1      0   106     0
## 4 Period 4   792  1.46  3.66     0    35     0
# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  DV by IV
## Kruskal-Wallis chi-squared = 97.93, df = 3, p-value < 2.2e-16
dunnTest(DV ~ IV, data = mydata)
##            Comparison         Z      P.unadj        P.adj
## 1 Period 1 - Period 2 -1.938989 5.250273e-02 1.050055e-01
## 2 Period 1 - Period 3  1.896541 5.788849e-02 5.788849e-02
## 3 Period 2 - Period 3  4.304904 1.670579e-05 6.682316e-05
## 4 Period 1 - Period 4  4.750496 2.029179e-06 1.014590e-05
## 5 Period 2 - Period 4  9.670827 4.011246e-22 2.406747e-21
## 6 Period 3 - Period 4  2.437306 1.479714e-02 4.439143e-02
# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)
## 
##  One-way analysis of means (not assuming equal variances)
## 
## data:  mydata$DV and mydata$IV
## F = 44.959, num df = 3.00, denom df = 785.09, p-value <
## 0.00000000000000022
anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = mydata$DV ~ mydata$IV)
## 
## $`mydata$IV`
##                         diff       lwr        upr     p adj
## Period 2-Period 1 -2.9354020 -4.596483 -1.2743215 0.0000343
## Period 3-Period 1 -3.7069982 -5.850161 -1.5638356 0.0000536
## Period 4-Period 1 -6.0093795 -7.797171 -4.2215878 0.0000000
## Period 3-Period 2 -0.7715962 -2.463948  0.9207557 0.6446358
## Period 4-Period 2 -3.0739775 -4.285220 -1.8627352 0.0000000
## Period 4-Period 3 -2.3023813 -4.119265 -0.4854978 0.0062514

Alternative group plots

Histograms may not be all that suitable for showing group distributions that are as skewed as some of ours are. This code shows the group distributionas box plots instead.

# Nicer group comparison graphics

library(ggplot2)

# Graph the group distributions and averages

ggplot(AllData, aes(x = Period,
                    y = Ukraine)) +
  geom_boxplot() +
  theme_minimal()

# MSNBC only

GroupData <- AllData %>%
  filter(Series == "MSNBC")

ggplot(GroupData, aes(x = Period, y = Ukraine)) +
  geom_boxplot() +
  ylab("Ukraine - MSNBC only") +
  theme_minimal()

# CNN only

GroupData <- AllData %>%
  filter(Series == "CNN")

ggplot(GroupData, aes(x = Period, y = Ukraine)) +
  geom_boxplot() +
  ylab("Ukraine - CNN only") +
  theme_minimal()

# Fox News only

GroupData <- AllData %>%
  filter(Series == "FOXNEWS")

ggplot(GroupData, aes(x = Period, y = Ukraine)) +
  geom_boxplot() +
  ylab("Ukraine - Fox News only") +
  theme_minimal()

# Inflation

ggplot(AllData, aes(x = Period, y = Inflation)) +
  geom_boxplot() +
  ylab("Inflation") +
  theme_minimal()

# Climate change

ggplot(AllData, aes(x = Period, y = Climate_change)) +
  geom_boxplot() +
  ylab("Climate change") +
  theme_minimal()

# Election

ggplot(AllData, aes(x = Period, y = Election)) +
  geom_boxplot() +
  ylab("Election") +
  theme_minimal()

# Abortion

ggplot(AllData, aes(x = Period, y = Abortion)) +
  geom_boxplot() +
  ylab("Abortion") +
  theme_minimal()

# Mass shootings

ggplot(AllData, aes(x = Period, y = Mass_shooting)) +
  geom_boxplot() +
  ylab("Mass shooting") +
  theme_minimal()

The full script

Here is the complete script, start to finish.

if (!require("tidyverse"))
  install.packages("tidyverse")
if (!require("plotly"))
  install.packages("plotly")
library(tidyverse)
library(plotly)

# Defining date range

startdate <- "20220214"
enddate <- "20241114"

# Defining query

query <- "(russia%20OR%20ukrain)"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Ukraine <- read_csv(v_url)
Ukraine <- Ukraine %>%
  rename(Date = 1, Ukraine = 3)

### Gaza

# Defining query

query <- "(gaza%20OR%20israel)"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Gaza <- read_csv(v_url)
Gaza <- Gaza %>%
  rename(Date = 1, Gaza = 3)

AllData <- left_join(Ukraine, Gaza)

### Mass shooting

# Defining query

query <- "mass%20shooting"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Mass_shooting <- read_csv(v_url)
Mass_shooting <- Mass_shooting %>%
  rename(Date = 1, Mass_shooting = 3)

AllData <- left_join(AllData, Mass_shooting)

### Abortion

# Defining query

query <- "abortion"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Abortion <- read_csv(v_url)
Abortion <- Abortion %>%
  rename(Date = 1, Abortion = 3)

AllData <- left_join(AllData, Abortion)

### Election

# Defining query

query <- "election"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Election <- read_csv(v_url)
Election <- Election %>%
  rename(Date = 1, Election = 3)

AllData <- left_join(AllData, Election)

### Climate change

# Defining query

query <- "climate%20change"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Climate_change <- read_csv(v_url)
Climate_change <- Climate_change %>%
  rename(Date = 1, Climate_change = 3)

AllData <- left_join(AllData, Climate_change)

### Inflation

# Defining query

query <- "inflation"

# Building the volume dataframe

vp1 <- "https://api.gdeltproject.org/api/v2/tv/tv?query="
vp2 <- "%20market:%22National%22&mode=timelinevol&format=csv&datanorm=raw&startdatetime="
vp3 <- "000000&enddatetime="
vp4 <- "000000"
text_v_url <- paste0(vp1, query, vp2, startdate, vp3, enddate, vp4)
v_url <- URLencode(text_v_url)
v_url
Inflation <- read_csv(v_url)
Inflation <- Inflation %>%
  rename(Date = 1, Inflation = 3)

AllData <- left_join(AllData, Inflation)

# Filter AllData for Fox News, CNN, and MSNBC

AllData <- AllData %>%
  arrange(Date) %>% 
  filter(Series == "FOXNEWS"|
           Series == "CNN"|
           Series == "MSNBC")

### Graphic

# Add "WeekOf" variable to the data frame

if (!require("lubridate"))
  install.packages("lubridate")
library(lubridate)

AllData$WeekOf <- round_date(AllData$Date,
                             unit = "week",
                             week_start = getOption("lubridate.week.start", 1))


CombinedCoverage <- AllData %>%
  group_by(WeekOf) %>%
  summarize(
    Ukraine = sum(Ukraine, na.rm = TRUE),
    Gaza = sum(Gaza, na.rm = TRUE),
    Mass_shooting = sum(Mass_shooting, na.rm = TRUE),
    Abortion = sum(Abortion, na.rm = TRUE),
    Election = sum(Election, na.rm = TRUE),
    Climate_change = sum(Climate_change, na.rm = TRUE),
    Inflation = sum(Inflation, na.rm = TRUE)
  )


fig <- plot_ly(
  CombinedCoverage,
  x = ~ WeekOf,
  y = ~ Ukraine,
  name = 'Ukraine',
  type = 'scatter',
  mode = 'none',
  stackgroup = 'one',
  fillcolor = '#264653'
)
fig <- fig %>% add_trace(y = ~ Gaza,
                         name = 'Gaza',
                         fillcolor = '#287271')
fig <- fig %>% add_trace(
  y = ~ Mass_shooting,
  name = 'Mass shooting',
  fillcolor = '#2a9d8f'
)
fig <- fig %>% add_trace(y = ~ Abortion,
                         name = 'Abortion',
                         fillcolor = '#8ab17d')
fig <- fig %>% add_trace(y = ~ Election,
                         name = 'Election',
                         fillcolor = '#e9c46a')
fig <- fig %>% add_trace(
  y = ~ Climate_change,
  name = 'Climate change',
  fillcolor = '#f4a261'
)
fig <- fig %>% add_trace(y = ~ Inflation,
                         name = 'Inflation',
                         fillcolor = '#e76f51')
fig <- fig %>% layout(
  title = 'Segment counts, by topic and week, all outlets',
  xaxis = list(title = "Week of", showgrid = FALSE),
  yaxis = list(title = "Count", showgrid = TRUE)
)

fig

### Results for Fox News, CNN, and MSNBC, separately

#Fox News

FoxNews <- AllData %>%
  filter(Series == "FOXNEWS")
figfox <- plot_ly(
  FoxNews,
  x = ~ WeekOf,
  y = ~ Ukraine,
  name = 'Ukraine',
  type = 'scatter',
  mode = 'none',
  stackgroup = 'one',
  fillcolor = '#264653'
)
figfox <- figfox %>% add_trace(y = ~ Gaza,
                               name = 'Gaza',
                               fillcolor = '#287271')
figfox <- figfox %>% add_trace(
  y = ~ Mass_shooting,
  name = 'Mass shooting',
  fillcolor = '#2a9d8f'
)
figfox <- figfox %>% add_trace(y = ~ Abortion,
                               name = 'Abortion',
                               fillcolor = '#8ab17d')
figfox <- figfox %>% add_trace(y = ~ Election,
                               name = 'Election',
                               fillcolor = '#e9c46a')
figfox <- figfox %>% add_trace(
  y = ~ Climate_change,
  name = 'Climate change',
  fillcolor = '#f4a261'
)
figfox <- figfox %>% add_trace(y = ~ Inflation,
                               name = 'Inflation',
                               fillcolor = '#e76f51')
figfox <- figfox %>% layout(
  title = 'Segment counts, by topic and week, Fox News',
  xaxis = list(title = "Week of", showgrid = FALSE),
  yaxis = list(title = "Count", showgrid = TRUE)
)

figfox

# CNN

CNN <- AllData %>%
  filter(Series == "CNN")
figCNN <- plot_ly(
  CNN,
  x = ~ WeekOf,
  y = ~ Ukraine,
  name = 'Ukraine',
  type = 'scatter',
  mode = 'none',
  stackgroup = 'one',
  fillcolor = '#264653'
)
figCNN <- figCNN %>% add_trace(y = ~ Gaza,
                               name = 'Gaza',
                               fillcolor = '#287271')
figCNN <- figCNN %>% add_trace(
  y = ~ Mass_shooting,
  name = 'Mass shooting',
  fillcolor = '#2a9d8f'
)
figCNN <- figCNN %>% add_trace(y = ~ Abortion,
                               name = 'Abortion',
                               fillcolor = '#8ab17d')
figCNN <- figCNN %>% add_trace(y = ~ Election,
                               name = 'Election',
                               fillcolor = '#e9c46a')
figCNN <- figCNN %>% add_trace(
  y = ~ Climate_change,
  name = 'Climate change',
  fillcolor = '#f4a261'
)
figCNN <- figCNN %>% add_trace(y = ~ Inflation,
                               name = 'Inflation',
                               fillcolor = '#e76f51')
figCNN <- figCNN %>% layout(
  title = 'Segment counts, by topic and week, CNN',
  xaxis = list(title = "Week of", showgrid = FALSE),
  yaxis = list(title = "Count", showgrid = TRUE)
)

figCNN

# MSNBC

MSNBC <- AllData %>%
  filter(Series == "MSNBC")
figMSNBC <- plot_ly(
  MSNBC,
  x = ~ WeekOf,
  y = ~ Ukraine,
  name = 'Ukraine',
  type = 'scatter',
  mode = 'none',
  stackgroup = 'one',
  fillcolor = '#264653'
)
figMSNBC <- figMSNBC %>% add_trace(y = ~ Gaza,
                                   name = 'Gaza',
                                   fillcolor = '#287271')
figMSNBC <- figMSNBC %>% add_trace(
  y = ~ Mass_shooting,
  name = 'Mass shooting',
  fillcolor = '#2a9d8f'
)
figMSNBC <- figMSNBC %>% add_trace(y = ~ Abortion,
                                   name = 'Abortion',
                                   fillcolor = '#8ab17d')
figMSNBC <- figMSNBC %>% add_trace(y = ~ Election,
                                   name = 'Election',
                                   fillcolor = '#e9c46a')
figMSNBC <- figMSNBC %>% add_trace(
  y = ~ Climate_change,
  name = 'Climate change',
  fillcolor = '#f4a261'
)
figMSNBC <- figMSNBC %>% add_trace(y = ~ Inflation,
                                   name = 'Inflation',
                                   fillcolor = '#e76f51')
figMSNBC <- figMSNBC %>% layout(
  title = 'Segment counts, by topic and week, MSNBC',
  xaxis = list(title = "Week of", showgrid = FALSE),
  yaxis = list(title = "Count", showgrid = TRUE)
)

figMSNBC

rm(
  Abortion,
  Climate_change,
  CNN,
  CombinedCoverage,
  Election,
  fig,
  figCNN,
  figfox,
  figMSNBC,
  FoxNews,
  Gaza,
  Inflation,
  Mass_shooting,
  MSNBC,
  Ukraine,
  enddate,
  query,
  startdate,
  text_v_url,
  v_url,
  vp1,
  vp2,
  vp3,
  vp4
)

######################### ANALYSES ###############################

### DV = Ukraine

# Creating groups by date

AllData <- AllData %>% 
  mutate(Period = case_when(
    (Date < ymd("2022-06-06")) ~ "Period 1",
    (Date < ymd("2023-10-07")) ~ "Period 2",
    (Date < ymd("2024-01-22")) ~ "Period 3",
    TRUE ~ "Period 4"
  ))

# Group median and mean comparisons

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData
  
# Specify the DV and IV
mydata$DV <- mydata$Ukraine
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

# Fox News only

mydata <- AllData %>% 
  filter(Series == "FOXNEWS")

# Specify the DV and IV
mydata$DV <- mydata$Ukraine
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

# CNN only
mydata <- AllData %>% 
  filter(Series == "CNN")

# Specify the DV and IV
mydata$DV <- mydata$Ukraine
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

# MSNBC only

mydata <- AllData %>% 
  filter(Series == "MSNBC")

# Specify the DV and IV
mydata$DV <- mydata$Ukraine
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

#--------------- DV = Inflation ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Inflation
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

#--------------- DV = Climate change ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Climate_change
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

#--------------- DV = Election ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Election
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

#--------------- DV = Abortion ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Abortion
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

#--------------- DV = Mass shooting ------------#

library(ggplot2)
options(scipen = 999)

# Read the data
mydata <- AllData

# Specify the DV and IV
mydata$DV <- mydata$Mass_shooting
mydata$IV <- mydata$Period

# Graph the group distributions and averages

averages <- group_by(mydata, IV) %>%
  summarise(mean = mean(DV, na.rm = TRUE))
ggplot(mydata, aes(x = DV)) +
  geom_histogram() +
  facet_grid(IV ~ .) +
  geom_histogram(color = "black", fill = "#1f78b4") +
  geom_vline(data = averages, aes(xintercept = mean, ))

# Calculate and show the group counts, means, standard
# deviations, minimums, maximums, and medians

group_by(mydata, IV) %>%
  summarise(
    count = n(),
    mean = mean(DV, na.rm = TRUE),
    sd = sd(DV, na.rm = TRUE),
    min = min(DV, na.rm = TRUE),
    max = max(DV, na.rm = TRUE),
    med = median(DV, na.rm = TRUE)
  )

# Kruskal-Wallis test & Dunn's post hoc test

if (!require("FSA"))
  install.packages("FSA")
library(FSA)
options(scipen=0)
kruskal.test(DV ~ IV, data = mydata)
dunnTest(DV ~ IV, data = mydata)

# ANOVA & Tukey post hoc test

options(scipen = 999)
oneway.test(mydata$DV ~ mydata$IV,
            var.equal = FALSE)

anova_1 <- aov(mydata$DV ~ mydata$IV)
TukeyHSD(anova_1)

# Nicer group comparison graphics

library(ggplot2)

# Graph the group distributions and averages

ggplot(AllData, aes(x = Period,
                    y = Ukraine)) +
  geom_boxplot() +
  theme_minimal()

# MSNBC only

GroupData <- AllData %>%
  filter(Series == "MSNBC")

ggplot(GroupData, aes(x = Period, y = Ukraine)) +
  geom_boxplot() +
  ylab("Ukraine - MSNBC only") +
  theme_minimal()

# CNN only

GroupData <- AllData %>%
  filter(Series == "CNN")

ggplot(GroupData, aes(x = Period, y = Ukraine)) +
  geom_boxplot() +
  ylab("Ukraine - CNN only") +
  theme_minimal()

# Fox News only

GroupData <- AllData %>%
  filter(Series == "FOXNEWS")

ggplot(GroupData, aes(x = Period, y = Ukraine)) +
  geom_boxplot() +
  ylab("Ukraine - Fox News only") +
  theme_minimal()

# Inflation

ggplot(AllData, aes(x = Period, y = Inflation)) +
  geom_boxplot() +
  ylab("Inflation") +
  theme_minimal()

# Climate change

ggplot(AllData, aes(x = Period, y = Climate_change)) +
  geom_boxplot() +
  ylab("Climate change") +
  theme_minimal()

# Election

ggplot(AllData, aes(x = Period, y = Election)) +
  geom_boxplot() +
  ylab("Election") +
  theme_minimal()

# Abortion

ggplot(AllData, aes(x = Period, y = Abortion)) +
  geom_boxplot() +
  ylab("Abortion") +
  theme_minimal()

# Mass shootings

ggplot(AllData, aes(x = Period, y = Mass_shooting)) +
  geom_boxplot() +
  ylab("Mass shooting") +
  theme_minimal()