install.packages("readxl")
install.packages("dplyr")
install.packages("ggplot2")
install.packages("stats")
install.packages("NHANES")
library(readxl)
library(dplyr)
library(ggplot2)
library(stats)
library(NHANES)
alldata <- read_excel("10.20.2025.Data.Team3.clean.xlsx")
alldata[alldata == -99] <- NA
alldata[alldata == -50] <- NA
#explanation: these files are necessary to run the following code chunks smoothly.Plotting Zero Sum Beliefs and their Relationship with Political Polarization
Political Polarization, Economic Zero Sum Beliefs, Social Identity Zero Sum Beliefs, Spearman Rho correlation, Mental Health
1 1 Results
1.1 1.1 Load
1.2 1.2 Import
alldata <- read_excel("10.20.2025.Data.Team3.clean.xlsx")
#explanation- This allows the data to be accessed in positcloud. 1.3 1.3 Transform
alldata[alldata == -99] <- NA
alldata[alldata == -50] <- NA
E_zerosums <- c("ZSPRE_HEALTH", "ZSPRE_ECONOMY", "ZSPRE_ENVIRO1", "ZSPRE_ENVIRO2")
S_zerosums <- c("ZSPRE_IMM", "ZSPRE_WOMEN1", "ZSPRE_WOMEN2", "ZSPRE_DEI1", "ZSPRE_DEI2")
alldata <- alldata %>%
mutate(across(all_of(c(E_zerosums, S_zerosums)), as.numeric))
alldata <- alldata %>%
mutate(
E_avgscore = rowMeans(select(., all_of(E_zerosums)), na.rm = TRUE),
S_avgscore = rowMeans(select(., all_of(S_zerosums)), na.rm = TRUE),
)
alldata <- alldata %>%
mutate(POLITICALAFFIL = as.numeric(POLITICALAFFIL))
dem_data <- alldata %>%
filter (POLITICALAFFIL == 2)
dem_data <- dem_data %>%
mutate(POLARIZE_REP = as.numeric(POLARIZE_REP))
#explanation: For future use, naming and defining these variables is crucial. It allows you to call on it for future use, and it also gives you both of the participants zerosum score. Filtering the data for democrats only elimanates all non target demographics. Mutatitng the data allows for polarize rep to be called on and used by posit cloud in a numeric way.1.4 1.4 Model
cor.test(dem_data$E_avgscore, dem_data$POLARIZE_REP, method = "spearman")Warning in cor.test.default(dem_data$E_avgscore, dem_data$POLARIZE_REP, :
Cannot compute exact p-value with ties
Spearman's rank correlation rho
data: dem_data$E_avgscore and dem_data$POLARIZE_REP
S = 27482, p-value = 0.2196
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
-0.173158
ggplot(dem_data, aes(x = E_avgscore, y = POLARIZE_REP)) +
geom_point(position = "jitter", alpha = 0.25) + geom_smooth(method = "lm") +
xlab("Environmental Zero Sum Belief Average") +
ylab("Political Opinion Towards Republicans") +
ggtitle("Environmental zero sum belief and Polarized Opinion")`geom_smooth()` using formula = 'y ~ x'
#explanation: The spearman method is run first in order to calculate the values. Dem_ data, which was created earlier, is then used to plot E_avgscore on the x axis and POLARIZE_REP (democrat feelings towards republicans) on the y axis. geom_point is used for scatterplots, and geom_smooth is used in order to create a line of best fit included in the graph.cor.test(dem_data$S_avgscore, dem_data$POLARIZE_REP, method = "spearman")Warning in cor.test.default(dem_data$S_avgscore, dem_data$POLARIZE_REP, :
Cannot compute exact p-value with ties
Spearman's rank correlation rho
data: dem_data$S_avgscore and dem_data$POLARIZE_REP
S = 31602, p-value = 0.01122
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
-0.3489968
ggplot(dem_data, aes(x = S_avgscore, y = POLARIZE_REP)) +
geom_point(position = "jitter", alpha = 0.25) + geom_smooth(method = "lm") +
xlab("Social Zero Sum Belief Average") +
ylab("Political Opinion Towards Republicans") +
ggtitle("Social Identity zero sum beliefs and Polarized Opinion")`geom_smooth()` using formula = 'y ~ x'
#explanation: the spearman method is run first in order to calculate the values. Dem_ data, which was created earlier, is then used to plot S_avgscore on the x axis and POLARIZE_REP (democrat feelings towards republicans) on the y axis. geom_point is used for scatterplots, and geom_smooth is used in order to create a line of best fit included in the graph.2 Discussion
Upon analysis of our data, we found that Democrats with higher levels of agreement with Social Identity Zero Sum statements may be more likely to hold less extreme views towards Republicans. Furthermore, it was found that Democrats’ agreement with Economic Zero Sum statements has no correlation with their extreme opinions of the opposite political party. When analyzing the data for Republicans, we found only two participants to be eligible to analyze, which is not a large enough data set. We originally hypothesized that both economic and social identity beliefs would have a correlation with an individual’s polarization level, and we also hypothesized that we would be able to use their average zero sum score to predict their polarization level. This hypothesis did not hold true, as economic zero sum beliefs have no correlation with polarization and only a weak negative correlation was found for social identity beliefs. While the results are limited, it does raise interesting questions about the small, negative correlation found between social identity beliefs and extreme polarization