Rationale

In agenda-setting theory, the issues that receive greater levels of media attention can become more important in the minds of the public. The amount of attention given to an issue, as well as its prominence within media coverage, can influence how important audiences perceive that issue to be.

Considering what the theory says, the amount of attention Fox News and CNN give to immigration could influence how important viewers perceive immigration to be as a national issue. Specifically, comparing the volume and prominence of immigration coverage on Fox News and CNN could show whether immigration is one of their most emphasized issues and whether differences in coverage may affect the perceived importance of immigration among their audiences.

Hypothesis

Average perceptions of the importance of immigration will differ among viewers exposed to Fox News coverage compared with average perceptions of the importance of immigration among viewers exposed to CNN coverage.

Variables & Method

The dependent variable in the analysis was a continuous measure of the viewers preferred network of either CNN or Fox. The categorical independent variable indicated whether the viewer decided that that immigration was the top number one issue on their proffered network or not.

A sample of 600 subjects were divided randomly into two groups of 300. Each group then viewed either one ad or the other. After viewing the ad, subjects completed a questionnaire asking, among other things, how many calories they thought were in the advertised sandwich.

An independent-samples t-test was used to test for a statistically significant difference between the preferred network and immigration being the top issue

Results & Discussion

The graph and crosstabulation table below summarize the association between the dependent and independent variables. The chi-square results are shown as well.

Chi-squared Test Results
Test of Independence between DV and IV
Test Chi-squared Statistic Degrees of Freedom p-value
Chi-squared Test of Independence 55.476 1 0.000

The results supported the hypothesis. While majorities of both treatment groups considered immigration not a top issue, proportionally more participants among the CNN viewers considered it so (58.9%) than among the Fox viewers (41.1%). The chi-square test found the association to be statistically significant.

Code

# ------------------------------
# Setup: Install and load packages
# ------------------------------
if (!require("tidyverse")) install.packages("tidyverse")   # Data wrangling & plotting
if (!require("gmodels")) install.packages("gmodels")       # Crosstabs
if (!require("gt")) install.packages("gt")                 # Table formatting

library(tidyverse)
library(gmodels)
library(gt)

# ------------------------------
# Load the data
# ------------------------------
# Replace "YOURFILENAME.csv" with your dataset name
mydata <- read.csv("TopIssue.csv") #Edit

# ------------------------------
# Define Dependent (DV) and Independent (IV) variables
# ------------------------------
# Replace YOURDVNAME and YOURIVNAME with actual column names in your data
mydata$DV <- mydata$PreferredNetwork #Edit
mydata$IV <- mydata$Immigration #Edit

# ------------------------------
# Visualization: Stacked bar chart of IV by DV
# ------------------------------
graph <- ggplot(mydata, aes(x = IV, fill = DV)) +
  geom_bar(colour = "black") +
  scale_fill_brewer(palette = "Paired") +
  labs(
    title = "Distribution of DV by IV",
    x = "Independent Variable",
    y = "Count",
    fill = "Dependent Variable"
  )

#Show the graph
graph

# ------------------------------
# Crosstabulation of DV by IV (DV = rows, IV = columns)
# ------------------------------

crosstab <- mydata %>%
  count(DV, IV) %>%
  group_by(IV) %>%
  mutate(RowPct = 100 * n / sum(n)) %>%
  ungroup() %>%
  mutate(Cell = paste0(n, "\n(", round(RowPct, 1), "%)")) %>%
  select(DV, IV, Cell) %>%
  pivot_wider(names_from = IV, values_from = Cell)

# Format into gt table
crosstab_table <- crosstab %>%
  gt(rowname_col = "DV") %>%
  tab_header(
    title = "Crosstabulation of DV by IV",
    subtitle = "Counts and (Column Percentages)"
  ) %>%
  cols_label(
    DV = "Dependent Variable"
  )

# Show the polished crosstab table
crosstab_table

# ------------------------------
# Chi-squared test of independence
# ------------------------------
options(scipen = 999)  # Prevents scientific notation
chitestresults <- chisq.test(mydata$DV, mydata$IV)

# ------------------------------
# Format Chi-squared test results into a table
# ------------------------------
chitest_summary <- tibble(
  Test   = "Chi-squared Test of Independence",
  Chi_sq = chitestresults$statistic,
  df     = chitestresults$parameter,
  p      = chitestresults$p.value
)

chitest_table <- chitest_summary %>%
  gt() %>%
  # Round χ² and p-value to 3 decimals, df to integer
  fmt_number(columns = c(Chi_sq, p), decimals = 3) %>%
  fmt_number(columns = df, decimals = 0) %>%
  tab_header(
    title = "Chi-squared Test Results",
    subtitle = "Test of Independence between DV and IV"
  ) %>%
  cols_label(
    Test   = "Test",
    Chi_sq = "Chi-squared Statistic",
    df     = "Degrees of Freedom",
    p      = "p-value"
  )

# Show the formatted results table
chitest_table