Rationale
What we know about Second-Level Agenda Setting would tell us that Fox and CNN will help to tell us what to think about the issue of Immigration, and we will likely see different results depending on which audience we are talking about. The data we have would have us believe that these two networks would help shape different opinions for their particular audiences.
Hypothesis
Fox viewers will be more likely to view immigration as a top issue, while CNN viewers are more likely to not view it as a top issue.
Variables & Method
The dependent variable in this data measured which people thought that immigration was a top issue between the Fox and CNN viewers. The independent variable showed whether or not this was a Fox Viewer or a CNN Viewer who held that belief.
A total of 600 viewers were divided into Fox and CNN viewers evenly so that each group had 300 total. Each group then answered the question about the importance of immigration.
From there, a Chi-Test was conducted to determine whether or not there was a statiscally significant difference between the two groups on how they perceived the issue of immigration.
Results & Discussion
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 |
Crosstabulation of DV by IV | ||
Counts and (Column Percentages) | ||
CNN | Fox | |
---|---|---|
1 Top issue | 35 (11.7%) | 115 (38.3%) |
2 Not top issue | 265 (88.3%) | 185 (61.7%) |
Distribution was shown to be the same and the CNN viewers were also shown to believe less that immigration was a top issue while more Fox viewers believed that immigration was a top issue. The chi-squared test determined the p-value to be statiscally significant. These results came together to verify what we determined in the hypothesis.
# ------------------------------
# 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")
# ------------------------------
# Define Dependent (DV) and Independent (IV) variables
# ------------------------------
# Replace YOURDVNAME and YOURIVNAME with actual column names in your data
mydata$DV <- mydata$Immigration
mydata$IV <- mydata$PreferredNetwork
# ------------------------------
# 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