Framing theory suggests that what a person is exposed to shapes what issues people will see as important. Different news network viewers may differ in whether they believe immigration is a top national issue.
Immigration is more likely to be seen as a top national issue depending on what news network source the viewer watches.
Independent Variable (IV): PreferredNetwork
Dependent Variable (DV): Immigration
A chi-square test evaluates whether or not the news network the viewer watches changes their opinion on immigration.
| DV by IV | ||
| Counts with (Column %) | ||
| CNN | Fox | |
|---|---|---|
| 1 Top issue | 35 (11.7%) | 115 (38.3%) |
| 2 Not top issue | 265 (88.3%) | 185 (61.7%) |
| Chi-square Results | |||
| Immigration (DV) vs Preferred Network (IV) | |||
| Test | Chi-square | df | p-value |
|---|---|---|---|
| Chi-square Test of Independence | 55.476 | 1 | 0.000 |
The data shows there is less than a .05 p-value, therefore there is reason to believe that the news network that the viewer watches is directly correlated to their beliefs on whether or not immigration is a top national issue.
# ------------------------------
# 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)
# ------------------------------
# Packages
# ------------------------------
library(dplyr)
library(tidyr)
library(ggplot2)
library(gt)
# ------------------------------
# Load the data
# ------------------------------
# Local file:
# mydata <- read.csv("TopIssue.csv")
# ------------------------------
# Define IV (predictor) and DV (outcome)
# ------------------------------
# Convention here: PreferredNetwork -> IV, Immigration -> DV
mydata$IV <- (mydata$PreferredNetwork)
mydata$DV <- (mydata$Immigration)
# ------------------------------
# Visualization: Stacked bar of DV by IV (column % look)
# ------------------------------
graph <- ggplot(mydata, aes(x = IV, fill = DV)) +
geom_bar(colour = "black") +
labs(
title = "Immigration (DV) by Preferred Network (IV)",
x = "Preferred Network (IV)",
y = "Count",
fill = "Immigration (DV)"
)
graph
# ------------------------------
# Crosstab: DV (rows) × IV (columns) with column percentages
# ------------------------------
crosstab <- mydata %>%
count(DV, IV, name = "n") %>%
group_by(IV) %>%
mutate(ColPct = 100 * n / sum(n)) %>%
ungroup() %>%
mutate(Cell = paste0(n, " (", round(ColPct, 1), "%)")) %>%
select(DV, IV, Cell) %>%
pivot_wider(names_from = IV, values_from = Cell)
crosstab_table <- crosstab %>%
gt(rowname_col = "DV") %>%
tab_header(
title = "DV by IV",
subtitle = "Counts with (Column %)"
) %>%
cols_label(DV = "Immigration (DV)")
crosstab_table
# ------------------------------
# Chi-square test of independence
# ------------------------------
options(scipen = 999)
chisq_res <- chisq.test(mydata$DV, mydata$IV)
# Nicely formatted results
chitest_table <- tibble(
Test = "Chi-square Test of Independence",
Chi_sq = unname(chisq_res$statistic),
df = unname(chisq_res$parameter),
p = chisq_res$p.value
) %>%
gt() %>%
fmt_number(columns = c(Chi_sq, p), decimals = 3) %>%
fmt_number(columns = df, decimals = 0) %>%
tab_header(
title = "Chi-square Results",
subtitle = "Immigration (DV) vs Preferred Network (IV)"
) %>%
cols_label(
Test = "Test",
Chi_sq = "Chi-square",
df = "df",
p = "p-value"
)
chitest_table