Une histoire du conflit politique. Élections et inégalités sociales en France, 1789-2022, Paris, Le Seuil is a dataset providing extensive data on French elections and their results. Due to the vast nature of this dataset, this report focusses on a small subset of this data set where some of the municiplaities have been removed due to changes in geography.
The data set has information regarding both the results of the 1981 election and recent results. We begin With the aims of determining whether or not the results of the 1981 election a good predictor for more recent years.
# Arrange and display the plots in a grid.
grid.arrange(p_left, p_right, p_trotskyist_communist, ncol=2)
All three figures display roughly horizontal regression lines, suggesting that changes in the votes for left, right Trotskyist to Communist parties from 1981 to the recent election are not strongly correlated with the number of votes they received in 1981. This implies that the recent performance of parties in elections is relatively independent of their performance in 1981, suggesting that other factors are influencing their current vote shares. To reinforce our conclusion, we can examine a correlation plot comparing the data from 1981 to the recent data.
This plot reveals a low correlation between each political alignment and its corresponding 1981 variable, further supporting the conclusions drawn from the previous plots.
# Display the top 10 correlations
knitr::kable(top_correlations)
| Variable1 | Variable2 | Correlation | |
|---|---|---|---|
| 236 | far_right | left | -0.4286527 |
| 14 | left | capitalratio2022 | 0.3229500 |
| 31 | left | revmoyfoy2022 | 0.3105322 |
| 133 | left | persup2022 | 0.2703571 |
| 48 | left | revmoy2022 | 0.2478573 |
| 134 | far_right | persup2022 | -0.2364745 |
| 116 | left | perbac2022 | 0.2356687 |
| 117 | far_right | perbac2022 | -0.2179563 |
| 15 | far_right | capitalratio2022 | -0.2092748 |
| 167 | left | pcadr2022 | 0.1908726 |
The table highlights key sociological predictors for far-right and left-wing voting patterns in 2022, identifying persup2022, perbac2022, and capitaratio2022 as important for predicting far-right votes, whereas capitaratio2022, revmoyfoy2022, and persup2022 are highlighted as important for left-wing votes. Notably, capitaratio2022, which represents the ratio of average per capita land value relative to the national average in 2022, displays a positive correlation with left-wing votes and a negative correlation with far-right votes, which is perhaps contrary to expectation. Furthermore, the indicators of educational attainment within a municipality, persup2022 and perbac2022, reveal that higher education levels are positively associated with left-wing political views and inversely linked with right-wing views. The table also indicates a lack of strong predictors for right-wing or Trotskyist vote counts in 2022.
We can view these relationships explicitly by plotting the most correlated predictors with the results.
# Display the plots of top 6 correlations, excluding right vs left itself
do.call(grid.arrange, c(plots_list[2:7], ncol=3))
# Load the data.
election_data <- read.csv("DatasetAssignment2.csv",na.strings=".")
# Convert columns of numbers (the 4th column onwards) to numeric
election_data[, 4:ncol(election_data)] <- lapply(election_data[, 4:ncol(election_data)],
function(x) as.numeric(as.character(x)))
# Remove na values.
election_data <-na.omit(election_data)
# POINT 2:
# Are the results of the 1981 election a good predictor?
# Combine variables by politcial views and year.
# Old Data
election_data$center1981 <- with(election_data, pvoixGISCARDDESTAING)
election_data$left1981 <- with(election_data, pvoixMITTERRAND)
election_data$right1981 <- with(election_data, pvoixCHIRAC)
election_data$communist1981 <- with(election_data, pvoixMARCHAIS)
#New Data
election_data$left <- with(election_data, pvoixJADOT)
election_data$far_right <- with(election_data, pvoixMLEPEN + pvoixZEMMOUR)
election_data$right <- with(election_data, pvoixPECRESSE)
election_data$trotskyst <- with(election_data, pvoixPOUTOU + pvoixARTHAUD)
# Plot for Left 1981 vs Recent Left.
p_left <- ggplot(election_data, aes(x=left1981, y=left)) +
geom_point() +
geom_smooth(method="lm") +
labs(title="Comparison of Left Votes: 1981 vs Recent",
x="Left 1981", y="Left Recent")
# Plot for Right 1981 vs Recent Right.
p_right <- ggplot(election_data, aes(x=right1981, y=right)) +
geom_point() +
geom_smooth(method="lm") +
labs(title="Comparison of Right Votes: 1981 vs Recent",
x="Right 1981", y="Right Recent")
# Plot for Trotskyist/Communist 1981 vs Recent.
p_trotskyist_communist <- ggplot(election_data, aes(x=communist1981, y=trotskyst)) +
geom_point() +
geom_smooth(method="lm") +
labs(title="Comparison of Trotskyist/Communist Votes: 1981 vs Recent",
x="Communist 1981", y="Trotskyist/Communist Recent")
# Arrange and display the plots in a grid.
grid.arrange(p_left, p_right, p_trotskyist_communist, ncol=2)
# Correlation matrix for old vs new data
correlation_matrix <- cor(election_data[, c("left1981", "right1981", "center1981",
"communist1981", "left", "right", "far_right",
"trotskyst")], use="complete.obs")
# Use corrplot to visualize the correlation matrix
corrplot(correlation_matrix, method="color", type="upper", order="hclust",
tl.col="black", tl.srt=45,
addCoef.col="black", # Show correlation coefficient
cl.cex=0.75, tl.cex=0.75)
#QUESTION3
# Can you find the important sociological
# variables to predict the results of the 2022 election?
# Select numeric columns.
numeric_data <- election_data[sapply(election_data, is.numeric)]
# Select columns relevant to 2022.
numeric_data <- election_data %>% select(
capitalratio2022,
revmoyfoy2022,
revmoy2022,
ppropri2022,
popagglo2022,
pop2022,
perbac2022,
persup2022,
pagri2022,
pcadr2022,
pouvr2022,
pempl2022,
pchom2022, left, far_right, trotskyst, right
)
# Create correlation matrix of the selected data.
cor_matrix <- cor(numeric_data)
# Convert the correlation matrix to a data frame.
cor_data <- as.data.frame(as.table(cor_matrix))
# Set column names of data frame.
names(cor_data) <- c("Variable1", "Variable2", "Correlation")
# Specify the variables of results.
result_vars <- c("left", "far_right", "trotskyist", "right")
# Exclude self-correlations.
cor_data <- cor_data[cor_data$Variable1 != cor_data$Variable2, ]
# Only include correlations where at least one variable is in the set of variables of results.
cor_data <- cor_data[(cor_data$Variable1 %in% result_vars | cor_data$Variable2 %in% result_vars), ]
# Remove duplicate pairs.
cor_data <- cor_data[!duplicated(t(apply(cor_data[, 1:2], 1, sort))), ]
# Sort by the absolute values of correlations to find highest correlations.
cor_data <- cor_data[order(-abs(cor_data$Correlation)), ]
# Select the top 10 correlations.
top_correlations <- head(cor_data, 10)
# Display the top 10 correlations
knitr::kable(top_correlations)
# Separate predictor variables from result variables.
predictor_variables <- top_correlations$Variable1
result_variables <- top_correlations$Variable2
# Create empty list to store plots.
plots_list <- list()
# Set initial index for plots_list
count <- 1
# Generate plots for each pair.
for (predictor in predictor_variables) {
for (result in result_variables) {
p <- ggplot(election_data, aes(x = .data[[predictor]], y = .data[[result]])) +
geom_point() +
geom_smooth(method = "lm", color = "blue") + # Add color for clarity, if desired
theme_minimal() +
labs(title = paste(predictor, "vs", result), x = predictor, y = result)
plots_list[[count]] <- p
count <- count + 1
}
}
# Display the first 4 plots
do.call(grid.arrange, c(plots_list[1:6], ncol=3))